twilight_http/request/guild/auto_moderation/
delete_auto_moderation_rule.rs1use crate::{
2 client::Client,
3 error::Error,
4 request::{self, AuditLogReason, Request, TryIntoRequest},
5 response::{marker::EmptyBody, Response, ResponseFuture},
6 routing::Route,
7};
8use std::future::IntoFuture;
9use twilight_model::id::{
10 marker::{AutoModerationRuleMarker, GuildMarker},
11 Id,
12};
13use twilight_validate::request::{audit_reason as validate_audit_reason, ValidationError};
14
15#[must_use = "requests must be configured and executed"]
21pub struct DeleteAutoModerationRule<'a> {
22 auto_moderation_rule_id: Id<AutoModerationRuleMarker>,
23 guild_id: Id<GuildMarker>,
24 http: &'a Client,
25 reason: Result<Option<&'a str>, ValidationError>,
26}
27
28impl<'a> DeleteAutoModerationRule<'a> {
29 pub(crate) const fn new(
30 http: &'a Client,
31 guild_id: Id<GuildMarker>,
32 auto_moderation_rule_id: Id<AutoModerationRuleMarker>,
33 ) -> Self {
34 Self {
35 auto_moderation_rule_id,
36 guild_id,
37 http,
38 reason: Ok(None),
39 }
40 }
41}
42
43impl<'a> AuditLogReason<'a> for DeleteAutoModerationRule<'a> {
44 fn reason(mut self, reason: &'a str) -> Self {
45 self.reason = validate_audit_reason(reason).and(Ok(Some(reason)));
46
47 self
48 }
49}
50
51impl IntoFuture for DeleteAutoModerationRule<'_> {
52 type Output = Result<Response<EmptyBody>, Error>;
53
54 type IntoFuture = ResponseFuture<EmptyBody>;
55
56 fn into_future(self) -> Self::IntoFuture {
57 let http = self.http;
58
59 match self.try_into_request() {
60 Ok(request) => http.request(request),
61 Err(source) => ResponseFuture::error(source),
62 }
63 }
64}
65
66impl TryIntoRequest for DeleteAutoModerationRule<'_> {
67 fn try_into_request(self) -> Result<Request, Error> {
68 let mut request = Request::builder(&Route::DeleteAutoModerationRule {
69 auto_moderation_rule_id: self.auto_moderation_rule_id.get(),
70 guild_id: self.guild_id.get(),
71 });
72
73 if let Some(reason) = self.reason.map_err(Error::validation)? {
74 request = request.headers(request::audit_header(reason)?);
75 }
76
77 request.build()
78 }
79}