Add support for replying on call
This commit is contained in:
@@ -6,8 +6,10 @@ use twilight_model::{
|
||||
gateway::payload::incoming::{MessageCreate, MessageDelete, MessageUpdate},
|
||||
id::Id,
|
||||
};
|
||||
use twilight_util::builder::embed::{EmbedAuthorBuilder, EmbedBuilder, ImageSource};
|
||||
|
||||
use crate::{
|
||||
constants::COLOR_WHITE,
|
||||
database::models::{Call, Channel, Message, User, UserIncident},
|
||||
discord::sanitizing::SanitizeDiscordMarkdown,
|
||||
framework::{
|
||||
@@ -23,7 +25,7 @@ use crate::{
|
||||
moderation::{Action, Rule, escape_message},
|
||||
},
|
||||
state::State,
|
||||
utils::i64_to_u64,
|
||||
utils::{ellipse, i64_to_u64},
|
||||
};
|
||||
|
||||
async fn penalize_user(
|
||||
@@ -177,6 +179,22 @@ impl OnMessageHandler<State> for CallMessageHandler {
|
||||
|
||||
let message: Message;
|
||||
|
||||
let replying_to = if let Some(reference) = &event.reference {
|
||||
if let Some(replying_to_message_id) = reference.message_id {
|
||||
Message::get_by_call_and_message_id(
|
||||
call.id,
|
||||
replying_to_message_id.get(),
|
||||
&rt.state.db,
|
||||
)
|
||||
.await?
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let replying_to_id = replying_to.as_ref().map(|i| i.message_id);
|
||||
|
||||
if rules
|
||||
.iter()
|
||||
.any(|rule| rule.action() == &Action::BlockAndPenalty)
|
||||
@@ -201,11 +219,28 @@ impl OnMessageHandler<State> for CallMessageHandler {
|
||||
.message(event.0.clone())
|
||||
.profile(profile.clone())
|
||||
.is_censored(!rules.is_empty())
|
||||
.replying_to_id(replying_to_id)
|
||||
.build()
|
||||
.expect(
|
||||
"The message builder was missing either the call ID, the message, or the profile",
|
||||
);
|
||||
} else {
|
||||
let mut embeds = vec![];
|
||||
|
||||
if let Some(replying_to) = replying_to {
|
||||
embeds.push(
|
||||
EmbedBuilder::new()
|
||||
.author(
|
||||
EmbedAuthorBuilder::new(replying_to.data.author_name).icon_url(
|
||||
ImageSource::url(replying_to.data.author_avatar_url).unwrap(),
|
||||
),
|
||||
)
|
||||
.color(COLOR_WHITE)
|
||||
.description(ellipse(replying_to.data.content, 100))
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
||||
let message_sent = rt
|
||||
.http
|
||||
.execute_webhook(Id::new(webhook_id), &webhook_token)
|
||||
@@ -213,6 +248,7 @@ impl OnMessageHandler<State> for CallMessageHandler {
|
||||
.username(&profile.name)
|
||||
.avatar_url(&profile.avatar_url)
|
||||
.content(&content)
|
||||
.embeds(&embeds)
|
||||
.wait()
|
||||
.await
|
||||
.inspect_err(|e| {
|
||||
@@ -230,6 +266,7 @@ impl OnMessageHandler<State> for CallMessageHandler {
|
||||
.message(event.0.clone())
|
||||
.profile(profile.clone())
|
||||
.is_censored(!rules.is_empty())
|
||||
.replying_to_id(replying_to_id)
|
||||
.propagation_message_id(message_sent.id.get())
|
||||
.propagation_channel_id(opposite_channel.id)
|
||||
.build()
|
||||
|
||||
Reference in New Issue
Block a user