feat: respond to message reference

This commit is contained in:
oSumAtrIX 2023-07-08 17:46:26 +02:00
parent 32630c7434
commit aba93d89cd
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
4 changed files with 36 additions and 7 deletions

View File

@ -41,8 +41,9 @@
}, },
"thread_options": { "thread_options": {
"lock_on_response": false, "lock_on_response": false,
"close_on_response": false, "close_on_response": false
} },
"respond_to_reference": false
} }
] ]
} }

View File

@ -160,7 +160,8 @@
"url": "" "url": ""
} }
} }
} },
"respond_to_reference": true
}, },
{ {
"includes": { "includes": {
@ -196,7 +197,8 @@
"url": "" "url": ""
} }
} }
} },
"respond_to_reference": true
}, },
{ {
"includes": { "includes": {
@ -247,7 +249,8 @@
"url": "" "url": ""
} }
} }
} },
"respond_to_reference": true
}, },
{ {
"includes": { "includes": {
@ -308,7 +311,8 @@
"url": "" "url": ""
} }
} }
} },
"respond_to_reference": true
} }
] ]
} }

View File

@ -86,6 +86,7 @@ pub struct MessageResponse {
pub condition: Option<Condition>, pub condition: Option<Condition>,
pub response: Response, pub response: Response,
pub thread_options: Option<ThreadOptions>, pub thread_options: Option<ThreadOptions>,
pub respond_to_reference: Option<bool>,
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]

View File

@ -82,9 +82,32 @@ pub async fn handle_message_response(ctx: &serenity::Context, new_message: &sere
let channel_id = new_message.channel_id; 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 if let Err(err) = channel_id
.send_message(&ctx.http, |m| { .send_message(&ctx.http, |m| {
if let Some(reference) = message_reference {
m.reference_message(reference);
} else {
m.reference_message(new_message); m.reference_message(new_message);
}
match &response.response.embed { match &response.response.embed {
Some(embed) => m.embed(|e| { Some(embed) => m.embed(|e| {
e.title(&embed.title) e.title(&embed.title)