Add support for masks
This commit is contained in:
+93
-28
@@ -9,17 +9,17 @@ use twilight_model::{
|
||||
id::Id,
|
||||
};
|
||||
use twilight_util::{
|
||||
builder::embed::{EmbedAuthorBuilder, EmbedBuilder, ImageSource},
|
||||
builder::embed::{EmbedAuthorBuilder, EmbedBuilder, EmbedFooterBuilder, ImageSource},
|
||||
snowflake::Snowflake,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
constants::COLOR_WHITE,
|
||||
database::models::{Call, Channel, Message, User, UserIncident},
|
||||
discord::sanitizing::SanitizeDiscordMarkdown,
|
||||
constants::{COLOR_WHITE, COLOR_YELLOW},
|
||||
database::models::{Call, Channel, Message, Participant, User, UserIncident},
|
||||
discord::{images, sanitizing::SanitizeDiscordMarkdown},
|
||||
extras::Extras,
|
||||
framework::{
|
||||
commands::{extras::ExtrasGetter, permissions::Permission},
|
||||
commands::extras::ExtrasGetter,
|
||||
events::traits::{
|
||||
EventResult, OnMessageDeleteHandler, OnMessageEditHandler, OnMessageHandler,
|
||||
},
|
||||
@@ -28,9 +28,9 @@ use crate::{
|
||||
},
|
||||
groups::calls::{
|
||||
components::{CodeOfConductButton, NeedHelpButton},
|
||||
embeds, get_display_profile,
|
||||
embeds,
|
||||
masks::{get_mask_avatar_url, get_mask_display_name},
|
||||
moderation::{Action, Rule, escape_message},
|
||||
permissions::NonNewAccountPermission,
|
||||
},
|
||||
state::State,
|
||||
utils::{ellipse, i64_to_u64},
|
||||
@@ -195,8 +195,6 @@ impl OnMessageHandler<State, Extras> for CallMessageHandler {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let profile = get_display_profile(event);
|
||||
|
||||
let (content, rules) = escape_message(event);
|
||||
|
||||
let message: Message;
|
||||
@@ -217,6 +215,30 @@ impl OnMessageHandler<State, Extras> for CallMessageHandler {
|
||||
};
|
||||
let replying_to_id = replying_to.as_ref().map(|i| i.message_id);
|
||||
|
||||
let participant = Participant::get_or_create(
|
||||
user.id,
|
||||
event.channel_id.get(),
|
||||
call.id,
|
||||
event
|
||||
.member
|
||||
.clone()
|
||||
.and_then(|member| member.nick)
|
||||
.or(event.author.global_name.clone())
|
||||
.unwrap_or(event.author.name.clone()),
|
||||
images::get_avatar_url(
|
||||
event
|
||||
.member
|
||||
.clone()
|
||||
.and_then(|inner| inner.avatar)
|
||||
.or(event.author.avatar),
|
||||
event.author.id.get(),
|
||||
event.author.discriminator as u64,
|
||||
),
|
||||
user.is_masked,
|
||||
&rt.state.db,
|
||||
)
|
||||
.await?;
|
||||
|
||||
if rules
|
||||
.iter()
|
||||
.any(|rule| rule.action() == &Action::BlockAndPenalty)
|
||||
@@ -232,14 +254,14 @@ impl OnMessageHandler<State, Extras> for CallMessageHandler {
|
||||
.create_message(Id::new(opposite_channel.id))
|
||||
.content(&format!(
|
||||
"🚩 **{}** Sent a message that was blocked.\n-# If you see an inappropiate message, please report it using `Message > Apps > Report Message`.",
|
||||
profile.name.sanitize(false)
|
||||
participant.display_name().sanitize(false)
|
||||
))
|
||||
.await?;
|
||||
|
||||
message = Message::build()
|
||||
.call_id(call.id)
|
||||
.message(event.0.clone())
|
||||
.profile(profile.clone())
|
||||
.participant(participant)
|
||||
.is_censored(!rules.is_empty())
|
||||
.replying_to_message_id(replying_to_id)
|
||||
.build()
|
||||
@@ -250,29 +272,72 @@ impl OnMessageHandler<State, Extras> for CallMessageHandler {
|
||||
let mut embeds = vec![];
|
||||
|
||||
if let Some(replying_to) = replying_to {
|
||||
embeds.push(
|
||||
EmbedBuilder::new()
|
||||
.author(
|
||||
EmbedAuthorBuilder::new(format!(
|
||||
"Replying to {}",
|
||||
replying_to.data.author_name
|
||||
if let Some(propagation_channel_id) = replying_to.data.propagation_channel_id {
|
||||
let (display_name, avatar_url) =
|
||||
if let Some(mask) = replying_to.data.author_mask {
|
||||
(
|
||||
if i64_to_u64(propagation_channel_id) != event.channel_id.get() {
|
||||
get_mask_display_name(&mask)
|
||||
} else {
|
||||
format!(
|
||||
"{} ({})",
|
||||
get_mask_display_name(&mask),
|
||||
replying_to.data.author_name
|
||||
)
|
||||
},
|
||||
get_mask_avatar_url(&mask).expect("Failed to get mask avatar URL"),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
replying_to.data.author_name.clone(),
|
||||
replying_to.data.author_avatar_url.clone(),
|
||||
)
|
||||
};
|
||||
|
||||
embeds.push(
|
||||
EmbedBuilder::new()
|
||||
.author(
|
||||
EmbedAuthorBuilder::new(format!("Replying to {display_name}",))
|
||||
.icon_url(ImageSource::url(avatar_url).unwrap()),
|
||||
)
|
||||
.color(COLOR_WHITE)
|
||||
.description(ellipse(replying_to.data.content, 100))
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if participant.is_masked {
|
||||
let last_message =
|
||||
Message::get_last_by_author_id(call.id, event.author.id.get(), &rt.state.db)
|
||||
.await?;
|
||||
|
||||
if last_message
|
||||
.map(|lm| lm.data.author_mask.is_none())
|
||||
.unwrap_or(true)
|
||||
{
|
||||
embeds.push(
|
||||
EmbedBuilder::new()
|
||||
.color(COLOR_YELLOW)
|
||||
.description(format!(
|
||||
"🎭 **{}** is wearing a mask! Their real identity is hidden.",
|
||||
participant.display_name()
|
||||
))
|
||||
.icon_url(
|
||||
ImageSource::url(replying_to.data.author_avatar_url).unwrap(),
|
||||
),
|
||||
)
|
||||
.color(COLOR_WHITE)
|
||||
.description(ellipse(replying_to.data.content, 100))
|
||||
.build(),
|
||||
);
|
||||
.footer(EmbedFooterBuilder::new(format!(
|
||||
"You can set your own mask using {}mask on.",
|
||||
prefixes[0]
|
||||
)))
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let message_sent = match rt
|
||||
.http
|
||||
.execute_webhook(Id::new(webhook_id), &webhook_token)
|
||||
.allowed_mentions(None)
|
||||
.username(&profile.name)
|
||||
.avatar_url(&profile.avatar_url)
|
||||
.username(&participant.display_name())
|
||||
.avatar_url(&participant.avatar_url())
|
||||
.content(&content.sanitize_mentions())
|
||||
.embeds(&embeds)
|
||||
.wait()
|
||||
@@ -307,7 +372,7 @@ impl OnMessageHandler<State, Extras> for CallMessageHandler {
|
||||
message = Message::build()
|
||||
.call_id(call.id)
|
||||
.message(event.0.clone())
|
||||
.profile(profile.clone())
|
||||
.participant(participant)
|
||||
.is_censored(!rules.is_empty())
|
||||
.replying_to_message_id(replying_to_id)
|
||||
.propagation_message_id(message_sent.id.get())
|
||||
|
||||
Reference in New Issue
Block a user