twilight_http/request/application/interaction/
delete_followup.rs

1use crate::{
2    client::Client,
3    error::Error,
4    request::{Request, TryIntoRequest},
5    response::{marker::EmptyBody, Response, ResponseFuture},
6    routing::Route,
7};
8use std::future::IntoFuture;
9use twilight_model::id::{
10    marker::{ApplicationMarker, MessageMarker},
11    Id,
12};
13
14/// Delete the original message, by its token.
15///
16/// This endpoint is not bound to the application's global rate limit.
17///
18/// # Examples
19///
20/// ```no_run
21/// # #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> {
22/// use std::env;
23/// use twilight_http::Client;
24/// use twilight_model::id::Id;
25///
26/// let client = Client::new(env::var("DISCORD_TOKEN")?);
27/// let application_id = Id::new(1);
28///
29/// client
30///     .interaction(application_id)
31///     .delete_followup("token here", Id::new(2))
32///     .await?;
33/// # Ok(()) }
34/// ```
35#[must_use = "requests must be configured and executed"]
36pub struct DeleteFollowup<'a> {
37    http: &'a Client,
38    message_id: Id<MessageMarker>,
39    token: &'a str,
40    application_id: Id<ApplicationMarker>,
41}
42
43impl<'a> DeleteFollowup<'a> {
44    pub(crate) const fn new(
45        http: &'a Client,
46        application_id: Id<ApplicationMarker>,
47        token: &'a str,
48        message_id: Id<MessageMarker>,
49    ) -> Self {
50        Self {
51            http,
52            message_id,
53            token,
54            application_id,
55        }
56    }
57}
58
59impl IntoFuture for DeleteFollowup<'_> {
60    type Output = Result<Response<EmptyBody>, Error>;
61
62    type IntoFuture = ResponseFuture<EmptyBody>;
63
64    fn into_future(self) -> Self::IntoFuture {
65        let http = self.http;
66
67        match self.try_into_request() {
68            Ok(request) => http.request(request),
69            Err(source) => ResponseFuture::error(source),
70        }
71    }
72}
73
74impl TryIntoRequest for DeleteFollowup<'_> {
75    fn try_into_request(self) -> Result<Request, Error> {
76        Request::builder(&Route::DeleteWebhookMessage {
77            message_id: self.message_id.get(),
78            thread_id: None,
79            token: self.token,
80            webhook_id: self.application_id.get(),
81        })
82        .use_authorization_token(false)
83        .build()
84    }
85}
86
87#[cfg(test)]
88mod tests {
89    use super::DeleteFollowup;
90    use crate::{
91        client::Client,
92        request::{Request, TryIntoRequest},
93        routing::Route,
94    };
95    use std::error::Error;
96    use twilight_model::id::Id;
97
98    #[test]
99    fn request() -> Result<(), Box<dyn Error>> {
100        let client = Client::new("token".to_owned());
101
102        let builder = DeleteFollowup::new(&client, Id::new(1), "token", Id::new(2));
103        let actual = builder.try_into_request()?;
104
105        let expected = Request::from_route(&Route::DeleteWebhookMessage {
106            message_id: 2,
107            thread_id: None,
108            token: "token",
109            webhook_id: 1,
110        });
111
112        assert_eq!(expected.path, actual.path);
113        assert!(!actual.use_authorization_token());
114
115        Ok(())
116    }
117}