Skip to main content

twilight_http/request/guild/auto_moderation/
get_auto_moderation_rule.rs

1#[cfg(not(target_os = "wasi"))]
2use crate::response::{Response, ResponseFuture};
3use crate::{
4    client::Client,
5    error::Error,
6    request::{Request, TryIntoRequest},
7    routing::Route,
8};
9use std::future::IntoFuture;
10use twilight_model::{
11    guild::auto_moderation::AutoModerationRule,
12    id::{
13        Id,
14        marker::{AutoModerationRuleMarker, GuildMarker},
15    },
16};
17
18/// Get an auto moderation rule in a guild.
19///
20/// Requires the [`MANAGE_GUILD`] permission.
21///
22/// [`MANAGE_GUILD`]: twilight_model::guild::Permissions::MANAGE_GUILD
23#[must_use = "requests must be configured and executed"]
24pub struct GetAutoModerationRule<'a> {
25    auto_moderation_rule_id: Id<AutoModerationRuleMarker>,
26    guild_id: Id<GuildMarker>,
27    http: &'a Client,
28}
29
30impl<'a> GetAutoModerationRule<'a> {
31    pub(crate) const fn new(
32        http: &'a Client,
33        guild_id: Id<GuildMarker>,
34        auto_moderation_rule_id: Id<AutoModerationRuleMarker>,
35    ) -> Self {
36        Self {
37            auto_moderation_rule_id,
38            guild_id,
39            http,
40        }
41    }
42}
43
44#[cfg(not(target_os = "wasi"))]
45impl IntoFuture for GetAutoModerationRule<'_> {
46    type Output = Result<Response<AutoModerationRule>, Error>;
47
48    type IntoFuture = ResponseFuture<AutoModerationRule>;
49
50    fn into_future(self) -> Self::IntoFuture {
51        let http = self.http;
52
53        match self.try_into_request() {
54            Ok(request) => http.request(request),
55            Err(source) => ResponseFuture::error(source),
56        }
57    }
58}
59
60impl TryIntoRequest for GetAutoModerationRule<'_> {
61    fn try_into_request(self) -> Result<Request, Error> {
62        Request::builder(&Route::GetAutoModerationRule {
63            auto_moderation_rule_id: self.auto_moderation_rule_id.get(),
64            guild_id: self.guild_id.get(),
65        })
66        .build()
67    }
68}