aboutsummaryrefslogtreecommitdiff
path: root/src/model/invite.rs
Commit message (Collapse)AuthorAgeFilesLines
* A bunch of typo fixes (#404)Perry Fraser2018-10-011-2/+2
|
* Fix all the dead links in the docsErk-2018-08-091-18/+20
|
* Monomorphize all functionsZeyla Hellyer2018-07-041-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | This commit monomorphizes all functions, turning functions like: ```rust fn foo<T: Into<Bar>>(baz: T) { baz = baz.into(); // function here } ``` Into functions like: ```rust fn foo<T: Into<Bar>>(baz: T) { _foo(baz.into()) } fn _foo(baz: Bar) { // function here } ``` This avoids binary bloat and improves build times, by reducing the amount of code duplication.
* Make guild optional on InvitesZeyla Hellyer2018-06-271-8/+20
| | | | | | | | Make the `guild` structfield on `Invite` and `RichInvite` optional. This was done due to a change in the [docs]. [docs]: https://github.com/discordapp/discord-api-docs/commit/bc0a15bd11db72644633080903171fbc3e71b026
* Implement or derive Serialize on all modelsZeyla Hellyer2018-01-011-4/+4
|
* Improve performance of builders even furtheracdenisSK2017-12-271-1/+1
| | | | | | By negating hashing altogether. The increase is around 1000-ish nanoseconds saved.
* Break up the model moduleZeyla Hellyer2017-12-161-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `model` module has historically been one giant module re-exporting all of the model types, which is somewhere around 100 types. This can be a lot to look at for a new user and somewhat overwhelming, especially with a large number of fine-grained imports from the module. The module is now neatly split up into submodules, mostly like it has been internally since the early versions of the library. The submodules are: - application - channel - error - event - gateway - guild - id - invite - misc - permissions - prelude - user - voice - webhook Each submodule contains types that are "owned" by the module. For example, the `guild` submodule contains, but not limited to, Emoji, AuditLogsEntry, Role, and Member. `channel` contains, but not limited to, Attachment, Embed, Message, and Reaction. Upgrade path: Instead of glob importing the models via `use serenity::model::*;`, instead glob import via the prelude: ```rust use serenity::model::prelude::*; ``` Instead of importing from the root model module: ```rust use serenity::model::{Guild, Message, OnlineStatus, Role, User}; ``` instead import from the submodules like so: ```rust use serenity::model::channel::Message; use serenity::model::guild::{Guild, Role}; use serenity::model::user::{OnlineStatus, User}; ```
* Re-order use statements alphabeticallyZeyla Hellyer2017-11-111-2/+2
|
* Slightly improve performance of buildersZeyla Hellyer2017-10-181-3/+5
| | | | | | | | | | | | | | | Builders would keep a `serde_json::Map<String, Value>`, which would require re-creating owned strings for the same parameter multiple times in some cases, depending on builder defaults and keying strategies. This commit uses a `std::collections::HashMap<&'static str, Value>` internally, and moves over values to a `serde_json::Map<String, Value>` when it comes time to sending them to the appropriate `http` module function. This saves the number of heap-allocated string creations on most builders, with specific performance increase on `builder::CreateMessage` and `builder::CreateEmbed` & co.
* Revert "Use the de-generification trick."acdenisSK2017-10-091-4/+1
| | | | Makes the compiliation time just a bit worse
* Use the de-generification trick.acdenisSK2017-10-091-1/+4
| | | | Fixes #168
* `to_owned` -> `to_string`acdenisSK2017-10-091-7/+7
|
* Update bitflags, other dependenciesZeyla Hellyer2017-09-211-4/+4
| | | | | | | | | | | | | | | | | | | | | | | Bitflags changed its macro codegen from creating constants to associated constants on structs. Upgrade path: Update code from: ```rust use serenity::model::permissions::{ADD_REACTIONS, MANAGE_MESSAGES}; foo(vec![ADD_REACTIONS, MANAGE_MESSAGES]); ``` to: ```rust use serenity::model::Permissions; foo(vec![Permissions::ADD_REACTIONS, Permissions::MANAGE_MESSAGES]); ```
* Apply rustfmtZeyla Hellyer2017-09-181-2/+1
|
* Fix compiles of a variety of feature combinationsZeyla Hellyer2017-09-181-1/+1
| | | | | This fixes compilation errors and warnings when compiling a mixture of non-default feature targets.
* Add ability to play DCA and Opus files. (#148)Maiddog2017-08-271-1/+2
|
* Revamp `RwLock` usage in the libacdenisSK2017-08-241-2/+1
| | | | Also not quite sure if they goofed rustfmt or something, but its changes it did were a bit bizarre.
* Change the config a bit, and a few nitpicksacdenisSK2017-07-271-3/+1
|
* rustfmtacdenisSK2017-07-271-30/+24
|
* Use chrono for struct timestamp fieldsZeyla Hellyer2017-06-061-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Chrono is easier to use than timestamped strings, so they should be automatically deserialized and available for the user, instead of having the user deserialize the strings themselves. These fields have been changed to use a type of `DateTime<FixedOffset>`: - `ChannelPinsUpdateEvent.last_pin_timestamp` - `Group.last_pin_timestamp` - `Guild.joined_at` - `GuildChannel.last_pin_timestamp` - `Invite.created_at` - `Member.joined_at` - `Message.edited_timestamp - `Message.timestamp` - `MessageUpdateEvent.edited_timestamp` - `MessageUpdateEvent.timestamp` - `PrivateChannel.last_pin_timestamp` `Member.joined_at` is now also an `Option`. Previously, if a Guild Member Update was received for a member not in the cache, a new Member would be instantiated with a default String value. This is incorrect behaviour, and has now been replaced with being set to `None` in that case. Id methods' `created_at()` method now return a `chrono::NaiveDateTime` instead of a `time::Timespec`, and `User::created_at` has been updated to reflect that. Additionally, drop `time` as a direct dependency and use chrono for internals.
* Fix compilations across feature combinationsZeyla Hellyer2017-06-021-2/+4
|
* Fix {Invite,RichInvite}::url testsZeyla Hellyer2017-05-221-0/+6
| | | | | Add fields in struct instantiation for the new stats fields introduced by the recent invite stats commit.
* Restructure modulesZeyla Hellyer2017-05-221-24/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Modules are now separated into a fashion where the library can be used for most use cases, without needing to compile the rest. The core of serenity, with no features enabled, contains only the struct (model) definitions, constants, and prelude. Models do not have most functions compiled in, as that is separated into the `model` feature. The `client` module has been split into 3 modules: `client`, `gateway`, and `http`. `http` contains functions to interact with the REST API. `gateway` contains the Shard to interact with the gateway, requiring `http` for retrieving the gateway URL. `client` requires both of the other features and acts as an abstracted interface over both the gateway and REST APIs, handling the event loop. The `builder` module has been separated from `utils`, and can now be optionally compiled in. It and the `http` feature are required by the `model` feature due to a large number of methods requiring access to them. `utils` now contains a number of utilities, such as the Colour struct, the `MessageBuilder`, and mention parsing functions. Each of the original `ext` modules are still featured, with `cache` not requiring any feature to be enabled, `framework` requiring the `client`, `model`, and `utils`, and `voice` requiring `gateway`. In total the features and their requirements are: - `builder`: none - `cache`: none - `client`: `gateway`, `http` - `framework`: `client`, `model`, `utils` - `gateway`: `http` - `http`: none - `model`: `builder`, `http` - `utils`: none - `voice`: `gateway` The default features are `builder`, `cache`, `client`, `framework`, `gateway`, `model`, `http`, and `utils`. To help with forwards compatibility, modules have been re-exported from their original locations.
* Add `Invite::url()`, `RichInvite::url()`Zeyla Hellyer2017-05-221-0/+72
| | | | | Add helper methods to easily produce invite URLs, such as `"https://discord.gg/WxZumR"`.
* Add support for retrieving invites with countsMei2017-05-181-4/+17
| | | | | | | Previously retrieving an invite with the `?with_counts=true` wasn't possible. Added support to `get_invite` for retrieving an invite with the counts, this requires the user to pass true to the function. The counts include `approximate_presence_count` and `approximate_member_count` which have been added to the `Invite` stuct, as well as `text_channel_count` and `voice_channel_count` to the `InviteGuild` struct.
* Add Shard Id helpersZeyla Hellyer2017-04-121-0/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add helpers to retrieve the shard Id for guilds, and count how many guilds are handled by a Shard. Helpers to retrieve the shard Id of a guild have been added as: - `Guild::shard_id` - `GuildId::shard_id` These are in two forms: one working with the cache feature, and one without. The function that works with the cache will automatically retrieve the total number of shards from the Cache, while the uncached version requires passing in the total number of shards used. With the cache enabled, this might look like: ```rust guild.shard_id(); // which calls: guild_id.shard_id(); ``` Without the cache enabled, this looks like: ```rust let shard_count = 7; guild.shard_id(shard_count); // which calls: guild_id.shard_id(shard_count); ``` These two variants on `Guild` and `GuildId` are helper sugar methods over the new function `utils::shard_id`, which accepts a `guild_id` and a `shard_count`: ```rust use serenity::utils; assert_eq!(utils::shard_id(81384788765712384, 17), 7); ``` You would use `utils::shard_id` when you have the total number of shards due to `{Guild,GuildId}::shard_id` unlocking the cache to retrieve the total number of shards. This avoids some amount of work
* Switch to using serde for deserializationZeyla Hellyer2017-04-111-3/+80
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The current build system is rudimentary, incomplete, and rigid, offering little in the way of customizing decoding options. To solve this, switch to using serde-derive with custom Deserialization implementations. This allows very simple deserialization when special logic does not need to be applied, yet allows us to implement our own deserialization logic when required. The problem with the build system was that it built enums and structs from YAML files. This is not so good, because it requires creating a custom build system (which was rudimentary), creating "special struct configs" when logic needed to be ever so slightly extended (rigid), and if special logic needed to be applied, a custom deserialization method would have been needed to be made anyway (incomplete). To solve this, switch to serde-derive and implementing Deserialize ourselves where required. This reduces YAML definitions that might look like: ```yaml --- name: Group description: > A group channel, potentially including other users, separate from a [`Guild`]. [`Guild`]: struct.Guild.html fields: - name: channel_id description: The Id of the group channel. from: id type: ChannelId - name: icon description: The optional icon of the group channel. optional: true type: string - name: last_message_id description: The Id of the last message sent. optional: true type: MessageId - name: last_pin_timestamp description: Timestamp of the latest pinned message. optional: true type: string - name: name description: The name of the group channel. optional: true type: string - name: owner_id description: The Id of the group channel creator. type: UserId - name: recipients description: Group channel's members. custom: decode_users t: UserId, Arc<RwLock<User>> type: hashmap ``` to: ```rs /// A group channel - potentially including other [`User`]s - separate from a /// [`Guild`]. /// /// [`Guild`]: struct.Guild.html /// [`User`]: struct.User.html pub struct Group { /// The Id of the group channel. #[serde(rename="id")] pub channel_id: ChannelId, /// The optional icon of the group channel. pub icon: Option<String>, /// The Id of the last message sent. pub last_message_id: Option<MessageId>, /// Timestamp of the latest pinned message. pub last_pin_timestamp: Option<String>, /// The name of the group channel. pub name: Option<String>, /// The Id of the group owner. pub owner_id: UserId, /// A map of the group's recipients. #[serde(deserialize_with="deserialize_users")] pub recipients: HashMap<UserId, Arc<RwLock<User>>>, } ``` This is much simpler and does not have as much boilerplate. There should not be any backwards incompatible changes other than the old, public - yet undocumented (and hidden from documentation) - decode methods being removed. Due to the nature of this commit, field names may be incorrect, and will need to be corrected as deserialization errors are found.
* Remove invite acceptingZeyla Hellyer2017-03-041-63/+0
|
* Pass by reference where possibleZeyla Hellyer2017-02-281-1/+1
| | | | | | | A lot of the `rest` methods took - for example a Map - by value, where they could instead take a reference. While this only prevents one clone in the library, user-land code should no longer need to clone maps when using the `rest` module.
* Fix docs linksAustin Hellyer2017-01-241-0/+1
|
* Switch to a mostly-fully OOP approachAustin Hellyer2017-01-231-11/+48
| | | | | | The context is now strictly in relation to the context of the current channel related to the event, if any. See Context::say for a list of events that the context can be used for.
* Fix typoIllia2016-12-311-2/+2
|
* Use conditional blocks over macrosAustin Hellyer2016-12-291-8/+12
|
* More config for CreateCommand, add various methodsIllia2016-12-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Adds multiple configurations to the command builder, and adds methods to various structs. Context::get_current_user is a shortcut to retrieve the current user from the cache. Message::get_member retrieves the member object of the message, if sent in a guild. Message::is_private checks if the message was sent in a Group or PrivateChannel. User::member retrieves the user's member object in a guild by Id; Adds 6 configurations to the command builder: - dm_only: whether the command can only be used in direct messages; - guild_only: whether the command can only be used in guilds; - help_available: whether the command should be displayed in the help list; - max_args: specify the maximum number of arguments a command must be given; - min_args: specify the minimum number of arguments a command must be given; - required_permissions: the permissions a member must have to be able to use the command;
* Fix no-cache+method conditional compilesAustin Hellyer2016-12-101-3/+6
| | | | Additionally, flag imports behind feature flags to avoid unused imports.
* Change all try's into ?sacdenisSK2016-12-071-2/+2
| | | This breaks compatibility with < 1.13, but we didn't support that anyway.
* More widely support no-cache method compilesAustin Hellyer2016-11-251-8/+11
| | | | | | | Conditional compiles with the 'methods' feature enabled - but the 'cache' feature disabled - were supported, but methods would call an empty function to check if the current user has permissions. Instead, put these function calls behind macros which check for feature cfgs.
* Rename the `http` module to `rest`Austin Hellyer2016-11-251-11/+11
|
* Allow compiling with only either cache or methodsAustin Hellyer2016-11-241-4/+6
| | | | | | | | | Some of the methods relied on the cache being present. Now, these methods only conditionally require the cache to be compiled and present. The cache was mainly used for checking if the current user had permission to perform operations.
* Change the CACHE to be an RwLockAustin Hellyer2016-11-221-2/+2
| | | | | | | | | | | | | | | | | | The global Cache used to be an Arc<Mutex>, however the issue is that it could only be opened for reading or writing once at a time. With an RwLock, multiple readers can access the Cache at once, while only one Writer may at once. This will allow users to be able to have multiple Readers open at once, which should ease some of the pains with working with the Cache. Upgrade path: Modify all uses of the CACHE from: `CACHE.lock().unwrap()` to `CACHE.read().unwrap()` if reading from the Cache (most use cases), or `CACHE.write().unwrap()` to write to it.
* Rename the State to CacheAustin Hellyer2016-11-221-8/+8
|
* A bit of docsAustin Hellyer2016-11-181-20/+26
|
* Accepting invites only works for user accountsAustin Hellyer2016-11-161-3/+43
| | | | | They do not work for bot users. So return a `ClientError::InvalidOperationAsBot` if someone tries to.
* Add state/framework/etc. conditional compile flagsAustin Hellyer2016-11-151-0/+4
| | | | | | | | | | | | | | | This adds conditional compilation for the following features, in addition to the voice conditional compilation flag: - extras (message builder) - framework - methods - state These 4 are enabled _by default_, while the `voice` feature flag is disabled. Disabling the state will allow incredibly low-memory bots.
* Add internal moduleAustin Hellyer2016-11-141-1/+1
| | | | | Create a general `internal` module, and move `prelude_internal` to `internal::prelude`.
* Add a prelude for userlandAustin Hellyer2016-11-051-1/+1
| | | | | | | Users can now import all of a prelude via `use serenity::prelude::*;`, which should provide some helpful stuff. As such, the internal prelude is now named `serenity::prelude_internal`, and all internal uses have been adjusted.
* Finalize invite-related documentationAustin Hellyer2016-11-051-16/+41
|
* Initial commitAustin Hellyer2016-10-181-0/+47