Skip to main content

djs_rest/endpoints/
mod.rs

1//! Typed methods for REST endpoints, one module per resource (D-082, D-091).
2
3mod application;
4mod application_command;
5mod application_identity_profile;
6mod application_role_connection_metadata;
7mod audit_log;
8mod auto_moderation;
9mod channel;
10mod emoji;
11mod entitlement;
12mod guild;
13mod guild_scheduled_event;
14mod guild_template;
15mod interaction;
16mod invite;
17mod lobby;
18mod message;
19mod oauth2;
20mod poll;
21mod sku;
22mod soundboard;
23mod stage_instance;
24mod sticker;
25mod subscription;
26mod user;
27mod voice;
28mod webhook;
29
30use djs_model::{
31    permissions::Permissions,
32    rest::{Gateway, GatewayBot},
33};
34use serde::Deserialize;
35
36use crate::client::boxed;
37use crate::{Error, Request, Rest, Route};
38
39/// The response of the computed permission endpoints (channel and guild), unwrapped by the
40/// methods (D-110).
41#[derive(Deserialize)]
42struct PermissionsResponse {
43    permissions: Permissions,
44}
45
46/// A list that Discord wraps in an object (`{"items": [...]}`), unwrapped by the methods.
47#[derive(Deserialize)]
48struct Items<T> {
49    items: Vec<T>,
50}
51
52impl Rest {
53    /// [Get Gateway](https://docs.discord.com/developers/events/gateway#get-gateway): returns
54    /// the gateway URL. Needs no token; bots should use
55    /// [`get_gateway_bot`](Self::get_gateway_bot), which also returns the shard count and the
56    /// session start limit.
57    ///
58    /// discord.js counterpart: none.
59    ///
60    /// # Errors
61    ///
62    /// See [`Rest::request`].
63    pub fn get_gateway(&self) -> impl Future<Output = Result<Gateway, Error>> + Send + '_ {
64        boxed(async move { self.call(Request::new(Route::GetGateway)).await })
65    }
66
67    /// [Get Gateway Bot](https://docs.discord.com/developers/events/gateway#get-gateway-bot):
68    /// returns the gateway URL, the recommended shard count and the session start limit.
69    ///
70    /// discord.js counterpart: `REST#get(Routes.gatewayBot())`.
71    ///
72    /// # Errors
73    ///
74    /// See [`Rest::request`].
75    pub fn get_gateway_bot(&self) -> impl Future<Output = Result<GatewayBot, Error>> + Send + '_ {
76        boxed(async move { self.call(Request::new(Route::GetGatewayBot)).await })
77    }
78
79    /// Sends `request` and discards the response body, whatever it is: for endpoints whose
80    /// docs do not describe their response.
81    pub(crate) async fn request_ignoring_body(&self, request: Request<'_>) -> Result<(), Error> {
82        let _: serde::de::IgnoredAny = self.call(request).await?;
83        Ok(())
84    }
85}