aboutsummaryrefslogtreecommitdiff
path: root/src/client/dispatch.rs
Commit message (Collapse)AuthorAgeFilesLines
* Change signature of EventHandler::message_update and the dispatch call to ↵fix_message_updateMishio5952018-09-051-3/+1
| | | | account for situations where the new message is not cached
* Old message on update (#368)Adelyn2018-08-261-2/+9
|
* Fix erroneous deadlock detected messages. (#363)Lymia Aluysia2018-08-081-10/+10
|
* Fix compilation + tests on certain feature combosZeyla Hellyer2018-08-071-0/+1
| | | | | | | | On certain feature combinations, compilation and tests would not function correctly. This commit goes through a number of feature combinations and gates some tests behind the required features and fixes other compilation errors.
* Fix potential dispatch cache deadlocking + log itZeyla Hellyer2018-08-021-1/+12
| | | | | | Fix the dispatch functionality potentially deadlocking when a deadlock has occurred elsewhere (or a read/write lock is forever held elsewhere), and log when it happens, WARNing the user that a possible deadlock has happened.
* Add missing `mut`acdenisSK2018-08-021-1/+1
|
* Don't delay Ready with cache enabledZeyla Hellyer2018-08-011-46/+5
| | | | | | | | | | | When the cache is enabled, don't delay the Ready until all guilds have been received. This never really worked in the first place and duplicates the "cached" logic that fires when all guilds have been received. This presumably fixes the "silent death" bug, as this appears to stall the thread on certain conditions.
* De-cringe a commentacdenisSK2018-08-011-3/+3
|
* Add a message cache API (#345)zeyla2018-07-091-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds an API for message caching. By default this caches 0 messages per channel. This can be customized when instantiating: ```rust use serenity::cache::{Cache, Settings}; let mut settings = Settings::new(); // Cache 10 messages per channel. settings.max_messages(10); let cache = Cache::new_with_settings(settings); ``` After instantiation: ```rust use serenity::cache::Cache; let mut cache = Cache::new(); cache.settings_mut().max_messages(10); ``` And during runtime through the global cache: ```rust use serenity::CACHE; CACHE.write().settings_mut().max_messages(10); ```
* Fix panics on guild member update dispatchesZeyla Hellyer2018-04-261-10/+12
| | | | | | | | Fixes panics for Guild Member Update dispatches, a retrieval for the new version of the member sooner and checking that the member exists prior to dispatching. Closes #264.
* Refactor imports/exports to use nested groups and better formattingacdenisSK2018-03-291-5/+9
|
* Fix no-cache standardframework compilation (#290)Lakelezz2018-03-151-1/+1
|
* Use an InterMessage to communicate over gatewayZeyla Hellyer2018-01-181-5/+5
| | | | | | | Instead of communicating over the gateway in a split form of a `serde_json::Value` or a `client::bridge::gateway::ShardClientMessage`, wrap them both into a single enum for better interaction between the client, gateway, and voice modules.
* Resolve no-framework client compilationZeyla Hellyer2018-01-021-2/+2
|
* Update dispatch.rsZeyla Hellyer2018-01-021-1/+1
|
* Fix no-framework dispatchingZeyla Hellyer2018-01-021-1/+1
|
* Add an event for shard updatesZeyla Hellyer2018-01-011-43/+57
| | | | | Add an event in the EventHandler to be called when a shard updates its Connection Stage.
* Fix most clippy lints, take more refeerncesZeyla Hellyer2017-12-161-44/+45
| | | | | Fix clippy lints and subsequently accept references for more function parameters.
* Break up the model moduleZeyla Hellyer2017-12-161-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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}; ```
* Use the threadpool for framework command executionZeyla Hellyer2017-11-131-121/+283
| | | | | | | Instead of executing framework commands in the shard runner thread (potentially blocking the shard runner from reading new messages over the websocket and heartbeating), dispatch framework commands to the shard runner's threadpool.
* Re-order use statements alphabeticallyZeyla Hellyer2017-11-111-2/+2
|
* Redo client internals + gatewayZeyla Hellyer2017-11-031-59/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit is a rewrite of the client module's internals and the gateway. The main benefit of this is that there is either 0 or 1 lock retrievals per event received, and the ability to utilize the ShardManager both internally and in userland code has been improved. The primary rework is in the `serenity::client` module, which now includes a few more structures, some changes to existing ones, and more functionality (such as to the `ShardManager`). The two notable additions to the client-gateway bridge are the `ShardMessenger` and `ShardManagerMonitor`. The `ShardMessenger` is a simple-to-use interface for users to use to interact with shards. The user is given one of these in the `serenity::client::Context` in dispatches to the `serenity::client::EventHandler`. This can be used for updating the presence of a shard, sending a guild chunk message, or sending a user's defined WebSocket message. The `ShardManagerMonitor` is a loop run in its own thread, potentially the main thread, that is responsible for receiving messages over an mpsc channel on what to do with shards via the `ShardManager`. For example, it will receive a message to shutdown a single shard, restart a single shard, or shutdown the entire thing. Users, in most applications, will not interact with the `ShardManagerMonitor`. Users using the `serenity::client::Client` interact with only the `ShardMessenger`. The `ShardManager` is now usable by the user and is available to them, and contains public functions for shutdowns, initializations, restarts, and complete shutdowns of shards. It contains utility functions like determining whether the `ShardManager` is responsible for a shard of a given ID and the IDs of shards currently active (having an associated `ShardRunner`). It can be found on `serenity::client::Client::shard_manager`. Speaking of the `ShardRunner`, it no longer owns a clone of an Arc to its assigned `serenity::gateway::Shard`. It now completely owns the Shard. This means that in order to open the shard, a `ShardRunner` no longer has to repeatedly retrieve a lock to it. This reduces the number of lock retrievals per event dispatching cycle from 3 or 4 depending on event type to 0 or 1 depending on whether it's a message create _and_ if the framework is in use. To interact with the Shard, one must now go through the previously mentioned `ShardMessenger`, which the `ShardRunner` will check for messages from on a loop. `serenity::client::Context` is now slightly different. Instead of the `shard` field being `Arc<Mutex<Shard>>`, it is an instance of a `ShardMessenger`. The interface is the same (minus losing some Shard-specific methods like `latency`), and `Context`'s shortcuts still exist (like `Context::online` or `Context::set_game`). It now additionally includes a `Context::shard_id` field which is a u64 containing the ID of the shard that the event was dispatched from. `serenity::client::Client` has one changed field name, one field that is now public, and a new field. `Client::shard_runners` is now `Client::shard_manager` of type `Arc<Mutex<ShardManager>>`. The `Client::token` field is now public. This can, for example, be mutated on token resets if you know what you're doing. `Client::ws_uri` is new and contains the URI for shards to use when connecting to the gateway. Otherwise, the Client's usage is unchanged. `serenity::gateway::Shard` has a couple of minor changes and many more public methods and fields. The `autoreconnect`, `check_heartbeat`, `handle_event`, `heartbeat`, `identify`, `initialize`, `reset`, `resume`, `reconnect`, and `update_presence` methods are now public. The `token` structfield is now public. There are new getters for various structfields, such as `heartbeat_instants` and `last_heartbeat_ack`. The breaking change on the `Shard` is that `Shard::handle_event` now takes an event by reference and, instead of returning `Result<Option<Event>>`, it now returns `Result<Option<ShardAction>>`. `serenity::gateway::ShardAction` is a light enum determining an action that someone _should_/_must_ perform on the shard, e.g. reconnecting or identifying. This is determined by `Shard::handle_event`. In total, there aren't too many breaking changes that most of userland use cases has to deal with -- at most, changing some usage of `Context`. Retrieving information like a Shard's latency is currently not possible anymore but work will be done to make this functionality available again.
* Remove `on_` prefix to EventHandler tymethodsZeyla Hellyer2017-10-221-52/+52
| | | | | It was voted that the `on_` prefix is unnecessary, so these have been dropped.
* Update to account for changes made in 0.4.1acdenisSK2017-10-141-1/+1
|\
| * Fix clippy lintsZeyla Hellyer2017-10-111-1/+1
| |
| * Add a threadpool to the shard runnerZeyla Hellyer2017-10-091-17/+18
| | | | | | | | | | | | A threadpool will help with giving event dispatches a threaded behaviour while still allowing the library the ability to perform other actions, such as receiving new events and heartbeating over the websocket client.
* | Switch to parking_lot::{Mutex, RwLock}Zeyla Hellyer2017-10-101-11/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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); ```
* | Add a threadpool to the shard runnerZeyla Hellyer2017-10-091-17/+18
|/ | | | | | A threadpool will help with giving event dispatches a threaded behaviour while still allowing the library the ability to perform other actions, such as receiving new events and heartbeating over the websocket client.
* Remove tokio usageZeyla Hellyer2017-09-211-339/+131
|
* Fix a documentation typoZeyla Hellyer2017-09-191-1/+1
|
* Also rustfmtZeyla Hellyer2017-09-181-1/+3
|
* Fix block on spawning multiple shardsZeyla Hellyer2017-09-181-1/+1
| | | | | | | | | | | | When spawning multiple shards (via an equal number of futures - one per shard) joined on a core.run use, the very first future executed would block forever due to a sync, blocking `monitor_shard` use. While this defeats the purpose of tokio, this was meant to be a first step to an async serenity implementation. To "fix" this blocking call until a deeper async implementation is made, spawn a new thread per tokio core (and thus per shard). This causes the same expected behaviour, just with multiple threads like before.
* Apply rustfmtZeyla Hellyer2017-09-181-53/+12
|
* Fix compiles of a variety of feature combinationsZeyla Hellyer2017-09-181-23/+13
| | | | | This fixes compilation errors and warnings when compiling a mixture of non-default feature targets.
* Revamp `CacheEventsImpl`acdenisSK2017-09-121-69/+59
|
* Add `Context::handle`acdenisSK2017-09-111-43/+43
|
* Implement categoriesacdenisSK2017-09-091-0/+13
|
* Change order to avoid subtraction overflow error (#160)Maiddog2017-09-071-1/+1
|
* Prevent malformed opus data from crashing the bot process (#149)Maiddog2017-08-271-59/+65
|
* Add ability to play DCA and Opus files. (#148)Maiddog2017-08-271-15/+56
|
* Revamp `RwLock` usage in the libacdenisSK2017-08-241-118/+77
| | | | Also not quite sure if they goofed rustfmt or something, but its changes it did were a bit bizarre.
* Move builtin framework impl to its own moduleZeyla Hellyer2017-08-191-2/+2
| | | | | | | | | | | | | | | | | The framework is now moved in its entirity to the `framework` module, with the `Framework` trait currently on its own and the builtin implementation provided. The builtin implementation has been renamed to "Standard". Upgrade path: Rename the `BuiltinFramework` import to `StandardFramework`. Instead of importing builtin framework items from `serenity::framework`, import them from `serenity::framework::standard`. This is the beginning to #60. The root `framework` module (non-standard implementation) will be built more by the time it's closed.
* 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