aboutsummaryrefslogtreecommitdiff
path: root/src/client/dispatch.rs
Commit message (Collapse)AuthorAgeFilesLines
...
* Apply rustfmtZeyla Hellyer2017-08-181-11/+52
|
* Move the Framework trait to the frameworkZeyla Hellyer2017-08-181-1/+1
|
* Split event handling in the cache to a traitacdenisSK2017-08-101-18/+4
| | | | note: This trait might become like `framework::Framework` in the future.
* Change the config a bit, and a few nitpicksacdenisSK2017-07-271-4/+6
|
* rustfmtacdenisSK2017-07-271-47/+43
|
* Use a consistent indentation styleZeyla Hellyer2017-07-261-18/+18
| | | | | | | | | This project has - in the past - used an indentation style of 4 spaces, without trailing whitespace. This commit modifies lines with tab indentation to 4 spaces. Whether to use tabs or spaces is up to the current maintainer, but consistency avoids files eventually being completely mixed styles.
* Make the `framework` module feature-gated and fix the names in the helper macroacdenisSK2017-07-271-3/+3
|
* Fix condional compilation for `Framework::initialized` when ↵acdenisSK2017-07-271-18/+22
| | | | builtin-framework is turned off
* Fix #130acdenisSK2017-07-221-79/+34
| | | | Removed action support from the builtin one as well, due to it adding some uneccassery complexity and it being only asked upon by one user
* Remove more threads with futuresacdenisSK2017-07-151-6/+6
|
* Switch to tokio for events (#122)Alex Lyon2017-07-141-71/+227
|
* Fixed clippy warnings (#120)Kaidan2017-07-101-1/+1
|
* Apply the new api change for dms in botsacdenisSK2017-07-071-4/+20
|
* Add an `is_new` to the arguments of the `guild_create` handleracdenisSK2017-07-051-1/+12
| | | | To make a better distinction from a guild that the bot's already in and from the ones it's joining
* Add a macro hereacdenisSK2017-07-031-48/+32
|
* Merge branch "trait-based-event-handling"acdenisSK2017-06-281-300/+220
|
* Add reaction actions (#115)alex2017-06-281-16/+87
| | | Fixes #87
* Add an `on_cached` event (#114)alex2017-06-281-8/+49
| | | | Fixes #89
* Fix no-framework compilationZeyla Hellyer2017-06-141-1/+1
|
* Remove Context::{channel_id, queue}Zeyla Hellyer2017-06-131-58/+41
| | | | | | | | | The `channel_id` field on Context is no longer required internally, and is no longer of use to userland as event handlers are given the channel ID in some way where possible. `queue` is a remnant from when the Context was the primary way to interact with the REST API.
* Fix compilations across feature combinationsZeyla Hellyer2017-06-021-1/+2
|
* Fix client-feature, no-model compilesZeyla Hellyer2017-06-011-3/+21
| | | | | | | Some of the methods used in the client dispatch, namely `Channel::id` and `Message::transform_content`, are not _required_ for functionality by the dispatcher. Since these methods are `model` features, they can be gated behind a `model` feature cfg.
* Restructure modulesZeyla Hellyer2017-05-221-1/+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.
* Handle message type 7 (member join)illia k2017-05-221-2/+6
| | | | | | | | | | When message type 7 is received from the gateway, transform the content if the type is 7 to a proper greeting. Additionally, when the type is 6, provide a proper content notifying that a user has pinned a message to the channel. These transformations are not done at REST-level when retrieving messages, and are instead done in `ChannelId::message` and `ChannelId::messages`.
* Remove ChannelPinsAck/MessageAck eventsZeyla Hellyer2017-04-191-7/+0
| | | | | These events are mostly only userbot events and were leftover from userbot support.
* Deprecate methods prefixed with `get_`Zeyla Hellyer2017-04-191-4/+2
| | | | | | A lot of structs - such as `Guild` or `ChannelId` - have methods with prefixes of `get_`, which are generally discouraged. To fix this, deprecate them and remove them in v0.3.0.
* Clippy lints + permission byte literalsZeyla Hellyer2017-04-091-1/+1
| | | | | Perform a number of various clippy lints, and rewrite the permissions values to use byte literals instead of bitshifts.
* Remove support for group calls and guild syncZeyla Hellyer2017-04-091-57/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Calls and guild sync are essentially leftovers from selfbot support removal, the former moreso. Removes the following `model::event` structs: - CallCreateEvent - CallDeleteEvent - CallUpdateEvent - GuildSyncEvent which also removes the following `model::event::Event` variants: `client::gateway::Shard::sync_calls` has been removed. The following `client::Client` methods have been removed: - `on_call_create` - `on_call_delete` - `on_call_update` - `on_guild_sync` Removes the following items on `ext::cache::Cache`: ``` ext::cache::Cache::{ // fields calls, // methods get_call, update_with_call_create, update_with_call_delete, update_with_call_update, update_with_guild_sync, } ``` Voice structs and methods now take solely a `guild_id` instead of a `target`, due to the handling of 1-on-1 and group calls being removed. This continues off commit d9118c0.<Paste>
* Remove selfbot supportZeyla Hellyer2017-04-051-197/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While selfbots have always been "roughly tolerated", lately they have been tolerated to less of a degree. The simple answer is to no longer support selfbots in any form. This is done for a few of reasons: 1) in anticipation of selfbots no longer being tolerated; 2) there are few reasons why one should make a selfbot in Rust and not a scripting language; 3) there are alternatives (i.e. discord-rs) that still support userbots. Selfbots are simply not a goal of the maintainer of serenity. Upgrade path: Don't use selfbots with serenity. Use discord-rs instead. The following has been removed: Enums: - `RelationshipType` Structs: - `FriendSourceFlags` - `ReadState` - `Relationship` - `SearchResult` - `SuggestionReason` - `Tutorial` - `UserConnection` - `UserGuildSettings` - `UserSettings` Removed the following fields: - `CurrentUser::mobile` - Ready::{ analytics_token, experiments, friend_suggestion_count, notes, read_state, relationships, tutorial, user_guild_settings, user_settings, } Removed the following methods: - `Client::login_user` Deprecated `Client::login_bot` in favour of `Client::login`. Removed `client::LoginType`. The following no longer take a `login_type` parameter: - `Context::new` - `Shard::new` `Shard::sync_guilds` has been removed. The `client::Error::{InvalidOperationAsBot, InvalidOperationAsUser}` variants have been removed. The following event handlers on `Client` have been removed: - `on_friend_suggestion_create` - `on_friend_suggestion_delete` - `on_relationship_add` - `on_relationship_remove` - `on_user_guild_settings_update` - `on_note_update` - `on_user_settings_update` The following `client::rest` functions have been removed: - `ack_message` - `edit_note` - `get_user_connections` - `search_channel_messages` - `search_guild_messages` The following `client::rest::ratelimiting::Route` variants have been removed: - `ChannelsIdMessagesSearch` - `GuildsIdMessagesSearch` - `UsersMeConnections` The following fields on `ext::cache::Cache` have been removed: - `guild_settings` - `relationships` - `settings` while the following methods have also been removed: - `update_with_relationship_add` - `update_with_relationship_remove` - `update_with_user_guild_settings_update` - `update_with_user_note_update` - `update_with_user_settings_update` The following methods have been removed across models: - `ChannelId::{ack, search}` - `Channel::{ack, search}` - `Group::{ack, search}` - `GuildChannel::{ack, search}` - `GuildId::{search, search_channels}` - `Guild::{search, search_channels}` - `Message::ack` - `PartialGuild::{search, search_channels}` - `PrivateChannel::{ack, search}` - `UserId::{delete_note, edit_note}` - `User::{delete_note, edit_note}` The following events in `model::events` have been removed: - `FriendSuggestionCreateEvent` - `FriendSuggestionDeleteEvent` - `MessageAckEvent` - `RelationshipAddEvent` - `RelationshipRemoveEvent` - `UserGuildSettingsUpdateEvent` - `UserNoteUpdateEvent` - `UserSettingsUpdateEvent` Consequently, the following variants on `model::event::Event` have been removed: - `FriendSuggestionCreate` - `FriendSuggestionDelete` - `MessageAdd` - `RelationshipAdd` - `RelationshipRemove` - `UserGuildSettingUpdate` - `UserNoteUpdate` - `UserSettingsUpdate` The `utils::builder::Search` search builder has been removed.
* Optimize cachingZeyla Hellyer2017-02-091-9/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Don't clone the contextAustin Hellyer2017-01-281-6/+4
|
* Don't clone on non-framework message createsAustin Hellyer2017-01-271-5/+4
|
* Fix no-framework compilesAustin Hellyer2017-01-241-2/+2
|
* Avoid a lot of Arc/Message/RwLock clonesAustin Hellyer2017-01-241-328/+155
| | | | | | | When passing monitoring info from the shard handler to the dispatch function, pass arguments by reference instead of by cloning and passing by reference. Additionally, don't re-clone handler Arcs and temporary Messages.
* Use conditional blocks over macrosAustin Hellyer2016-12-291-24/+39
|
* 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-1/+1
| | | | Additionally, flag imports behind feature flags to avoid unused imports.
* Add a ShareMap across contextsAustin Hellyer2016-12-051-39/+60
| | | | | | | | The context now exposes, through the Client, a `data` field, which can be accessed safely across contexts. This allows for a custom "shared state" without the need for (ab)using lazy-static.rs. Refer to example 06 for an example on how to use shared data.
* Encase the event storage in an Arc<RwLock>Austin Hellyer2016-12-021-6/+6
| | | | | | Commands should be dispatched more quickly with this patch. This brings down a (locally-tested) average "ping" command response from 278ms to 67ms.
* Make Cache::get_channel return a referenceAustin Hellyer2016-11-261-1/+2
| | | | | | | Additionally, allow it to search the groups' and private channels' maps in the cache. As these are usually O(1) operations, it's cheap to allow, in comparison to the current unoptimized method of getting a guild's channel.
* Move events into their own moduleAustin Hellyer2016-11-251-1/+2
| | | | | | | | | | | | | | | | | | | | 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; ```
* Change the CACHE to be an RwLockAustin Hellyer2016-11-221-7/+7
| | | | | | | | | | | | | | | | | | 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-33/+33
|
* Re-organize the client moduleAustin Hellyer2016-11-211-5/+6
| | | | | | | | | | | | | | | | | | Re-organize the client module, creating a `gateway` submodule, and splitting the connection into separate files in it. The connection was a conglomeration of a number of purposes, most of which are actually used elsewhere in the library and/or exposed to the user. Thus, it makes sense to separate each item in a gateway-specific module. By splitting the client module further, this is a re-organization for preliminary RPC support WRT the Client. Additionally, rename the Connection struct to a Shard. The Connection itself was not the actual connection, and was a higher-level interface to the real connection logic. A Shard is a more accurate representation of what it actually is.
* Rename state methods from find_ to get_Austin Hellyer2016-11-191-2/+2
| | | | | | | | | | For consistency with the rest of the library, rename the methods prefixed with `find_` to `get_`. The past logic was that items are "found", as they may or may not exist. With get, the expectation is that it is _always_ there, i.e. over REST. However, this is inconsistent, and "get"ting over REST can fail for other reasons.
* Fix type errors for non-framework buildsAustin Hellyer2016-11-191-1/+1
|
* Nonblocking connectionAustin Hellyer2016-11-191-8/+5
| | | | | | | | | | | The connection is now non-blocking, allowing user event handlers to immediately unlock it themselves (assuming they haven't unlocked it elsewhere), rather than waiting on the library to receive an event. This is done by decoupling the receiver away from the connection, which is not necessarily "directly" associated with the connection. This needs a _lot_ of code cleanup later.
* Fix cond. compile across multiple feature targetsAustin Hellyer2016-11-191-26/+41
| | | | | | | | Fixes conditional compilation across multiple combinations of feature targets, where it was assumed a second feature would be enabled by something that requires a feature to be enabled. This also fixes an EOF compilation error on no-feature builds.
* Register friend suggestion eventsAustin Hellyer2016-11-181-0/+20
|
* Add state/framework/etc. conditional compile flagsAustin Hellyer2016-11-151-149/+281
| | | | | | | | | | | | | | | 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.