Block users from using external emoji (Fixes #2)
+ Scan incoming messages for emoji, if they are from an external server they are blocked + clippy + fmt
This commit is contained in:
@@ -474,11 +474,7 @@ async fn handle_errors(
|
||||
match command_result {
|
||||
Ok(()) => println!("Successfully processed command '{}'", command_name),
|
||||
Err(err) => {
|
||||
let reply_msg = format!(
|
||||
"Command '{}' returned an error. {}",
|
||||
command_name,
|
||||
err.to_string()
|
||||
);
|
||||
let reply_msg = format!("Command '{}' returned an error. {}", command_name, err,);
|
||||
println!("{}", reply_msg);
|
||||
msg.reply(&ctx.http, reply_msg).await.unwrap();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ use serenity::client::{Context, EventHandler};
|
||||
use serenity::http::AttachmentType;
|
||||
use serenity::model::channel::Message;
|
||||
use serenity::model::gateway::Ready;
|
||||
use serenity::utils::parse_emoji;
|
||||
|
||||
use crate::discord::helper::send_webhook_msg_to_player_channels;
|
||||
use crate::game::global_data::GlobalData;
|
||||
@@ -40,6 +41,23 @@ impl EventHandler for Handler {
|
||||
let guild = msg.guild(&ctx.cache).await.unwrap();
|
||||
let user_msg = msg.content.clone();
|
||||
|
||||
let re = regex::Regex::new(r"<a?:.+:\d+>").unwrap();
|
||||
|
||||
for emoji_cap in re.captures_iter(&user_msg) {
|
||||
if let Some(emoji) = parse_emoji(&emoji_cap[0]) {
|
||||
if !msg
|
||||
.guild(&ctx.cache)
|
||||
.await
|
||||
.unwrap()
|
||||
.emojis
|
||||
.contains_key(&emoji.id)
|
||||
{
|
||||
msg.reply(&ctx.http, "Your messages contains custom emojis from outside this guild and has been blocked.").await.unwrap();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let attachments: Vec<AttachmentType> = msg
|
||||
.attachments
|
||||
.iter()
|
||||
|
||||
@@ -114,7 +114,6 @@ pub async fn send_webhook_msg(
|
||||
msg: &str,
|
||||
attachment: Option<Vec<AttachmentType<'_>>>,
|
||||
) -> error::Result<()> {
|
||||
|
||||
let webhook = http.get_webhook(webhook_id).await?;
|
||||
|
||||
webhook
|
||||
|
||||
Reference in New Issue
Block a user