aboutsummaryrefslogtreecommitdiff
path: root/src/model/gateway.rs
Commit message (Collapse)AuthorAgeFilesLines
* Properly link to User in Game docsZeyla Hellyer2018-08-241-0/+2
|
* Add support for session start info in BotGatewayZeyla Hellyer2018-08-241-0/+16
| | | | | Add support for the new information describing the current session start ratelimits given in the GET /gateway/bot endpoint.
* Fix all the dead links in the docsErk-2018-08-091-3/+3
|
* Fix Game From impls on no-model compilationZeyla Hellyer2018-08-051-2/+10
|
* Add From impls for Game, generify Game paramsZeyla Hellyer2018-08-011-0/+52
| | | | | Add more `impl From<T> for Game` implementations, and make `Into<Game>` trait bounds for all function parameters accepting a Game.
* Fix some clippy lintsZeyla Hellyer2018-07-151-1/+1
| | | | | Some lints were not resolved due to causing API changes. Most lints in the framework were left unfixed.
* Change the way ids and some enums are made (#295)Leah2018-03-231-16/+25
| | | | | This makes them easier to be found by tools like rls. Also update struct inits to use the shorthand version for `x: x`.
* Remove useless clones (#292)Maiddog2018-03-171-1/+1
|
* Remove GameType::WatchingZeyla Hellyer2018-01-031-32/+0
| | | | | | According to [this commit], the game type has been removed. [this commit]: https://github.com/discordapp/discord-api-docs/commit/50999182f307ffda9ac7208a48570586ea446c08#diff-b307d936b736f302bc7cc153f0d8a0a3L779
* Implement or derive Serialize on all modelsZeyla Hellyer2018-01-011-4/+32
|
* Add missing 'num' implementations on modelsZeyla Hellyer2017-12-271-0/+13
| | | | | | | Add missing 'num' implementations from the following models: - `channel::{ChannelType, MessageType}` - `gateway::GameType`
* Default serde on a couple Ready structfieldsZeyla Hellyer2017-12-171-6/+8
| | | | | | | Have serde default on the `presences` and `private_channels` structfields of `Ready`. Some JSON serializers might leave these out when serializing if they're empty, so resolve this by simply defaulting to empty maps.
* Break up the model moduleZeyla Hellyer2017-12-161-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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}; ```
* Revamp the internals of `Args`acdenisSK2017-12-161-3/+3
| | | | Fixes #180, however this partially breaks `single_zc` and `multiple_quoted`, but since they're minor it's better to fix them later for now.
* Add the new game types (#219)Mei Boudreau2017-11-161-0/+62
|
* Switch to parking_lot::{Mutex, RwLock}Zeyla Hellyer2017-10-101-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Switch to the `parking_lot` crate's implementations of `std::sync::Mutex` and `std::sync::RwLock`, which are more efficient. A writeup on why `parking_lot` is more efficient can be read here: <https://github.com/Amanieu/parking_lot> Upgrade path: Modify `mutex.lock().unwrap()` usage to `mutex.lock()` (not needing to unwrap or handle a result), and `rwlock.read().unwrap()`/`rwlock.write().unwrap()` usage to `rwlock.read()` and `rwlock.write()`. For example, modify: ```rust use serenity::CACHE; println!("{}", CACHE.read().unwrap().user.id); ``` to: ```rust use serenity::CACHE; println!("{}", CACHE.read().user.id); ```
* `to_owned` -> `to_string`acdenisSK2017-10-091-3/+3
|
* Apply rustfmtZeyla Hellyer2017-09-181-23/+13
|
* Add ability to play DCA and Opus files. (#148)Maiddog2017-08-271-13/+23
|
* Revamp `RwLock` usage in the libacdenisSK2017-08-241-23/+13
| | | | Also not quite sure if they goofed rustfmt or something, but its changes it did were a bit bizarre.
* Fix tests (#145)Maiddog2017-08-221-3/+6
|
* Apply rustfmtZeyla Hellyer2017-08-181-8/+16
|
* Change the config a bit, and a few nitpicksacdenisSK2017-07-271-19/+15
|
* rustfmtacdenisSK2017-07-271-26/+33
|
* Add some model docs, deprecate Role::edit_roleMaiddog2017-06-031-0/+35
| | | Deprecate `Role::edit_role` and rename it to `Role::edit`.
* Restructure modulesZeyla Hellyer2017-05-221-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Update most dependency version requirementsZeyla Hellyer2017-04-231-4/+4
| | | | | | | | Update the dependencies `base64`, `bitflags`, `byteorder`, `serde`, `serde_derive`, and `serde_json`. These dependencies have been updated, with byteorder and serde** hitting v1.0.0, so they should be updated for the v0.2.0 serenity release.
* Switch to using serde for deserializationZeyla Hellyer2017-04-111-36/+152
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Optimize cachingZeyla Hellyer2017-02-091-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Improve the cache by keeping track of new maps, making other maps have `Arc<RwLock>` values, optimizing already-existing methods, and take advantage of new, more efficient retrievals (e.g. simply keying a value from a map rather than iterating over vecs or maps and then itering over another vec). Keep track of two new maps in the cache: - **channels**: a map of all guild channels that exist, so that they can be efficiently found, and so a message's guild can be efficiently found - **users**: a map of all users that exist, so that it can be shared across all members and presences Other cache fields now have `Arc<RwLock>` values: - `groups` - `guilds` - `private_channels` `Cache::unavailable_guilds` is now a `HashSet<GuildId>` instead of a `Vec<GuildId>`. This should slightly optimize removals/insertions for large bots. `ext::cache::ChannelRef` has been removed as it became equivilant in functionality to `model::Channel`. Also, `model::Channel` now has all variant data encased in `Arc<RwLock>`s. E.g., `Channel::Group(Group)` is now `Channel::Group(Arc<RwLock<Group>>)`. Some model struct fields are now wrapped in an `Arc<RwLock>`. These are: - `Group::recipients`: `HashMap<UserId, User>` -> `HashMap<UserId, Arc<RwLock<User>>>` - `Guild::channels`: `HashMap<ChannelId, GuildChannel>` -> `HashMap<ChannelId, Arc<RwLock<GuildChannel>>>` - `Member::user`: `User` -> `Arc<RwLock<User>>` - `PrivateChannel::recipient`: `User` -> `Arc<RwLock<User>>` Some (cache-enabled) event handler signatures have changed to use `Arc<RwLock>`s: - `Client::on_call_delete` - `Client::on_call_update` - `Client::on_guild_delete` - `Client::on_guild_update` Many function signatures have changed: - `Cache::get_call` now returns a `Option<Arc<RwLock<Call>>>` instead of a `Option<&Call>` - `Cache::get_channel` now returns a `Option<Channel>` instead of a `Option<ChannelRef>`. This now also retrieves directly from the `Guild::channels` instead of iterating over guilds' for a guild channel - `Cache::get_guild` now returns a `Option<Arc<RwLock<Guild>>>` instead of a `Option<&Guild>` - `Cache::get_guild_channel` now returns a `Option<Arc<RwLock<GuildChannel>>>` instead of a `Option<&GuildChannel>` - `Cache::get_group` now returns a `Option<Arc<RwLock<Group>>>` instead of a `Option<&Group>` - `Cache::get_member` now returns a `Option<Member>` instead of a `Option<&Member>`, due to guilds being behind a lock themselves - `Cache::get_role` now returns a `Option<Role>` instead of a `Option<&Role>` for the above reason - `Cache::get_user` now returns a `Option<Arc<RwLock<User>>>` instead of a `Option<&User>` - `GuildId::find` now returns a `Option<Arc<RwLock<Guild>>>` instead of a `Option<Guild>` - `UserId::find` now returns a `Option<Arc<RwLock<User>>>` instead of a `Option<User>` - `Member::display_name` now returns a `Cow<String>` instead of a `&str` A new cache method has been added, `Cache::get_private_channel`, to retrieve a `PrivateChannel`. The `Display` formatter for `Channel` has been optimized to not clone.
* Switch to a mostly-fully OOP approachAustin Hellyer2017-01-231-2/+0
| | | | | | 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.
* Alphabetize model method namesAustin Hellyer2017-01-081-20/+20
|
* Change all try's into ?sacdenisSK2016-12-071-12/+12
| | | This breaks compatibility with < 1.13, but we didn't support that anyway.
* Add documentation for modelsIllia2016-12-041-2/+6
|
* Clean up the codebaseAustin Hellyer2016-11-291-2/+2
|
* Improve docs and add new message builder methodsIllia K2016-11-281-0/+2
| | | | | Add documentation for some missing methods - such as Game methods - and add more methods to the Message Builder.
* Voice example no longer requires 'extras'Austin Hellyer2016-11-261-1/+0
|
* Add a bit more docsAustin Hellyer2016-11-261-0/+1
|
* Catch some clippy lintsAustin Hellyer2016-11-251-3/+0
|
* Move events into their own moduleAustin Hellyer2016-11-251-755/+0
| | | | | | | | | | | | | | | | | | | | The events were cluttering the `model` module, and so are now moved into their own `model::event` module. As users should not usually have to work with events all that much - only currently in some rarely used event handlers - this change should not be much more effort to import from. i.e.: ```rs use serenity::model::event::ChannelPinsAckEvent; ``` vs. the now-old: ```rs use serenity::model::ChannelPinsAckEvent; ```
* Rename PublicChannel to GuildChannelAustin Hellyer2016-11-251-2/+2
|
* Rename guild structs to Guild and PartialGuildAustin Hellyer2016-11-241-6/+6
|
* Rename the State to CacheAustin Hellyer2016-11-221-2/+2
|
* Rework contextual presence methodsAustin Hellyer2016-11-191-5/+5
| | | | | | | | | Rework the methods to accept strings and games directly, rather than Optional values. Instead, use the new `reset_presence` to set a clean status, or `set_presence` for more fine-grained control. In addition, `Game::playing` and `Game::streaming` now accept `&str`s rather than Strings.
* Register friend suggestion eventsAustin Hellyer2016-11-181-0/+27
|
* 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 voice connection supportAustin Hellyer2016-11-141-60/+1
|
* Add internal moduleAustin Hellyer2016-11-141-1/+1
| | | | | Create a general `internal` module, and move `prelude_internal` to `internal::prelude`.
* Add delete_message_reactions + register eventAustin Hellyer2016-11-111-0/+19
| | | | | | | | | Add the `delete_message_reactions` endpoint (`DELETE /channels/{}/messages/{}/reactions`) and implement a method on the `Message` struct for easy access, `delete_reactions`. Register the `MESSAGE_REACTION_REMOVE_ALL` event and add an event handler.
* Map op codes via a macroAustin Hellyer2016-11-091-2/+2
|
* Add webhook supportAustin Hellyer2016-11-071-0/+16
|