Merge branch 'main' into guild-routes
This commit is contained in:
commit
9cb8b29487
|
@ -16,13 +16,20 @@ impl Channel {
|
||||||
/// # Reference
|
/// # Reference
|
||||||
/// See <https://discord-userdoccers.vercel.app/resources/channel#get-channel>
|
/// See <https://discord-userdoccers.vercel.app/resources/channel#get-channel>
|
||||||
pub async fn get(user: &mut ChorusUser, channel_id: Snowflake) -> ChorusResult<Channel> {
|
pub async fn get(user: &mut ChorusUser, channel_id: Snowflake) -> ChorusResult<Channel> {
|
||||||
let url = user.belongs_to.borrow().urls.api.clone();
|
let chorus_request = ChorusRequest::new(
|
||||||
let chorus_request = ChorusRequest {
|
http::Method::GET,
|
||||||
request: Client::new()
|
&format!(
|
||||||
.get(format!("{}/channels/{}", url, channel_id))
|
"{}/channels/{}",
|
||||||
.header("Authorization", user.token()),
|
user.belongs_to.borrow().urls.api.clone(),
|
||||||
limit_type: LimitType::Channel(channel_id),
|
channel_id
|
||||||
};
|
),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
Some(user),
|
||||||
|
LimitType::Channel(channel_id),
|
||||||
|
);
|
||||||
|
|
||||||
chorus_request.deserialize_response::<Channel>(user).await
|
chorus_request.deserialize_response::<Channel>(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,18 +40,24 @@ impl Channel {
|
||||||
///
|
///
|
||||||
/// # Reference
|
/// # Reference
|
||||||
/// See <https://discord-userdoccers.vercel.app/resources/channel#delete-channel>
|
/// See <https://discord-userdoccers.vercel.app/resources/channel#delete-channel>
|
||||||
pub async fn delete(self, user: &mut ChorusUser) -> ChorusResult<()> {
|
pub async fn delete(
|
||||||
let chorus_request = ChorusRequest {
|
self,
|
||||||
request: Client::new()
|
audit_log_reason: Option<String>,
|
||||||
.delete(format!(
|
user: &mut ChorusUser,
|
||||||
"{}/channels/{}",
|
) -> ChorusResult<()> {
|
||||||
user.belongs_to.borrow().urls.api,
|
let url = format!("{}/channels/{}", user.belongs_to.borrow().urls.api, self.id,);
|
||||||
self.id
|
|
||||||
))
|
let request = ChorusRequest::new(
|
||||||
.header("Authorization", user.token()),
|
http::Method::DELETE,
|
||||||
limit_type: LimitType::Channel(self.id),
|
&url,
|
||||||
};
|
None,
|
||||||
chorus_request.handle_request_as_result(user).await
|
audit_log_reason.as_deref(),
|
||||||
|
None,
|
||||||
|
Some(user),
|
||||||
|
LimitType::Channel(self.id),
|
||||||
|
);
|
||||||
|
|
||||||
|
request.handle_request_as_result(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modifies a channel with the provided data.
|
/// Modifies a channel with the provided data.
|
||||||
|
@ -64,22 +77,27 @@ impl Channel {
|
||||||
pub async fn modify(
|
pub async fn modify(
|
||||||
&self,
|
&self,
|
||||||
modify_data: ChannelModifySchema,
|
modify_data: ChannelModifySchema,
|
||||||
|
audit_log_reason: Option<String>,
|
||||||
user: &mut ChorusUser,
|
user: &mut ChorusUser,
|
||||||
) -> ChorusResult<Channel> {
|
) -> ChorusResult<Channel> {
|
||||||
let channel_id = self.id;
|
let channel_id = self.id;
|
||||||
let chorus_request = ChorusRequest {
|
let url = format!(
|
||||||
request: Client::new()
|
|
||||||
.patch(format!(
|
|
||||||
"{}/channels/{}",
|
"{}/channels/{}",
|
||||||
user.belongs_to.borrow().urls.api,
|
user.belongs_to.borrow().urls.api,
|
||||||
channel_id
|
channel_id
|
||||||
))
|
);
|
||||||
.header("Authorization", user.token())
|
|
||||||
.header("Content-Type", "application/json")
|
let request = ChorusRequest::new(
|
||||||
.body(to_string(&modify_data).unwrap()),
|
http::Method::PATCH,
|
||||||
limit_type: LimitType::Channel(channel_id),
|
&url,
|
||||||
};
|
Some(to_string(&modify_data).unwrap()),
|
||||||
chorus_request.deserialize_response::<Channel>(user).await
|
audit_log_reason.as_deref(),
|
||||||
|
None,
|
||||||
|
Some(user),
|
||||||
|
LimitType::Channel(channel_id),
|
||||||
|
);
|
||||||
|
|
||||||
|
request.deserialize_response::<Channel>(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetches recent messages from a channel.
|
/// Fetches recent messages from a channel.
|
||||||
|
@ -96,17 +114,22 @@ impl Channel {
|
||||||
channel_id: Snowflake,
|
channel_id: Snowflake,
|
||||||
user: &mut ChorusUser,
|
user: &mut ChorusUser,
|
||||||
) -> Result<Vec<Message>, ChorusError> {
|
) -> Result<Vec<Message>, ChorusError> {
|
||||||
let chorus_request = ChorusRequest {
|
let url = format!(
|
||||||
request: Client::new()
|
|
||||||
.get(format!(
|
|
||||||
"{}/channels/{}/messages",
|
"{}/channels/{}/messages",
|
||||||
user.belongs_to.borrow().urls.api,
|
user.belongs_to.borrow().urls.api,
|
||||||
channel_id
|
channel_id
|
||||||
))
|
);
|
||||||
.header("Authorization", user.token())
|
|
||||||
.query(&range),
|
let mut chorus_request = ChorusRequest::new(
|
||||||
limit_type: Default::default(),
|
http::Method::GET,
|
||||||
};
|
&url,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
Some(user),
|
||||||
|
Default::default(),
|
||||||
|
);
|
||||||
|
chorus_request.request = chorus_request.request.query(&range);
|
||||||
|
|
||||||
chorus_request
|
chorus_request
|
||||||
.deserialize_response::<Vec<Message>>(user)
|
.deserialize_response::<Vec<Message>>(user)
|
||||||
|
@ -152,20 +175,24 @@ impl Channel {
|
||||||
recipient_id: Snowflake,
|
recipient_id: Snowflake,
|
||||||
user: &mut ChorusUser,
|
user: &mut ChorusUser,
|
||||||
) -> ChorusResult<()> {
|
) -> ChorusResult<()> {
|
||||||
let request = Client::new()
|
let url = format!(
|
||||||
.delete(format!(
|
|
||||||
"{}/channels/{}/recipients/{}",
|
"{}/channels/{}/recipients/{}",
|
||||||
user.belongs_to.borrow().urls.api,
|
user.belongs_to.borrow().urls.api,
|
||||||
self.id,
|
self.id,
|
||||||
recipient_id
|
recipient_id
|
||||||
))
|
);
|
||||||
.header("Authorization", user.token());
|
|
||||||
ChorusRequest {
|
let request = ChorusRequest::new(
|
||||||
request,
|
http::Method::DELETE,
|
||||||
limit_type: LimitType::Channel(self.id),
|
&url,
|
||||||
}
|
None,
|
||||||
.handle_request_as_result(user)
|
None,
|
||||||
.await
|
None,
|
||||||
|
Some(user),
|
||||||
|
LimitType::Channel(self.id),
|
||||||
|
);
|
||||||
|
|
||||||
|
request.handle_request_as_result(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modifies the positions of a set of channel objects for the guild. Requires the `MANAGE_CHANNELS` permission.
|
/// Modifies the positions of a set of channel objects for the guild. Requires the `MANAGE_CHANNELS` permission.
|
||||||
|
@ -178,19 +205,22 @@ impl Channel {
|
||||||
guild_id: Snowflake,
|
guild_id: Snowflake,
|
||||||
user: &mut ChorusUser,
|
user: &mut ChorusUser,
|
||||||
) -> ChorusResult<()> {
|
) -> ChorusResult<()> {
|
||||||
let request = Client::new()
|
let url = format!(
|
||||||
.patch(format!(
|
|
||||||
"{}/guilds/{}/channels",
|
"{}/guilds/{}/channels",
|
||||||
user.belongs_to.borrow().urls.api,
|
user.belongs_to.borrow().urls.api,
|
||||||
guild_id
|
guild_id
|
||||||
))
|
);
|
||||||
.header("Authorization", user.token())
|
|
||||||
.body(to_string(&schema).unwrap());
|
let request = ChorusRequest::new(
|
||||||
ChorusRequest {
|
http::Method::PATCH,
|
||||||
request,
|
&url,
|
||||||
limit_type: LimitType::Guild(guild_id),
|
Some(to_string(&schema).unwrap()),
|
||||||
}
|
None,
|
||||||
.handle_request_as_result(user)
|
None,
|
||||||
.await
|
Some(user),
|
||||||
|
LimitType::Guild(guild_id),
|
||||||
|
);
|
||||||
|
|
||||||
|
request.handle_request_as_result(user).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,17 +138,20 @@ impl Message {
|
||||||
channel_id: Snowflake,
|
channel_id: Snowflake,
|
||||||
user: &mut ChorusUser,
|
user: &mut ChorusUser,
|
||||||
) -> ChorusResult<Vec<Message>> {
|
) -> ChorusResult<Vec<Message>> {
|
||||||
let chorus_request = ChorusRequest {
|
let chorus_request = ChorusRequest::new(
|
||||||
request: Client::new()
|
http::Method::GET,
|
||||||
.get(format!(
|
format!(
|
||||||
"{}/channels/{}/pins",
|
"{}/channels/{}/pins",
|
||||||
user.belongs_to.borrow().urls.api,
|
user.belongs_to.borrow().urls.api,
|
||||||
channel_id
|
channel_id
|
||||||
))
|
)
|
||||||
.header("Authorization", user.token())
|
.as_str(),
|
||||||
.header("Content-Type", "application/json"),
|
None,
|
||||||
limit_type: LimitType::Channel(channel_id),
|
None,
|
||||||
};
|
None,
|
||||||
|
Some(user),
|
||||||
|
LimitType::Channel(channel_id),
|
||||||
|
);
|
||||||
chorus_request
|
chorus_request
|
||||||
.deserialize_response::<Vec<Message>>(user)
|
.deserialize_response::<Vec<Message>>(user)
|
||||||
.await
|
.await
|
||||||
|
@ -162,21 +165,25 @@ impl Message {
|
||||||
pub async fn sticky(
|
pub async fn sticky(
|
||||||
channel_id: Snowflake,
|
channel_id: Snowflake,
|
||||||
message_id: Snowflake,
|
message_id: Snowflake,
|
||||||
|
audit_log_reason: Option<&str>,
|
||||||
user: &mut ChorusUser,
|
user: &mut ChorusUser,
|
||||||
) -> ChorusResult<()> {
|
) -> ChorusResult<()> {
|
||||||
let chorus_request = ChorusRequest {
|
let request = ChorusRequest::new(
|
||||||
request: Client::new()
|
http::Method::PUT,
|
||||||
.put(format!(
|
format!(
|
||||||
"{}/channels/{}/pins/{}",
|
"{}/channels/{}/pins/{}",
|
||||||
user.belongs_to.borrow().urls.api,
|
user.belongs_to.borrow().urls.api,
|
||||||
channel_id,
|
channel_id,
|
||||||
message_id
|
message_id
|
||||||
))
|
)
|
||||||
.header("Authorization", user.token())
|
.as_str(),
|
||||||
.header("Content-Type", "application/json"),
|
None,
|
||||||
limit_type: LimitType::Channel(channel_id),
|
audit_log_reason,
|
||||||
};
|
None,
|
||||||
chorus_request.handle_request_as_result(user).await
|
Some(user),
|
||||||
|
LimitType::Channel(channel_id),
|
||||||
|
);
|
||||||
|
request.handle_request_as_result(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unpins a message in a channel. Requires the `MANAGE_MESSAGES` permission. Returns a 204 empty response on success.
|
/// Unpins a message in a channel. Requires the `MANAGE_MESSAGES` permission. Returns a 204 empty response on success.
|
||||||
|
@ -185,21 +192,25 @@ impl Message {
|
||||||
pub async fn unsticky(
|
pub async fn unsticky(
|
||||||
channel_id: Snowflake,
|
channel_id: Snowflake,
|
||||||
message_id: Snowflake,
|
message_id: Snowflake,
|
||||||
|
audit_log_reason: Option<&str>,
|
||||||
user: &mut ChorusUser,
|
user: &mut ChorusUser,
|
||||||
) -> ChorusResult<()> {
|
) -> ChorusResult<()> {
|
||||||
let chorus_request = ChorusRequest {
|
let request = ChorusRequest::new(
|
||||||
request: Client::new()
|
http::Method::DELETE,
|
||||||
.delete(format!(
|
format!(
|
||||||
"{}/channels/{}/pins/{}",
|
"{}/channels/{}/pins/{}",
|
||||||
user.belongs_to.borrow().urls.api,
|
user.belongs_to.borrow().urls.api,
|
||||||
channel_id,
|
channel_id,
|
||||||
message_id
|
message_id
|
||||||
))
|
)
|
||||||
.header("Authorization", user.token())
|
.as_str(),
|
||||||
.header("Content-Type", "application/json"),
|
None,
|
||||||
limit_type: LimitType::Channel(channel_id),
|
audit_log_reason,
|
||||||
};
|
None,
|
||||||
chorus_request.handle_request_as_result(user).await
|
Some(user),
|
||||||
|
LimitType::Channel(channel_id),
|
||||||
|
);
|
||||||
|
request.handle_request_as_result(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a specific message object in the channel.
|
/// Returns a specific message object in the channel.
|
||||||
|
@ -234,19 +245,21 @@ impl Message {
|
||||||
schema: CreateGreetMessage,
|
schema: CreateGreetMessage,
|
||||||
user: &mut ChorusUser,
|
user: &mut ChorusUser,
|
||||||
) -> ChorusResult<Message> {
|
) -> ChorusResult<Message> {
|
||||||
let chorus_request = ChorusRequest {
|
let request = ChorusRequest::new(
|
||||||
request: Client::new()
|
http::Method::POST,
|
||||||
.post(format!(
|
format!(
|
||||||
"{}/channels/{}/messages/greet",
|
"{}/channels/{}/messages/greet",
|
||||||
user.belongs_to.borrow().urls.api,
|
user.belongs_to.borrow().urls.api,
|
||||||
channel_id,
|
channel_id,
|
||||||
))
|
)
|
||||||
.header("Authorization", user.token())
|
.as_str(),
|
||||||
.header("Content-Type", "application/json")
|
Some(to_string(&schema).unwrap()),
|
||||||
.body(to_string(&schema).unwrap()),
|
None,
|
||||||
limit_type: LimitType::Channel(channel_id),
|
None,
|
||||||
};
|
Some(user),
|
||||||
chorus_request.deserialize_response::<Message>(user).await
|
LimitType::Channel(channel_id),
|
||||||
|
);
|
||||||
|
request.deserialize_response::<Message>(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the channel's latest acknowledged message (marks a message as read) for the current user.
|
/// Sets the channel's latest acknowledged message (marks a message as read) for the current user.
|
||||||
|
@ -265,22 +278,22 @@ impl Message {
|
||||||
schema: MessageAck,
|
schema: MessageAck,
|
||||||
user: &mut ChorusUser,
|
user: &mut ChorusUser,
|
||||||
) -> ChorusResult<Option<String>> {
|
) -> ChorusResult<Option<String>> {
|
||||||
let chorus_request = ChorusRequest {
|
let request = ChorusRequest::new(
|
||||||
request: Client::new()
|
http::Method::POST,
|
||||||
.post(format!(
|
format!(
|
||||||
"{}/channels/{}/messages/{}/ack",
|
"{}/channels/{}/messages/{}/ack",
|
||||||
user.belongs_to.borrow().urls.api,
|
user.belongs_to.borrow().urls.api,
|
||||||
channel_id,
|
channel_id,
|
||||||
message_id
|
message_id
|
||||||
))
|
)
|
||||||
.header("Authorization", user.token())
|
.as_str(),
|
||||||
.header("Content-Type", "application/json")
|
Some(to_string(&schema).unwrap()),
|
||||||
.body(to_string(&schema).unwrap()),
|
None,
|
||||||
limit_type: LimitType::Channel(channel_id),
|
None,
|
||||||
};
|
Some(user),
|
||||||
chorus_request
|
LimitType::Channel(channel_id),
|
||||||
.deserialize_response::<Option<String>>(user)
|
);
|
||||||
.await
|
request.deserialize_response::<Option<String>>(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Crossposts a message in a News Channel to following channels.
|
/// Crossposts a message in a News Channel to following channels.
|
||||||
|
@ -294,19 +307,22 @@ impl Message {
|
||||||
message_id: Snowflake,
|
message_id: Snowflake,
|
||||||
user: &mut ChorusUser,
|
user: &mut ChorusUser,
|
||||||
) -> ChorusResult<Message> {
|
) -> ChorusResult<Message> {
|
||||||
let chorus_request = ChorusRequest {
|
let request = ChorusRequest::new(
|
||||||
request: Client::new()
|
http::Method::POST,
|
||||||
.post(format!(
|
format!(
|
||||||
"{}/channels/{}/messages/{}/crosspost",
|
"{}/channels/{}/messages/{}/crosspost",
|
||||||
user.belongs_to.borrow().urls.api,
|
user.belongs_to.borrow().urls.api,
|
||||||
channel_id,
|
channel_id,
|
||||||
message_id
|
message_id
|
||||||
))
|
)
|
||||||
.header("Authorization", user.token())
|
.as_str(),
|
||||||
.header("Content-Type", "application/json"),
|
None,
|
||||||
limit_type: LimitType::Channel(channel_id),
|
None,
|
||||||
};
|
None,
|
||||||
chorus_request.deserialize_response::<Message>(user).await
|
Some(user),
|
||||||
|
LimitType::Channel(channel_id),
|
||||||
|
);
|
||||||
|
request.deserialize_response::<Message>(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Hides a message from the feed of the guild the channel belongs to. Returns a 204 empty response on success.
|
/// Hides a message from the feed of the guild the channel belongs to. Returns a 204 empty response on success.
|
||||||
|
@ -318,18 +334,21 @@ impl Message {
|
||||||
message_id: Snowflake,
|
message_id: Snowflake,
|
||||||
user: &mut ChorusUser,
|
user: &mut ChorusUser,
|
||||||
) -> ChorusResult<()> {
|
) -> ChorusResult<()> {
|
||||||
let chorus_request = ChorusRequest {
|
let url = format!(
|
||||||
request: Client::new()
|
|
||||||
.delete(format!(
|
|
||||||
"{}/channels/{}/messages/{}/hide-guild-feed",
|
"{}/channels/{}/messages/{}/hide-guild-feed",
|
||||||
user.belongs_to.borrow().urls.api,
|
user.belongs_to.borrow().urls.api,
|
||||||
channel_id,
|
channel_id,
|
||||||
message_id
|
message_id
|
||||||
))
|
);
|
||||||
.header("Authorization", user.token())
|
let chorus_request = ChorusRequest::new(
|
||||||
.header("Content-Type", "application/json"),
|
http::Method::DELETE,
|
||||||
limit_type: LimitType::Channel(channel_id),
|
&url,
|
||||||
};
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
Some(user),
|
||||||
|
LimitType::Channel(channel_id),
|
||||||
|
);
|
||||||
chorus_request.handle_request_as_result(user).await
|
chorus_request.handle_request_as_result(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,19 +368,21 @@ impl Message {
|
||||||
schema: MessageModifySchema,
|
schema: MessageModifySchema,
|
||||||
user: &mut ChorusUser,
|
user: &mut ChorusUser,
|
||||||
) -> ChorusResult<Message> {
|
) -> ChorusResult<Message> {
|
||||||
let chorus_request = ChorusRequest {
|
let url = format!(
|
||||||
request: Client::new()
|
|
||||||
.patch(format!(
|
|
||||||
"{}/channels/{}/messages/{}",
|
"{}/channels/{}/messages/{}",
|
||||||
user.belongs_to.borrow().urls.api,
|
user.belongs_to.borrow().urls.api,
|
||||||
channel_id,
|
channel_id,
|
||||||
message_id
|
message_id
|
||||||
))
|
);
|
||||||
.header("Authorization", user.token())
|
let chorus_request = ChorusRequest::new(
|
||||||
.header("Content-Type", "application/json")
|
http::Method::PATCH,
|
||||||
.body(to_string(&schema).unwrap()),
|
&url,
|
||||||
limit_type: LimitType::Channel(channel_id),
|
Some(to_string(&schema).unwrap()),
|
||||||
};
|
None,
|
||||||
|
None,
|
||||||
|
Some(user),
|
||||||
|
LimitType::Channel(channel_id),
|
||||||
|
);
|
||||||
chorus_request.deserialize_response::<Message>(user).await
|
chorus_request.deserialize_response::<Message>(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,20 +391,26 @@ impl Message {
|
||||||
pub async fn delete(
|
pub async fn delete(
|
||||||
channel_id: Snowflake,
|
channel_id: Snowflake,
|
||||||
message_id: Snowflake,
|
message_id: Snowflake,
|
||||||
|
audit_log_reason: Option<String>,
|
||||||
user: &mut ChorusUser,
|
user: &mut ChorusUser,
|
||||||
) -> ChorusResult<()> {
|
) -> ChorusResult<()> {
|
||||||
let chorus_request = ChorusRequest {
|
let url = format!(
|
||||||
request: Client::new()
|
|
||||||
.delete(format!(
|
|
||||||
"{}/channels/{}/messages/{}",
|
"{}/channels/{}/messages/{}",
|
||||||
user.belongs_to.borrow().urls.api,
|
user.belongs_to.borrow().urls.api,
|
||||||
channel_id,
|
channel_id,
|
||||||
message_id
|
message_id
|
||||||
))
|
);
|
||||||
.header("Authorization", user.token())
|
|
||||||
.header("Content-Type", "application/json"),
|
let chorus_request = ChorusRequest::new(
|
||||||
limit_type: LimitType::Channel(channel_id),
|
http::Method::DELETE,
|
||||||
};
|
&url,
|
||||||
|
None,
|
||||||
|
audit_log_reason.as_deref(),
|
||||||
|
None,
|
||||||
|
Some(user),
|
||||||
|
LimitType::Channel(channel_id),
|
||||||
|
);
|
||||||
|
|
||||||
chorus_request.handle_request_as_result(user).await
|
chorus_request.handle_request_as_result(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,6 +426,7 @@ impl Message {
|
||||||
pub async fn bulk_delete(
|
pub async fn bulk_delete(
|
||||||
channel_id: Snowflake,
|
channel_id: Snowflake,
|
||||||
messages: Vec<Snowflake>,
|
messages: Vec<Snowflake>,
|
||||||
|
audit_log_reason: Option<String>,
|
||||||
user: &mut ChorusUser,
|
user: &mut ChorusUser,
|
||||||
) -> ChorusResult<()> {
|
) -> ChorusResult<()> {
|
||||||
if messages.len() < 2 {
|
if messages.len() < 2 {
|
||||||
|
@ -406,19 +434,21 @@ impl Message {
|
||||||
error: "`messages` must contain at least 2 entries.".to_string(),
|
error: "`messages` must contain at least 2 entries.".to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
let chorus_request = ChorusRequest {
|
let request = ChorusRequest::new(
|
||||||
request: Client::new()
|
http::Method::POST,
|
||||||
.post(format!(
|
format!(
|
||||||
"{}/channels/{}/messages/bulk-delete",
|
"{}/channels/{}/messages/bulk-delete",
|
||||||
user.belongs_to.borrow().urls.api,
|
user.belongs_to.borrow().urls.api,
|
||||||
channel_id,
|
channel_id,
|
||||||
))
|
)
|
||||||
.header("Authorization", user.token())
|
.as_str(),
|
||||||
.header("Content-Type", "application/json")
|
Some(to_string(&messages).unwrap()),
|
||||||
.body(to_string(&messages).unwrap()),
|
audit_log_reason.as_deref(),
|
||||||
limit_type: LimitType::Channel(channel_id),
|
None,
|
||||||
};
|
Some(user),
|
||||||
chorus_request.handle_request_as_result(user).await
|
LimitType::Channel(channel_id),
|
||||||
|
);
|
||||||
|
request.handle_request_as_result(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Acknowledges the currently pinned messages in a channel. Returns a 204 empty response on success.
|
/// Acknowledges the currently pinned messages in a channel. Returns a 204 empty response on success.
|
||||||
|
@ -429,17 +459,21 @@ impl Message {
|
||||||
channel_id: Snowflake,
|
channel_id: Snowflake,
|
||||||
user: &mut ChorusUser,
|
user: &mut ChorusUser,
|
||||||
) -> ChorusResult<()> {
|
) -> ChorusResult<()> {
|
||||||
let chorus_request = ChorusRequest {
|
let chorus_request = ChorusRequest::new(
|
||||||
request: Client::new()
|
http::Method::POST,
|
||||||
.post(format!(
|
format!(
|
||||||
"{}/channels/{}/pins/ack",
|
"{}/channels/{}/pins/ack",
|
||||||
user.belongs_to.borrow().urls.api,
|
user.belongs_to.borrow().urls.api,
|
||||||
channel_id,
|
channel_id,
|
||||||
))
|
)
|
||||||
.header("Authorization", user.token())
|
.as_str(),
|
||||||
.header("Content-Type", "application/json"),
|
None,
|
||||||
limit_type: LimitType::Channel(channel_id),
|
None,
|
||||||
};
|
None,
|
||||||
|
Some(user),
|
||||||
|
LimitType::Channel(channel_id),
|
||||||
|
);
|
||||||
|
|
||||||
chorus_request.handle_request_as_result(user).await
|
chorus_request.handle_request_as_result(user).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,10 @@ impl types::Channel {
|
||||||
///
|
///
|
||||||
/// # Reference
|
/// # Reference
|
||||||
/// See <https://discord-userdoccers.vercel.app/resources/channel#modify-channel-permissions>
|
/// See <https://discord-userdoccers.vercel.app/resources/channel#modify-channel-permissions>
|
||||||
pub async fn edit_permissions(
|
pub async fn modify_permissions(
|
||||||
user: &mut ChorusUser,
|
user: &mut ChorusUser,
|
||||||
channel_id: Snowflake,
|
channel_id: Snowflake,
|
||||||
|
audit_log_reason: Option<String>,
|
||||||
overwrite: PermissionOverwrite,
|
overwrite: PermissionOverwrite,
|
||||||
) -> ChorusResult<()> {
|
) -> ChorusResult<()> {
|
||||||
let url = format!(
|
let url = format!(
|
||||||
|
@ -39,12 +40,16 @@ impl types::Channel {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let chorus_request = ChorusRequest {
|
let mut request = Client::new()
|
||||||
request: Client::new()
|
|
||||||
.put(url)
|
.put(url)
|
||||||
.header("Authorization", user.token())
|
.header("Authorization", user.token())
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
.body(body),
|
.body(body);
|
||||||
|
if let Some(reason) = audit_log_reason {
|
||||||
|
request = request.header("X-Audit-Log-Reason", reason);
|
||||||
|
}
|
||||||
|
let chorus_request = ChorusRequest {
|
||||||
|
request,
|
||||||
limit_type: LimitType::Channel(channel_id),
|
limit_type: LimitType::Channel(channel_id),
|
||||||
};
|
};
|
||||||
chorus_request.handle_request_as_result(user).await
|
chorus_request.handle_request_as_result(user).await
|
||||||
|
@ -69,12 +74,17 @@ impl types::Channel {
|
||||||
channel_id,
|
channel_id,
|
||||||
overwrite_id
|
overwrite_id
|
||||||
);
|
);
|
||||||
let chorus_request = ChorusRequest {
|
|
||||||
request: Client::new()
|
let request = ChorusRequest::new(
|
||||||
.delete(url)
|
http::Method::DELETE,
|
||||||
.header("Authorization", user.token()),
|
&url,
|
||||||
limit_type: LimitType::Channel(channel_id),
|
None,
|
||||||
};
|
None,
|
||||||
chorus_request.handle_request_as_result(user).await
|
None,
|
||||||
|
Some(user),
|
||||||
|
LimitType::Channel(channel_id),
|
||||||
|
);
|
||||||
|
|
||||||
|
request.handle_request_as_result(user).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use reqwest::Client;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
api::LimitType,
|
api::LimitType,
|
||||||
errors::ChorusResult,
|
errors::ChorusResult,
|
||||||
|
@ -28,13 +26,18 @@ impl ReactionMeta {
|
||||||
self.channel_id,
|
self.channel_id,
|
||||||
self.message_id
|
self.message_id
|
||||||
);
|
);
|
||||||
let chorus_request = ChorusRequest {
|
|
||||||
request: Client::new()
|
let request = ChorusRequest::new(
|
||||||
.delete(url)
|
http::Method::DELETE,
|
||||||
.header("Authorization", user.token()),
|
&url,
|
||||||
limit_type: LimitType::Channel(self.channel_id),
|
None,
|
||||||
};
|
None,
|
||||||
chorus_request.handle_request_as_result(user).await
|
None,
|
||||||
|
Some(user),
|
||||||
|
LimitType::Channel(self.channel_id),
|
||||||
|
);
|
||||||
|
|
||||||
|
request.handle_request_as_result(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a list of users that reacted with a specific emoji to a message.
|
/// Gets a list of users that reacted with a specific emoji to a message.
|
||||||
|
@ -52,13 +55,18 @@ impl ReactionMeta {
|
||||||
self.message_id,
|
self.message_id,
|
||||||
emoji
|
emoji
|
||||||
);
|
);
|
||||||
let chorus_request = ChorusRequest {
|
|
||||||
request: Client::new().get(url).header("Authorization", user.token()),
|
let request = ChorusRequest::new(
|
||||||
limit_type: LimitType::Channel(self.channel_id),
|
http::Method::GET,
|
||||||
};
|
&url,
|
||||||
chorus_request
|
None,
|
||||||
.deserialize_response::<Vec<PublicUser>>(user)
|
None,
|
||||||
.await
|
None,
|
||||||
|
Some(user),
|
||||||
|
LimitType::Channel(self.channel_id),
|
||||||
|
);
|
||||||
|
|
||||||
|
request.deserialize_response::<Vec<PublicUser>>(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deletes all the reactions for a given emoji on a message.
|
/// Deletes all the reactions for a given emoji on a message.
|
||||||
|
@ -78,13 +86,18 @@ impl ReactionMeta {
|
||||||
self.message_id,
|
self.message_id,
|
||||||
emoji
|
emoji
|
||||||
);
|
);
|
||||||
let chorus_request = ChorusRequest {
|
|
||||||
request: Client::new()
|
let request = ChorusRequest::new(
|
||||||
.delete(url)
|
http::Method::DELETE,
|
||||||
.header("Authorization", user.token()),
|
&url,
|
||||||
limit_type: LimitType::Channel(self.channel_id),
|
None,
|
||||||
};
|
None,
|
||||||
chorus_request.handle_request_as_result(user).await
|
None,
|
||||||
|
Some(user),
|
||||||
|
LimitType::Channel(self.channel_id),
|
||||||
|
);
|
||||||
|
|
||||||
|
request.handle_request_as_result(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a reaction on a message.
|
/// Create a reaction on a message.
|
||||||
|
@ -107,14 +120,18 @@ impl ReactionMeta {
|
||||||
self.message_id,
|
self.message_id,
|
||||||
emoji
|
emoji
|
||||||
);
|
);
|
||||||
let chorus_request = ChorusRequest {
|
|
||||||
request: Client::new()
|
let request = ChorusRequest::new(
|
||||||
.put(url)
|
http::Method::PUT,
|
||||||
.header("Authorization", user.token())
|
&url,
|
||||||
.header("Content-Type", "application/json"),
|
None,
|
||||||
limit_type: LimitType::Channel(self.channel_id),
|
None,
|
||||||
};
|
None,
|
||||||
chorus_request.handle_request_as_result(user).await
|
Some(user),
|
||||||
|
LimitType::Channel(self.channel_id),
|
||||||
|
);
|
||||||
|
|
||||||
|
request.handle_request_as_result(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deletes a reaction the current user has made to the message.
|
/// Deletes a reaction the current user has made to the message.
|
||||||
|
@ -132,13 +149,18 @@ impl ReactionMeta {
|
||||||
self.message_id,
|
self.message_id,
|
||||||
emoji
|
emoji
|
||||||
);
|
);
|
||||||
let chorus_request = ChorusRequest {
|
|
||||||
request: Client::new()
|
let request = ChorusRequest::new(
|
||||||
.delete(url)
|
http::Method::DELETE,
|
||||||
.header("Authorization", user.token()),
|
&url,
|
||||||
limit_type: LimitType::Channel(self.channel_id),
|
None,
|
||||||
};
|
None,
|
||||||
chorus_request.handle_request_as_result(user).await
|
None,
|
||||||
|
Some(user),
|
||||||
|
LimitType::Channel(self.channel_id),
|
||||||
|
);
|
||||||
|
|
||||||
|
request.handle_request_as_result(user).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deletes a user's reaction to a message.
|
/// Deletes a user's reaction to a message.
|
||||||
|
@ -164,12 +186,17 @@ impl ReactionMeta {
|
||||||
emoji,
|
emoji,
|
||||||
user_id
|
user_id
|
||||||
);
|
);
|
||||||
let chorus_request = ChorusRequest {
|
|
||||||
request: Client::new()
|
let request = ChorusRequest::new(
|
||||||
.delete(url)
|
http::Method::DELETE,
|
||||||
.header("Authorization", user.token()),
|
&url,
|
||||||
limit_type: LimitType::Channel(self.channel_id),
|
None,
|
||||||
};
|
None,
|
||||||
chorus_request.handle_request_as_result(user).await
|
None,
|
||||||
|
Some(user),
|
||||||
|
LimitType::Channel(self.channel_id),
|
||||||
|
);
|
||||||
|
|
||||||
|
request.handle_request_as_result(user).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,9 +81,10 @@ impl Guild {
|
||||||
pub async fn create_channel(
|
pub async fn create_channel(
|
||||||
&self,
|
&self,
|
||||||
user: &mut ChorusUser,
|
user: &mut ChorusUser,
|
||||||
|
audit_log_reason: Option<String>,
|
||||||
schema: ChannelCreateSchema,
|
schema: ChannelCreateSchema,
|
||||||
) -> ChorusResult<Channel> {
|
) -> ChorusResult<Channel> {
|
||||||
Channel::create(user, self.id, schema).await
|
Channel::create(user, self.id, audit_log_reason, schema).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a list of the guild's channels.
|
/// Returns a list of the guild's channels.
|
||||||
|
@ -224,10 +225,10 @@ impl Channel {
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
user: &mut ChorusUser,
|
user: &mut ChorusUser,
|
||||||
guild_id: Snowflake,
|
guild_id: Snowflake,
|
||||||
|
audit_log_reason: Option<String>,
|
||||||
schema: ChannelCreateSchema,
|
schema: ChannelCreateSchema,
|
||||||
) -> ChorusResult<Channel> {
|
) -> ChorusResult<Channel> {
|
||||||
let chorus_request = ChorusRequest {
|
let mut request = Client::new()
|
||||||
request: Client::new()
|
|
||||||
.post(format!(
|
.post(format!(
|
||||||
"{}/guilds/{}/channels",
|
"{}/guilds/{}/channels",
|
||||||
user.belongs_to.borrow().urls.api,
|
user.belongs_to.borrow().urls.api,
|
||||||
|
@ -235,7 +236,12 @@ impl Channel {
|
||||||
))
|
))
|
||||||
.header("Authorization", user.token())
|
.header("Authorization", user.token())
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
.body(to_string(&schema).unwrap()),
|
.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,
|
||||||
limit_type: LimitType::Guild(guild_id),
|
limit_type: LimitType::Guild(guild_id),
|
||||||
};
|
};
|
||||||
chorus_request.deserialize_response::<Channel>(user).await
|
chorus_request.deserialize_response::<Channel>(user).await
|
||||||
|
|
|
@ -20,6 +20,54 @@ pub struct ChorusRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChorusRequest {
|
impl ChorusRequest {
|
||||||
|
/// Makes a new [`ChorusRequest`].
|
||||||
|
/// # Arguments
|
||||||
|
/// * `method` - The HTTP method to use. Must be one of the following:
|
||||||
|
/// * [`http::Method::GET`]
|
||||||
|
/// * [`http::Method::POST`]
|
||||||
|
/// * [`http::Method::PUT`]
|
||||||
|
/// * [`http::Method::DELETE`]
|
||||||
|
/// * [`http::Method::PATCH`]
|
||||||
|
/// * [`http::Method::HEAD`]
|
||||||
|
#[allow(unused_variables)] // TODO: Add mfa_token to request, once we figure out *how* to do so correctly
|
||||||
|
pub fn new(
|
||||||
|
method: http::Method,
|
||||||
|
url: &str,
|
||||||
|
body: Option<String>,
|
||||||
|
audit_log_reason: Option<&str>,
|
||||||
|
mfa_token: Option<&str>,
|
||||||
|
chorus_user: Option<&mut ChorusUser>,
|
||||||
|
limit_type: LimitType,
|
||||||
|
) -> ChorusRequest {
|
||||||
|
let request = Client::new();
|
||||||
|
let mut request = match method {
|
||||||
|
http::Method::GET => request.get(url),
|
||||||
|
http::Method::POST => request.post(url),
|
||||||
|
http::Method::PUT => request.put(url),
|
||||||
|
http::Method::DELETE => request.delete(url),
|
||||||
|
http::Method::PATCH => request.patch(url),
|
||||||
|
http::Method::HEAD => request.head(url),
|
||||||
|
_ => panic!("Illegal state: Method not supported."),
|
||||||
|
};
|
||||||
|
if let Some(user) = chorus_user {
|
||||||
|
request = request.header("Authorization", user.token());
|
||||||
|
}
|
||||||
|
if let Some(body) = body {
|
||||||
|
// ONCE TOLD ME THE WORLD WAS GONNA ROLL ME
|
||||||
|
request = request
|
||||||
|
.body(body)
|
||||||
|
.header("Content-Type", "application/json");
|
||||||
|
}
|
||||||
|
if let Some(reason) = audit_log_reason {
|
||||||
|
request = request.header("X-Audit-Log-Reason", reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChorusRequest {
|
||||||
|
request,
|
||||||
|
limit_type,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Sends a [`ChorusRequest`]. Checks if the user is rate limited, and if not, sends the request.
|
/// Sends a [`ChorusRequest`]. Checks if the user is rate limited, and if not, sends the request.
|
||||||
/// If the user is not rate limited and the instance has rate limits enabled, it will update the
|
/// If the user is not rate limited and the instance has rate limits enabled, it will update the
|
||||||
/// rate limits.
|
/// rate limits.
|
||||||
|
|
|
@ -22,7 +22,7 @@ async fn get_channel() {
|
||||||
async fn delete_channel() {
|
async fn delete_channel() {
|
||||||
let mut bundle = common::setup().await;
|
let mut bundle = common::setup().await;
|
||||||
let channel_guard = bundle.channel.write().unwrap().clone();
|
let channel_guard = bundle.channel.write().unwrap().clone();
|
||||||
let result = Channel::delete(channel_guard, &mut bundle.user).await;
|
let result = Channel::delete(channel_guard, None, &mut bundle.user).await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
common::teardown(bundle).await
|
common::teardown(bundle).await
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,10 @@ async fn modify_channel() {
|
||||||
default_thread_rate_limit_per_user: None,
|
default_thread_rate_limit_per_user: None,
|
||||||
video_quality_mode: None,
|
video_quality_mode: None,
|
||||||
};
|
};
|
||||||
let modified_channel = channel.modify(modify_data, &mut bundle.user).await.unwrap();
|
let modified_channel = channel
|
||||||
|
.modify(modify_data, None, &mut bundle.user)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
assert_eq!(modified_channel.name, Some(CHANNEL_NAME.to_string()));
|
assert_eq!(modified_channel.name, Some(CHANNEL_NAME.to_string()));
|
||||||
|
|
||||||
let permission_override = PermissionFlags::from_vec(Vec::from([
|
let permission_override = PermissionFlags::from_vec(Vec::from([
|
||||||
|
@ -66,7 +69,12 @@ async fn modify_channel() {
|
||||||
deny: "0".to_string(),
|
deny: "0".to_string(),
|
||||||
};
|
};
|
||||||
let channel_id: Snowflake = bundle.channel.read().unwrap().id;
|
let channel_id: Snowflake = bundle.channel.read().unwrap().id;
|
||||||
Channel::edit_permissions(&mut bundle.user, channel_id, permission_override.clone())
|
Channel::modify_permissions(
|
||||||
|
&mut bundle.user,
|
||||||
|
channel_id,
|
||||||
|
None,
|
||||||
|
permission_override.clone(),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ pub(crate) async fn setup() -> TestBundle {
|
||||||
};
|
};
|
||||||
let mut user = instance.register_account(®).await.unwrap();
|
let mut user = instance.register_account(®).await.unwrap();
|
||||||
let guild = Guild::create(&mut user, guild_create_schema).await.unwrap();
|
let guild = Guild::create(&mut user, guild_create_schema).await.unwrap();
|
||||||
let channel = Channel::create(&mut user, guild.id, channel_create_schema)
|
let channel = Channel::create(&mut user, guild.id, None, channel_create_schema)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ async fn test_self_updating_structs() {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
received_channel
|
received_channel
|
||||||
.modify(modify_schema, &mut bundle.user)
|
.modify(modify_schema, None, &mut bundle.user)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -115,7 +115,7 @@ async fn test_stickies() {
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
Vec::<Message>::new()
|
Vec::<Message>::new()
|
||||||
);
|
);
|
||||||
Message::sticky(channel.id, message.id, &mut bundle.user)
|
Message::sticky(channel.id, message.id, None, &mut bundle.user)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -127,7 +127,7 @@ async fn test_stickies() {
|
||||||
.id,
|
.id,
|
||||||
message.id
|
message.id
|
||||||
);
|
);
|
||||||
Message::unsticky(channel.id, message.id, &mut bundle.user)
|
Message::unsticky(channel.id, message.id, None, &mut bundle.user)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Reference in New Issue