djs_rest/endpoints/application.rs
1//! [Application endpoints](https://docs.discord.com/developers/resources/application): the
2//! bot's own application and its running Activity instances.
3
4use djs_model::{
5 application::{ActivityInstance, Application},
6 id::ApplicationId,
7 rest::EditCurrentApplication,
8};
9
10use crate::client::boxed;
11use crate::{Error, Request, Rest, Route};
12
13impl Rest {
14 /// [Get Current Application](https://docs.discord.com/developers/resources/application#get-current-application):
15 /// returns the application of the bot, with its owner or team and approximate install
16 /// counts.
17 ///
18 /// discord.js counterpart: `ClientApplication#fetch`.
19 ///
20 /// # Examples
21 ///
22 /// ```no_run
23 /// # async fn example(rest: djs_rest::Rest) -> Result<(), djs_rest::Error> {
24 /// let application = rest.get_current_application().await?;
25 /// println!(
26 /// "{} is in about {:?} guilds",
27 /// application.name, application.approximate_guild_count
28 /// );
29 /// # Ok(())
30 /// # }
31 /// ```
32 ///
33 /// # Errors
34 ///
35 /// See [`Rest::request`].
36 pub fn get_current_application(
37 &self,
38 ) -> impl Future<Output = Result<Application, Error>> + Send + '_ {
39 boxed(async move { self.call(Request::new(Route::GetCurrentApplication)).await })
40 }
41
42 /// [Edit Current Application](https://docs.discord.com/developers/resources/application#edit-current-application):
43 /// changes the settings of the bot's application and returns it.
44 ///
45 /// discord.js counterpart: `ClientApplication#edit`.
46 ///
47 /// # Errors
48 ///
49 /// See [`Rest::request`]; `50035` for a field Discord does not accept (for example an
50 /// interactions endpoint URL that fails validation).
51 pub fn edit_current_application<'a>(
52 &'a self,
53 body: &'a EditCurrentApplication,
54 ) -> impl Future<Output = Result<Application, Error>> + Send + 'a {
55 boxed(async move {
56 self.call(Request::new(Route::EditCurrentApplication).json(body)?)
57 .await
58 })
59 }
60
61 /// [Get Application Activity Instance](https://docs.discord.com/developers/resources/application#get-application-activity-instance):
62 /// returns a running instance of the application's Activity, with the users connected to
63 /// it — for example to check that a user who claims to be in it really is.
64 ///
65 /// discord.js counterpart: `ClientApplication#fetchActivityInstance`.
66 ///
67 /// # Errors
68 ///
69 /// See [`Rest::request`]; `404` when the instance does not exist (anymore).
70 pub fn get_application_activity_instance<'a>(
71 &'a self,
72 application_id: ApplicationId,
73 instance_id: &'a str,
74 ) -> impl Future<Output = Result<ActivityInstance, Error>> + Send + 'a {
75 boxed(async move {
76 self.call(Request::new(Route::GetApplicationActivityInstance {
77 application_id,
78 instance_id,
79 }))
80 .await
81 })
82 }
83}