Skip to content

Commit

Permalink
Merge pull request #146 from Project-Coda/dev
Browse files Browse the repository at this point in the history
Warn on mass mention
  • Loading branch information
ikifar2012 authored Mar 28, 2023
2 parents 58c6c10 + fe1202b commit 07b1f57
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 5 deletions.
43 changes: 41 additions & 2 deletions embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var kickAlert = async function(userkicking, userkicked, reason){
},
{
name: 'Joined Discord',
value: `${userkicked.createdAt}`,
value: `<t:${parseInt(userkicked.createdTimestamp / 1000, 10)}:F>`,
},
{
name: 'Mod ID',
Expand All @@ -130,4 +130,43 @@ var kickAlert = async function(userkicking, userkicked, reason){
sendError(err);
}
};
module.exports = { setembed, sendError, log, alert, banAlert, kickAlert };
var mentionAlert = async function(message){
try {
var embed = setembed({
title: '🚨 Mass Mention Alert 🚨',
description: `${message.author} has mass mentioned in ${message.channel}`,
thumbnail: {
url: `${message.member.displayAvatarURL({ dynamic: true })}`,
},
fields: [
{
name: 'Message Content',
value: `${message.content}`,
},
{
name: 'User ID',
value: `${message.author.id}`,
},
{
name: 'User Tag',
value: `${message.author.tag}`,
},
{
name: 'Joined Discord',
value: `<t:${parseInt(message.author.createdTimestamp / 1000, 10)}:F>`,
},
{
name: 'Joined Server',
value: `<t:${parseInt(message.member.joinedTimestamp / 1000, 10)}:F>`,
},
],
color: 0xe74c3c,
});
global.client.channels.cache.get(env.discord.logs_channel).send({ content: `Attention <@&${env.discord.mod_role}>, ${message.member} attempted to mass mention`, embeds: [embed] });
}
catch (err) {
console.log(err);
sendError(err);
}
};
module.exports = { setembed, sendError, log, alert, banAlert, kickAlert, mentionAlert };
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const pkg = require('./package.json');
const CustomVC = require('./utilities/custom-vc.js');
const autorole = require('./utilities/autorole.js');
const vctools = require('./utilities/vc-tools.js');
const { checkMention } = require('./utilities/message-filter.js');
global.client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.DirectMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildModeration],
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
Expand Down Expand Up @@ -84,6 +85,11 @@ const rest = new REST({ version: '9' }).setToken(env.discord.token);
embedcreator.sendError(error);
}
})();
global.client.on('messageCreate', async message => {
if (message.author.bot) return;
checkMention(message);
},
);

global.client.on('guildMemberAdd', async member => {

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coda-utilities",
"version": "3.1.0",
"version": "3.2.0",
"description": "A general utilities bot for Coda",
"main": "index.js",
"scripts": {
Expand Down
31 changes: 31 additions & 0 deletions utilities/message-filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const embedcreator = require('../embed.js');
const env = require('../env.js');
async function checkMention(message) {
try {
if (message.member.roles.cache.has(env.discord.admin_role) || message.member.roles.cache.has(env.discord.mod_role)) return;
if (message.content.includes('@everyone') || message.content.includes('@here')) {
embed = embedcreator.setembed(
{
title: 'Unauthorized Mention Detected',
description: 'You have attempted to mention everyone or here that behavior is not allowed.',
color: 0xe74c3c,
},
),
await embedcreator.mentionAlert(message);
reply = await message.reply({ embeds: [embed], ephemeral: true });
message.delete();
// wait 5 seconds then delete the reply
setTimeout(() => {
reply.delete();
}
, 5000);
}
}
catch (err) {
console.log(err);
embedcreator.sendError(err);
}
}
module.exports = {
checkMention,
};

0 comments on commit 07b1f57

Please sign in to comment.