aboutsummaryrefslogtreecommitdiff
path: root/src/ext
Commit message (Collapse)AuthorAgeFilesLines
* Restructure modulesZeyla Hellyer2017-05-2219-4191/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Reasonably derive Debug on itemsZeyla Hellyer2017-05-222-0/+2
|
* Remove more remaining selfbot supportZeyla Hellyer2017-05-221-2/+0
| | | | We removed these a long time ago, and these were missed.
* Allow unreachable_code lint in command! macroKen Swenson2017-05-181-4/+4
| | | | | If a user returns at the end of a `command!` macro block, the library's return value will never be processed, as it's unreachable. Instead of warning for this, allow it.
* Fix no-cache framework compilationZeyla Hellyer2017-05-131-7/+14
|
* Framework: trim content before parsing argsMaiddog2017-05-121-7/+11
|
* Check if message starts with dynamic_prefix resultMaiddog2017-05-081-1/+3
|
* Add framework dynamic_prefix exampleZeyla Hellyer2017-05-041-2/+24
|
* Clippy lintsZeyla Hellyer2017-04-191-15/+13
|
* Accept a slice of args in help commandsZeyla Hellyer2017-04-194-5/+5
| | | | | The help commands don't actually need to have the arguments passed by value, so passing them by reference is fine.
* Deprecate methods prefixed with `get_`Zeyla Hellyer2017-04-192-11/+77
| | | | | | 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.
* Update the way errors are handled in dispatchIllia2017-04-192-401/+172
|
* Add Shard Id helpersZeyla Hellyer2017-04-121-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-113-47/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Clippy lints + permission byte literalsZeyla Hellyer2017-04-093-11/+11
| | | | | 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-097-220/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-055-107/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Improve some framework docsZeyla Hellyer2017-03-251-5/+16
|
* Fix testsZeyla Hellyer2017-03-251-1/+2
|
* Add slightly more documentationZeyla Hellyer2017-03-251-0/+22
|
* Fix Member methods due to variant joined_at valuesZeyla Hellyer2017-03-201-0/+1
| | | | | | | | | | | | | | | Fix an issue where the library would check the Id of the guild that a member is in by checking the Member's ID and joined_at value with those of the members of guilds present in the cache. Performing this check would have the issue of where a joined_at for a member received over websocket would potentially have a varying value than that of the same member retrieved over REST. To fix this, attach the relevant guild's Id to the member on creation, where the Id is available. Fixes #68.
* Fix deadlock/panic on channel create event for private messagesSteffen Schröter2017-03-191-1/+1
|
* Fix incorrect cache exampleSteffen Schröter2017-03-171-1/+1
|
* Update doctests for Context changesZeyla Hellyer2017-02-153-14/+12
| | | | | | | | | | | | | | | | | | | Due to the Context having many methods removed, the doctests were failing. Update the doctests to use alternative methods to accomplish the same. Example: Before: ```rust context.say("hi"); ``` After: ```rust message.channel_id.say("hi") ```
* Remove most Context methodsZeyla Hellyer2017-02-122-22/+24
| | | | | | Most of the methods in the Context were for interacting with the related ChannelId, but these methods have been re-implemented on ChannelId itself, and is now the preferred (and now only) way to interact with it.
* Fix a not-if-else lintZeyla Hellyer2017-02-121-3/+3
|
* Small amount of voice docsZeyla Hellyer2017-02-114-5/+24
|
* Allow standalone voice connectionsZeyla Hellyer2017-02-112-151/+245
| | | | | | | | Allow voice connections be built standalone from the primary websocket connection to the gateway. This has the side-effect of reduced functionality (e.g. muting or deafening only update the internal handler state), but allows voice connections to be handled independently from the rest of the lib.
* Remove improper uses of `map` in the cachealex2017-02-101-63/+23
|
* Optimize cachingZeyla Hellyer2017-02-092-272/+413
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Fix unreachable patterns in command macroAustin Hellyer2017-02-011-1/+1
| | | | | | | | | When attempting to use a named argument with a type of String, the framework will try to parse the received argument - a String - into a String. This can never fail, so Rust warns that the `Err` arm of the `match` can never be reached. Let's just ignore that and everything will be fine.
* Fix docs linksAustin Hellyer2017-01-245-19/+16
|
* Properly drop on bindsAustin Hellyer2017-01-242-13/+10
| | | | | | | Instead of binding to `_why`, bind to `_`, dropping the value. This is pretty much just leftover from when the library was being rapidly developed before being released.
* Switch to a mostly-fully OOP approachAustin Hellyer2017-01-232-12/+11
| | | | | | 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.
* First round of deleting useless methodsAustin Hellyer2017-01-151-6/+30
|
* Code style cleanupAustin Hellyer2017-01-081-1/+1
|
* hashmap of usagesTaavetti Sjelkov2017-01-021-1/+1
|
* Feature-flag a framework checkAustin Hellyer2017-01-021-5/+8
|
* Relisting 'Commands:' is redundant in embed helpAustin Hellyer2017-01-011-2/+0
|
* Implement context message queueingTaavi2017-01-016-36/+40
| | | Also the dreaded `ctx <<= "something"` which is actually a mistake.
* Fix command macro signaturesAustin Hellyer2016-12-311-4/+4
|
* Fix typoIllia2016-12-312-4/+4
|
* Add command alias support and command.exampletaavi?2016-12-295-64/+155
|
* Use $crate in the command macroalex2016-12-241-4/+4
|
* Fix grammar in framework help the commandzeyla2016-12-211-1/+1
|
* (╯°□°)╯︵ ┻━┻Austin Hellyer2016-12-192-2/+3
|
* Clarify command missing argument messageAustin Hellyer2016-12-191-1/+1
|
* Fix framework message position boundary splitsAustin Hellyer2016-12-181-18/+21
| | | | | | | The framework would take the length of the prefix in bytes, and then search for a command either directly after the byte length _and_ plus one for a command. Instead, ensure that the message is longer than the prefix.
* Default Framework command use_quotes to falseAustin Hellyer2016-12-181-1/+1
|
* Add framework config to ignore webhook messagesIllia2016-12-182-1/+23
|