start adding auditlogreason to routes that take it
This commit is contained in:
parent
0cb2bb6883
commit
dd20cb6d9b
|
@ -33,15 +33,23 @@ impl Channel {
|
|||
///
|
||||
/// # Reference
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/channel#delete-channel>
|
||||
pub async fn delete(self, user: &mut ChorusUser) -> ChorusResult<()> {
|
||||
pub async fn delete(
|
||||
self,
|
||||
audit_log_reason: Option<String>,
|
||||
user: &mut ChorusUser,
|
||||
) -> ChorusResult<()> {
|
||||
let mut request = Client::new()
|
||||
.delete(format!(
|
||||
"{}/channels/{}",
|
||||
user.belongs_to.borrow().urls.api,
|
||||
self.id
|
||||
))
|
||||
.header("Authorization", user.token());
|
||||
if let Some(reason) = audit_log_reason {
|
||||
request = request.header("X-Audit-Log-Reason", reason);
|
||||
}
|
||||
let chorus_request = ChorusRequest {
|
||||
request: Client::new()
|
||||
.delete(format!(
|
||||
"{}/channels/{}",
|
||||
user.belongs_to.borrow().urls.api,
|
||||
self.id
|
||||
))
|
||||
.header("Authorization", user.token()),
|
||||
request,
|
||||
limit_type: LimitType::Channel(self.id),
|
||||
};
|
||||
chorus_request.handle_request_as_result(user).await
|
||||
|
@ -64,19 +72,24 @@ impl Channel {
|
|||
pub async fn modify(
|
||||
&self,
|
||||
modify_data: ChannelModifySchema,
|
||||
audit_log_reason: Option<String>,
|
||||
user: &mut ChorusUser,
|
||||
) -> ChorusResult<Channel> {
|
||||
let channel_id = self.id;
|
||||
let mut request = Client::new()
|
||||
.patch(format!(
|
||||
"{}/channels/{}",
|
||||
user.belongs_to.borrow().urls.api,
|
||||
channel_id
|
||||
))
|
||||
.header("Authorization", user.token())
|
||||
.header("Content-Type", "application/json")
|
||||
.body(to_string(&modify_data).unwrap());
|
||||
if let Some(reason) = audit_log_reason {
|
||||
request = request.header("X-Audit-Log-Reason", reason);
|
||||
}
|
||||
let chorus_request = ChorusRequest {
|
||||
request: Client::new()
|
||||
.patch(format!(
|
||||
"{}/channels/{}",
|
||||
user.belongs_to.borrow().urls.api,
|
||||
channel_id
|
||||
))
|
||||
.header("Authorization", user.token())
|
||||
.header("Content-Type", "application/json")
|
||||
.body(to_string(&modify_data).unwrap()),
|
||||
request,
|
||||
limit_type: LimitType::Channel(channel_id),
|
||||
};
|
||||
chorus_request.deserialize_response::<Channel>(user).await
|
||||
|
|
|
@ -162,18 +162,23 @@ impl Message {
|
|||
pub async fn sticky(
|
||||
channel_id: Snowflake,
|
||||
message_id: Snowflake,
|
||||
audit_log_reason: Option<String>,
|
||||
user: &mut ChorusUser,
|
||||
) -> ChorusResult<()> {
|
||||
let mut request = Client::new()
|
||||
.put(format!(
|
||||
"{}/channels/{}/pins/{}",
|
||||
user.belongs_to.borrow().urls.api,
|
||||
channel_id,
|
||||
message_id
|
||||
))
|
||||
.header("Authorization", user.token())
|
||||
.header("Content-Type", "application/json");
|
||||
if let Some(reason) = audit_log_reason {
|
||||
request = request.header("X-Audit-Log-Reason", reason);
|
||||
}
|
||||
let chorus_request = ChorusRequest {
|
||||
request: Client::new()
|
||||
.put(format!(
|
||||
"{}/channels/{}/pins/{}",
|
||||
user.belongs_to.borrow().urls.api,
|
||||
channel_id,
|
||||
message_id
|
||||
))
|
||||
.header("Authorization", user.token())
|
||||
.header("Content-Type", "application/json"),
|
||||
request,
|
||||
limit_type: LimitType::Channel(channel_id),
|
||||
};
|
||||
chorus_request.handle_request_as_result(user).await
|
||||
|
@ -185,18 +190,23 @@ impl Message {
|
|||
pub async fn unsticky(
|
||||
channel_id: Snowflake,
|
||||
message_id: Snowflake,
|
||||
audit_log_reason: Option<String>,
|
||||
user: &mut ChorusUser,
|
||||
) -> ChorusResult<()> {
|
||||
let mut request = Client::new()
|
||||
.delete(format!(
|
||||
"{}/channels/{}/pins/{}",
|
||||
user.belongs_to.borrow().urls.api,
|
||||
channel_id,
|
||||
message_id
|
||||
))
|
||||
.header("Authorization", user.token())
|
||||
.header("Content-Type", "application/json");
|
||||
if let Some(reason) = audit_log_reason {
|
||||
request = request.header("X-Audit-Log-Reason", reason);
|
||||
}
|
||||
let chorus_request = ChorusRequest {
|
||||
request: Client::new()
|
||||
.delete(format!(
|
||||
"{}/channels/{}/pins/{}",
|
||||
user.belongs_to.borrow().urls.api,
|
||||
channel_id,
|
||||
message_id
|
||||
))
|
||||
.header("Authorization", user.token())
|
||||
.header("Content-Type", "application/json"),
|
||||
request,
|
||||
limit_type: LimitType::Channel(channel_id),
|
||||
};
|
||||
chorus_request.handle_request_as_result(user).await
|
||||
|
@ -370,18 +380,23 @@ impl Message {
|
|||
pub async fn delete(
|
||||
channel_id: Snowflake,
|
||||
message_id: Snowflake,
|
||||
audit_log_reason: Option<String>,
|
||||
user: &mut ChorusUser,
|
||||
) -> ChorusResult<()> {
|
||||
let mut request = Client::new()
|
||||
.delete(format!(
|
||||
"{}/channels/{}/messages/{}",
|
||||
user.belongs_to.borrow().urls.api,
|
||||
channel_id,
|
||||
message_id
|
||||
))
|
||||
.header("Authorization", user.token())
|
||||
.header("Content-Type", "application/json");
|
||||
if let Some(reason) = audit_log_reason {
|
||||
request = request.header("X-Audit-Log-Reason", reason);
|
||||
}
|
||||
let chorus_request = ChorusRequest {
|
||||
request: Client::new()
|
||||
.delete(format!(
|
||||
"{}/channels/{}/messages/{}",
|
||||
user.belongs_to.borrow().urls.api,
|
||||
channel_id,
|
||||
message_id
|
||||
))
|
||||
.header("Authorization", user.token())
|
||||
.header("Content-Type", "application/json"),
|
||||
request,
|
||||
limit_type: LimitType::Channel(channel_id),
|
||||
};
|
||||
chorus_request.handle_request_as_result(user).await
|
||||
|
@ -399,6 +414,7 @@ impl Message {
|
|||
pub async fn bulk_delete(
|
||||
channel_id: Snowflake,
|
||||
messages: Vec<Snowflake>,
|
||||
audit_log_reason: Option<String>,
|
||||
user: &mut ChorusUser,
|
||||
) -> ChorusResult<()> {
|
||||
if messages.len() < 2 {
|
||||
|
@ -406,16 +422,20 @@ impl Message {
|
|||
error: "`messages` must contain at least 2 entries.".to_string(),
|
||||
});
|
||||
}
|
||||
let mut request = Client::new()
|
||||
.post(format!(
|
||||
"{}/channels/{}/messages/bulk-delete",
|
||||
user.belongs_to.borrow().urls.api,
|
||||
channel_id,
|
||||
))
|
||||
.header("Authorization", user.token())
|
||||
.header("Content-Type", "application/json")
|
||||
.body(to_string(&messages).unwrap());
|
||||
if let Some(reason) = audit_log_reason {
|
||||
request = request.header("X-Audit-Log-Reason", reason);
|
||||
}
|
||||
let chorus_request = ChorusRequest {
|
||||
request: Client::new()
|
||||
.post(format!(
|
||||
"{}/channels/{}/messages/bulk-delete",
|
||||
user.belongs_to.borrow().urls.api,
|
||||
channel_id,
|
||||
))
|
||||
.header("Authorization", user.token())
|
||||
.header("Content-Type", "application/json")
|
||||
.body(to_string(&messages).unwrap()),
|
||||
request,
|
||||
limit_type: LimitType::Channel(channel_id),
|
||||
};
|
||||
chorus_request.handle_request_as_result(user).await
|
||||
|
|
|
@ -20,9 +20,10 @@ impl types::Channel {
|
|||
///
|
||||
/// # Reference
|
||||
/// See <https://discord-userdoccers.vercel.app/resources/channel#modify-channel-permissions>
|
||||
pub async fn edit_permissions(
|
||||
pub async fn modify_permissions(
|
||||
user: &mut ChorusUser,
|
||||
channel_id: Snowflake,
|
||||
audit_log_reason: Option<String>,
|
||||
overwrite: PermissionOverwrite,
|
||||
) -> ChorusResult<()> {
|
||||
let url = format!(
|
||||
|
@ -39,12 +40,16 @@ impl types::Channel {
|
|||
});
|
||||
}
|
||||
};
|
||||
let mut request = Client::new()
|
||||
.put(url)
|
||||
.header("Authorization", user.token())
|
||||
.header("Content-Type", "application/json")
|
||||
.body(body);
|
||||
if let Some(reason) = audit_log_reason {
|
||||
request = request.header("X-Audit-Log-Reason", reason);
|
||||
}
|
||||
let chorus_request = ChorusRequest {
|
||||
request: Client::new()
|
||||
.put(url)
|
||||
.header("Authorization", user.token())
|
||||
.header("Content-Type", "application/json")
|
||||
.body(body),
|
||||
request,
|
||||
limit_type: LimitType::Channel(channel_id),
|
||||
};
|
||||
chorus_request.handle_request_as_result(user).await
|
||||
|
|
|
@ -198,17 +198,22 @@ impl Channel {
|
|||
user: &mut ChorusUser,
|
||||
guild_id: Snowflake,
|
||||
schema: ChannelCreateSchema,
|
||||
audit_log_reason: Option<String>,
|
||||
) -> ChorusResult<Channel> {
|
||||
let mut request = Client::new()
|
||||
.post(format!(
|
||||
"{}/guilds/{}/channels",
|
||||
user.belongs_to.borrow().urls.api,
|
||||
guild_id
|
||||
))
|
||||
.header("Authorization", user.token())
|
||||
.header("Content-Type", "application/json")
|
||||
.body(to_string(&schema).unwrap());
|
||||
if let Some(reason) = audit_log_reason {
|
||||
request = request.header("X-Audit-Log-Reason", reason);
|
||||
}
|
||||
let chorus_request = ChorusRequest {
|
||||
request: Client::new()
|
||||
.post(format!(
|
||||
"{}/guilds/{}/channels",
|
||||
user.belongs_to.borrow().urls.api,
|
||||
guild_id
|
||||
))
|
||||
.header("Authorization", user.token())
|
||||
.header("Content-Type", "application/json")
|
||||
.body(to_string(&schema).unwrap()),
|
||||
request,
|
||||
limit_type: LimitType::Guild(guild_id),
|
||||
};
|
||||
chorus_request.deserialize_response::<Channel>(user).await
|
||||
|
|
Loading…
Reference in New Issue