From aba93d89cd70a6610a29db1d8606717baf4dd7f9 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sat, 8 Jul 2023 17:46:26 +0200 Subject: [PATCH] feat: respond to message reference --- configuration.example.json | 5 +++-- configuration.revanced.json | 12 ++++++++---- src/model/application.rs | 1 + src/utils/message_response.rs | 25 ++++++++++++++++++++++++- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/configuration.example.json b/configuration.example.json index be74183..c15b7a5 100644 --- a/configuration.example.json +++ b/configuration.example.json @@ -41,8 +41,9 @@ }, "thread_options": { "lock_on_response": false, - "close_on_response": false, - } + "close_on_response": false + }, + "respond_to_reference": false } ] } \ No newline at end of file diff --git a/configuration.revanced.json b/configuration.revanced.json index fd192a1..bfc72ba 100644 --- a/configuration.revanced.json +++ b/configuration.revanced.json @@ -160,7 +160,8 @@ "url": "" } } - } + }, + "respond_to_reference": true }, { "includes": { @@ -196,7 +197,8 @@ "url": "" } } - } + }, + "respond_to_reference": true }, { "includes": { @@ -247,7 +249,8 @@ "url": "" } } - } + }, + "respond_to_reference": true }, { "includes": { @@ -308,7 +311,8 @@ "url": "" } } - } + }, + "respond_to_reference": true } ] } diff --git a/src/model/application.rs b/src/model/application.rs index 440022a..95c08e6 100644 --- a/src/model/application.rs +++ b/src/model/application.rs @@ -86,6 +86,7 @@ pub struct MessageResponse { pub condition: Option, pub response: Response, pub thread_options: Option, + pub respond_to_reference: Option, } #[derive(Serialize, Deserialize)] diff --git a/src/utils/message_response.rs b/src/utils/message_response.rs index 9def3db..4619ede 100644 --- a/src/utils/message_response.rs +++ b/src/utils/message_response.rs @@ -82,9 +82,32 @@ pub async fn handle_message_response(ctx: &serenity::Context, new_message: &sere let channel_id = new_message.channel_id; + let mut message_reference: Option<&serenity::Message> = None; + + // If the message has a reference and the response is set to respond to references, respond to the reference + if let Some(respond_to_reference) = response.respond_to_reference { + if respond_to_reference { + if let Some(reference) = &new_message.referenced_message { + message_reference = Some(reference.as_ref()); + if let Err(err) = new_message.delete(&ctx.http).await { + error!( + "Failed to delete the message from {}. Error: {:?}", + new_message.author.tag(), + err + ); + } + } + } + } + if let Err(err) = channel_id .send_message(&ctx.http, |m| { - m.reference_message(new_message); + if let Some(reference) = message_reference { + m.reference_message(reference); + } else { + m.reference_message(new_message); + } + match &response.response.embed { Some(embed) => m.embed(|e| { e.title(&embed.title)