aboutsummaryrefslogtreecommitdiff
path: root/src/client/rest
Commit message (Collapse)AuthorAgeFilesLines
* Restructure modulesZeyla Hellyer2017-05-222-2039/+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.
* Add support for retrieving invites with countsMei2017-05-181-2/+8
| | | | | | | Previously retrieving an invite with the `?with_counts=true` wasn't possible. Added support to `get_invite` for retrieving an invite with the counts, this requires the user to pass true to the function. The counts include `approximate_presence_count` and `approximate_member_count` which have been added to the `Invite` stuct, as well as `text_channel_count` and `voice_channel_count` to the `InviteGuild` struct.
* Fix guild leaving resultZeyla Hellyer2017-05-051-7/+2
| | | | | | | | | | | | | | | | When leaving a guild, `rest::leave_guild` would attempt to deserialize a JSON body containing a partial amount of guild info, resulting in an error: ``` Could not leave guild: Json(ErrorImpl { code: EofWhileParsingValue, line: 1, column: 0 }) ``` Although the bot would still actually leave the guild, it would always return this error. To fix this, don't try to deserialize anything and only check for a 204 instead.
* Fix ratelimiting on `Route::None` routesZeyla Hellyer2017-04-191-0/+2
| | | | | | | Routes with a `Route::None` - to indicate not to keep a ratelimit bucket - would enter a loop on the route. To fix this, add an `else` block to the check for whether the route is _not_ `Route::None`, and return from it.
* Deprecate methods prefixed with `get_`Zeyla Hellyer2017-04-191-6/+6
| | | | | | 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.
* Fix `client::rest::delete_webhook_with_token` testZeyla Hellyer2017-04-111-0/+1
| | | | | | | | The doctest for this function did not have an ending code fence, causing the remaining documentation to be lexed as part of the doctest. To fix this, add a code fence after the code and prior to the named anchor links.
* Switch to using serde for deserializationZeyla Hellyer2017-04-111-103/+113
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-052-118/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-251-10/+4
|
* Add slightly more documentationZeyla Hellyer2017-03-251-0/+199
|
* Fix Member methods due to variant joined_at valuesZeyla Hellyer2017-03-201-3/+6
| | | | | | | | | | | | | | | 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 rest::send_fileZeyla Hellyer2017-03-171-1/+8
| | | | | | Remove usage of `Value::to_string` - which would encapsulate the produced value with quotation marks - and instead match the type of value and wwrite the text accordingly.
* Remove invite acceptingZeyla Hellyer2017-03-041-45/+0
|
* Fix client::rest::get_guilds doctestZeyla Hellyer2017-03-031-1/+1
| | | | | The doctest did not pass by reference per an update caused by 28743c8632458b79b472e3719d4754b57e116ad0.
* Fix some clippy lintsZeyla Hellyer2017-02-281-4/+2
|
* Pass by reference where possibleZeyla Hellyer2017-02-282-65/+59
| | | | | | | A lot of the `rest` methods took - for example a Map - by value, where they could instead take a reference. While this only prevents one clone in the library, user-land code should no longer need to clone maps when using the `rest` module.
* Re-export hyper status enums in rest moduleZeyla Hellyer2017-02-121-1/+2
|
* Uniquely ratelimit message deletionsZeyla Hellyer2017-02-122-5/+30
| | | | | | | | | | | | | | | | | Message deletions fall under a separate ratelimit apart from the route's global ratelimit, and so the DELETE verb for the route is now separately handled. This is documented [here] as the following (at the time of this writing): > There is currently a single exception to the above rule regarding > different HTTP methods sharing the same rate limit, and that is for > the deletion of messages. Deleting messages falls under a separate, > higher rate limit so that bots are able to more quickly delete content > from channels (which is useful for moderation bots). [here]: https://discordapp.com/developers/docs/topics/rate-limits#rate-limits
* Handle unsuccessful responses before decodingZeyla Hellyer2017-02-111-4/+10
| | | | | | | Instead of assuming every request is successful, check that the class of the status is successful (2xx), and if not, return a `ClientError::InvalidRequest`, which is a renamed `ClientError::UnexpectedStatusCode`.
* Expose and document ratelimitingAustin Hellyer2017-02-051-9/+71
|
* Make GLOBAL ratelimit mutex a unitAustin Hellyer2017-02-052-4/+12
| | | | | Instead of making the GLOBAL ratelimit arc-mutex a RateLimit, make it an empty unit.
* Make Guild::create_channel return a GuildChannelAustin Hellyer2017-01-251-2/+2
| | | | | | | | | | | Instead of returning a generic `Channel` enum, make the following functions return an explicit GuildChannel instead of a more "generic" Channel enum: - Guild::create_channel - GuildId::create_channel - PartialGuild::create_channel - rest::create_channel
* Fix docs linksAustin Hellyer2017-01-241-2/+10
|
* Properly drop on bindsAustin Hellyer2017-01-242-3/+3
| | | | | | | 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.
* Code styleAustin Hellyer2017-01-241-56/+26
|
* Change rest::execute_webhooks to a POSTAustin Hellyer2017-01-241-1/+1
|
* Switch to a mostly-fully OOP approachAustin Hellyer2017-01-231-2/+1
| | | | | | 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.
* Make a single POST on guild role createAustin Hellyer2017-01-181-2/+2
| | | | | The endpoint to create a role no longer returns an empty role which must be PATCHed, and can be completed in the initial request.
* Return a User from rest::get_userAustin Hellyer2017-01-041-2/+2
|
* Remove user logout endpointAustin Hellyer2017-01-011-7/+0
|
* Fix typoIllia2016-12-312-4/+4
|
* Add guild and channel searchAustin Hellyer2016-12-292-1/+70
|
* Fix current application decodingAustin Hellyer2016-12-181-4/+13
| | | | | | | | | The endpoint for retrieving the current application does not return a `flags`, so don't try to decode it. Additionally, rename `get_application_info` to `get_current_application_info` and create a new `get_application_info` for getting the current user's applications by Id.
* Don't mutate token for bots on profile changezeyla2016-12-131-2/+4
|
* Fix some clippy lintsAustin Hellyer2016-12-091-1/+1
|
* Change all try's into ?sacdenisSK2016-12-072-118/+118
| | | This breaks compatibility with < 1.13, but we didn't support that anyway.
* Use proper comments on inline ratelimit commentsAustin Hellyer2016-12-041-2/+2
|
* Fix rest::get_guilds doctestAustin Hellyer2016-12-031-3/+4
|
* Make rest::edit_profile set new tokenAustin Hellyer2016-12-031-2/+20
| | | | | | | | | | | If a user account changes their profile settings, they'll receive a new token; update the locally stored token for REST requests with this token. Additionally, the `Context::edit_profile` does not need mutability over self. Fixes #25.
* Paginate rest::get_guilds and add helper methodsAustin Hellyer2016-12-021-5/+43
| | | | | | | | | | | | | | | | | | | | Paginate the rest::get_guilds endpoint, which can be used to retrieve the guilds after-or-before a certain guild's Id, with a limit of results to return (100 is the max). Example usage: ```rs use serenity::client::rest::GuildPagination; let target = GuildPagination::After(GuildId(81384788765712384)); let guilds = context.get_guilds(target, 50); ``` Additionally, add a method of `CurrentUser::guilds()`, to retrieve the current user's guilds. A limit of 100 is set, as (most) users can not be in more than 100 guilds.
* Fix start_integration_syncabalabahaha2016-11-301-2/+2
|
* Add remaining REST routesAustin Hellyer2016-11-302-8/+70
| | | | | | The status routes were missing from the HTTP module (now the REST module) rewrite, as well as the `GET /guilds/:id/members` route. In addition, remove an unnecessary counter to the global ratelimit mutex.
* Clean up the codebaseAustin Hellyer2016-11-291-4/+4
|
* Add missing REST methodsAustin Hellyer2016-11-281-3/+31
|
* Improve docs and add new message builder methodsIllia K2016-11-281-14/+12
| | | | | Add documentation for some missing methods - such as Game methods - and add more methods to the Message Builder.
* Add Context, REST, and model documentationfwrs2016-11-271-4/+72
| | | | | Add documentation for Context methods, as well as brief documentation for REST functions and model definitions.
* Make send_file use the CreateMessage builderAustin Hellyer2016-11-271-4/+17
|
* Tiny import re-orderAustin Hellyer2016-11-261-2/+1
|
* Rename PublicChannel to GuildChannelAustin Hellyer2016-11-251-12/+12
|
* Rename the `http` module to `rest`Austin Hellyer2016-11-252-0/+1608