aboutsummaryrefslogtreecommitdiff
path: root/src/utils
Commit message (Collapse)AuthorAgeFilesLines
* Fix internal enum being exportedZeyla Hellyer2017-05-131-1/+0
|
* Add faded_purple to colour listMei2017-05-131-1/+3
| | | Add `faded_purple` as a Colour, and rename `meibi_pink` to `meibe_pink`.
* Use constant for preset permissionsZeyla Hellyer2017-05-021-2/+2
| | | | | | | | Instead of having methods which return a preset value, use constants since the actual values are themselves constant. Deprecate the previous methods and move documentation to the new constants.
* Add `is_nsfw` check to channelsZeyla Hellyer2017-04-261-0/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A new feature in Discord is warning users about NSFW channels. This can be useful when wanting to determine if a command can be used in a channel or not, depending on the command content. To help with this, provide a utility function named `utils::is_nsfw`. This function accepts a channel name, which determines if the channel is NSFW. This information is not provided with data from the server. It is determined client-side based on a few rules. The rules for a channel being NSFW are: - must be a guild channel - must be a text channel - must be named `nsfw` or be prefixed with `nsfw-` If any of these conditions are false, then the channel is not NSFW. Additionally, provide four helper methods: - `GuildChannel::is_nsfw`: follows rules - `Group::is_nsfw`: always false - `PrivateChannel::is_nsfw`: always false - `Channel::is_nsfw`: depends on inner channel (one of 3 above) This check is volatile, as Discord may change requirements at any time. The check provided by the library should not be taken as being accurate all the time.
* 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.
* Check for embed lengths on message sendsZeyla Hellyer2017-04-191-3/+3
| | | | | | | | | | | | | | | | | | | | | | Due to the maximum length of the textual content of an embed being 4000, this should be checked prior to message sending. Embeds have a fairly new limit of only being 4000 character long, at maximum. The length of these fields - where present - should be summed, so that bad requests are not made with embeds that are too large in text. The fields that count as "textual" includes: - author name - description - `name` and `value` of each field - footer text - title If this exceeds the limit - currently at 4000 unicode codepoints - then a `ClientError::EmbedTooLarge` will be returned, including the number of codepoints overflowing.
* Deprecate methods prefixed with `get_`Zeyla Hellyer2017-04-191-26/+62
| | | | | | 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.
* Add Shard Id helpersZeyla Hellyer2017-04-121-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-1112-224/+324
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 selfbot supportZeyla Hellyer2017-04-053-322/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Update search paramsZeyla Hellyer2017-03-252-201/+135
|
* Add slightly more documentationZeyla Hellyer2017-03-251-0/+2
|
* Remove sending message noncesZeyla Hellyer2017-02-271-10/+0
|
* Add missing send_file/send_message implsZeyla Hellyer2017-02-251-3/+10
| | | | | | | | | | | | Add the `send_file` method to: - `model::Channel` - `model::Group` - `model::GuildChannel` Add the `send_message` method to: - `model::Channel` Additionally, add more documentation for these with an example.
* Update doctests for Context changesZeyla Hellyer2017-02-155-15/+14
| | | | | | | | | | | | | | | | | | | 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") ```
* Add method to EditGuild to transfer ownershipZeyla Hellyer2017-02-071-1/+8
| | | | | There used to be a method to do the equivilant but was lost in the move to an OOP pattern, so this should be re-added back.
* Remove lifetime on SearchZeyla Hellyer2017-02-071-4/+4
|
* Fix docs linksAustin Hellyer2017-01-247-17/+21
|
* Switch to a mostly-fully OOP approachAustin Hellyer2017-01-231-19/+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.
* allow quotes to be escaped in quote parserIllia2017-01-151-1/+5
|
* Convert Colour to be a tuple structAustin Hellyer2017-01-133-24/+17
| | | | The struct only has one field (`value`) anyway.
* Stop abusing unicode for sanitisationIllia2017-01-111-6/+6
|
* Use zero-width space for mention preventionIllia2017-01-111-13/+13
|
* Use CDN for default avatarsAustin Hellyer2017-01-091-1/+4
|
* Add User::default_avatar_url() methodAustin Hellyer2017-01-081-0/+10
|
* Add Rohrkatze Blue to Colour structBrendan McCarthy2017-01-061-0/+2
|
* Fix rs suffixIllia2017-01-052-2/+2
|
* Add Meibi Pink to coloursMei2017-01-021-0/+2
|
* Implement context message queueingTaavi2017-01-011-6/+5
| | | Also the dreaded `ctx <<= "something"` which is actually a mistake.
* Fix doctestAustin Hellyer2016-12-311-12/+17
|
* Fix typoIllia2016-12-313-6/+6
|
* Add guild and channel searchAustin Hellyer2016-12-292-0/+381
|
* Use conditional blocks over macrosAustin Hellyer2016-12-291-112/+0
|
* Remove image/thumbnail embed buildersAustin Hellyer2016-12-182-84/+13
| | | | | | | | When implemented, it was thought that images and thumbnails would be able to have their height/width specified. This isn't the case, and so the image/height methods were deprecated on the builders. Time has passed, so just remove them in favour of direct methods on CreateEmbed instead.
* Allow time::Tm to be passed into embed timestampAustin Hellyer2016-12-181-9/+44
|
* No Z or +XX:XXChristopher F2016-12-181-3/+4
| | | | Eventual Consistency:tm:
* Add documentation regarding ISO-8601 to embedsChristopher F2016-12-181-0/+7
|
* Make Id displays format u64 instead of a mentionAustin Hellyer2016-12-171-3/+3
| | | | | | Instead of mentioning the channel, role, or user on an Id display format, format its inner u64 instead. Instead, use `Id::mention()` to accomplish the equivilant.
* Implement command groups and bucketsIllia2016-12-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Implement command groups * change to ref mut * Implement framework API. * Remove commands field * Make it all work * Make example use command groups * Requested changes * Implement adding buckets * Add ratelimit check function * Finish everything * Fix voice example * Actually fix it * Fix doc tests * Switch to result * Savage examples * Fix docs * Fixes * Accidental push * 👀 * Fix an example * fix some example * Small cleanup * Abstract ratelimit bucket logic
* More config for CreateCommand, add various methodsIllia2016-12-101-24/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Deprecate embed image/thumbnail height/widthAustin Hellyer2016-12-091-36/+10
| | | | | | The height and width fields for embed images and thumbnails can not be set - whereas originally there may have been plans to - so deprecate them and remove in v0.3.0.
* Abstract command fields to typesAustin Hellyer2016-12-091-15/+13
|
* Command builder, quoted args, and multi-prefixesIllia2016-12-091-0/+46
| | | | | Add a command builder, which can take arguments such as multiple checks, quoted arguments, and multiple prefix support, as well as dynamic prefixes per context.
* Implement From<Embed> for CreateEmbedAustin Hellyer2016-12-081-1/+70
|
* Change all try's into ?sacdenisSK2016-12-072-9/+9
| | | This breaks compatibility with < 1.13, but we didn't support that anyway.
* Allow mentionable structs to be used as command argumentsIllia2016-12-071-0/+83
| | | | | Add EmojiIdentifier, allow User, UserId, Role, RoleId, EmojiIdentifier, Channel and ChannelId to be used as arguments for commands and add more parsing functions to utils
* Add more Context docs+permission requirementsAustin Hellyer2016-12-041-1/+22
| | | | | Add more documentation to most of the Context methods, also clarifying which permission/s are required for each method.
* Add documentation for modelsIllia2016-12-041-3/+8
|
* Make Member::colour() return an optional colourAustin Hellyer2016-12-031-2/+1
|