Skip to content

Commit

Permalink
feat: respond to message reference
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Jul 8, 2023
1 parent 32630c7 commit aba93d8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
5 changes: 3 additions & 2 deletions configuration.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
},
"thread_options": {
"lock_on_response": false,
"close_on_response": false,
}
"close_on_response": false
},
"respond_to_reference": false
}
]
}
12 changes: 8 additions & 4 deletions configuration.revanced.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@
"url": ""
}
}
}
},
"respond_to_reference": true
},
{
"includes": {
Expand Down Expand Up @@ -196,7 +197,8 @@
"url": ""
}
}
}
},
"respond_to_reference": true
},
{
"includes": {
Expand Down Expand Up @@ -247,7 +249,8 @@
"url": ""
}
}
}
},
"respond_to_reference": true
},
{
"includes": {
Expand Down Expand Up @@ -308,7 +311,8 @@
"url": ""
}
}
}
},
"respond_to_reference": true
}
]
}
1 change: 1 addition & 0 deletions src/model/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub struct MessageResponse {
pub condition: Option<Condition>,
pub response: Response,
pub thread_options: Option<ThreadOptions>,
pub respond_to_reference: Option<bool>,
}

#[derive(Serialize, Deserialize)]
Expand Down
25 changes: 24 additions & 1 deletion src/utils/message_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit aba93d8

Please sign in to comment.