feat: add thread options to message responses

This commit is contained in:
oSumAtrIX 2023-06-21 23:58:17 +02:00
parent e14f5f26ba
commit b470563aab
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
4 changed files with 362 additions and 316 deletions

633
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@ homepage = "https://revanced.app"
license = "GPL-3.0"
name = "revanced-discord-bot"
repository = "https://github.com/revanced/revanced-discord-bot"
version = "2.4.2"
version = "2.5.0"
edition = "2021"
[profile.release]

View File

@ -10,7 +10,6 @@ mod guild_member_update;
mod interaction;
mod message_create;
mod ready;
mod thread_create;
pub struct Handler<T> {
options: poise::FrameworkOptions<T, Error>,

View File

@ -78,8 +78,9 @@ pub async fn handle_message_response(ctx: &serenity::Context, new_message: &sere
}
}
if let Err(err) = new_message
.channel_id
let channel_id = new_message.channel_id;
if let Err(err) = channel_id
.send_message(&ctx.http, |m| {
m.reference_message(new_message);
match &response.response.embed {
@ -108,6 +109,43 @@ pub async fn handle_message_response(ctx: &serenity::Context, new_message: &sere
new_message.author.tag(),
err
);
} else if let Some(thread_options) = &response.thread_options {
let channel = channel_id
.to_channel(&ctx.http)
.await
.unwrap()
.guild()
.unwrap();
// only apply this thread if the channel is a thread
if channel.thread_metadata.is_none() {
return;
}
// only edit this thread if the message is the first one
if channel_id
.messages(&ctx.http, |b| b.limit(1).before(new_message))
.await
.unwrap()
.len()
!= 0
{
return;
}
if let Err(err) = channel
.edit_thread(&ctx.http, |e| {
e.locked(thread_options.lock_on_response)
.archived(thread_options.close_on_response)
})
.await
{
error!(
"Failed to edit the thread from {}. Error: {:?}",
new_message.author.tag(),
err
);
}
}
}
}