From b5fb8bde9767b8deb7743aefb45941b96f3afc54 Mon Sep 17 00:00:00 2001 From: AnxietyisReal <96593068+AnxietyisReal@users.noreply.github.com> Date: Thu, 11 Jan 2024 09:19:39 +1100 Subject: [PATCH] Add new automod rule and refactor the existing rules --- src/components/Automod.ts | 5 +++ src/events/messageCreate.ts | 68 +++++++++++++++++++++++++++---------- 2 files changed, 55 insertions(+), 18 deletions(-) diff --git a/src/components/Automod.ts b/src/components/Automod.ts index 4a712ba..f169d9a 100644 --- a/src/components/Automod.ts +++ b/src/components/Automod.ts @@ -38,4 +38,9 @@ export default class Automoderator { data.timeout = setTimeout(()=>delete client.repeatedMessages[message.author.id], thresholdTime); } } + static async imageOnly(message:Discord.Message) { + const io_channels = ['468896467688620032']; + let deleteReason:string = 'This is an image-only channel and your message did not contain any images.'; + if (io_channels.includes(message.channelId) && message.attachments.size < 1 && message.attachments.every(x=>!x.contentType.includes('image/'))) await message.delete().then(()=>message.channel.send(deleteReason).then((msg:Discord.Message)=>setTimeout(()=>msg.delete(), 8000))); + } } diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index 7d5b08c..ee2fe45 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -12,28 +12,48 @@ export default class MessageCreate { if (!message.inGuild()) return (client.channels.resolve(client.config.dcServer.channels.logs) as Discord.TextChannel).send({content: `<:fish_unamused:1083675172407623711> ${MessageTool.formatMention(client.config.whitelist[0], 'user')}\n**${message.author.username}** (\`${message.author.id}\`) tried to send me a DM, their message is:\`\`\`${message.content}\`\`\``, allowedMentions: {parse: ['users']}}); let automodded: boolean; - if (client.config.botSwitches.automod && !message.member.roles.cache.has(client.config.dcServer.roles.dcmod) && !message.member.roles.cache.has(client.config.dcServer.roles.admin) && message.guildId === client.config.dcServer.id){ + if (client.config.botSwitches.automod && !message.member.roles.cache.has(client.config.dcServer.roles.dcmod) && !message.member.roles.cache.has(client.config.dcServer.roles.admin) && message.guildId === client.config.dcServer.id) { const automodFailReason = 'msg got possibly deleted by another bot.'; - if (await client.prohibitedWords.findWord(Automoderator.scanMsg(message))) { - automodded = true; - message.delete().catch(()=>Logger.console('log', 'AUTOMOD:PROHIBITEDWORDS', automodFailReason)); - message.channel.send('That word isn\'t allowed here.').then(x=>setTimeout(()=>x.delete(), 10000)); - await Automoderator.repeatedMessages(client, message, 30000, 3, 'bw', '30m', 'Prohibited word spam'); - } else if (message.content.toLowerCase().includes('discord.gg/') && !MessageTool.isStaff(message.member as Discord.GuildMember)) { - const validInvite = await client.fetchInvite(message.content.split(' ').find(x=>x.includes('discord.gg/'))).catch(()=>null); - if (validInvite && validInvite.guild?.id !== client.config.dcServer.id) { - automodded = true; - message.delete().catch(()=>Logger.console('log', 'AUTOMOD:ADVERTISEMENT', automodFailReason)); - message.channel.send('Please don\'t advertise other Discord servers.').then(x=>setTimeout(()=>x.delete(), 15000)); - await Automoderator.repeatedMessages(client, message, 60000, 2, 'adv', '1h', 'Discord advertisement'); + const automodRules = { + prohibitedWords: { + check: async()=>await client.prohibitedWords.findWord(Automoderator.scanMsg(message)), + action: async()=>{ + automodded = true; + message.delete().catch(()=>Logger.console('log', 'AUTOMOD:PROHIBITEDWORDS', automodFailReason)); + message.channel.send('That word isn\'t allowed here.').then(x=>setTimeout(()=>x.delete(), 10000)); + await Automoderator.repeatedMessages(client, message, 30000, 3, 'bw', '30m', 'Prohibited word spam'); + } + }, + discordInvite: { + check: async()=>message.content.toLowerCase().includes('discord.gg/') && !MessageTool.isStaff(message.member as Discord.GuildMember), + action: async()=>{ + const validInvite = await client.fetchInvite(message.content.split(' ').find(x=>x.includes('discord.gg/'))).catch(()=>null); + if (validInvite && validInvite.guild?.id !== client.config.dcServer.id) { + automodded = true; + message.delete().catch(()=>Logger.console('log', 'AUTOMOD:ADVERTISEMENT', automodFailReason)); + message.channel.send('Please don\'t advertise other Discord servers.').then(x=>setTimeout(()=>x.delete(), 15000)); + await Automoderator.repeatedMessages(client, message, 60000, 2, 'adv', '1h', 'Discord advertisement'); + } + } + }, + imageOnly: { + check: async()=>!MessageTool.isStaff(message.member as Discord.GuildMember), + action: async()=>await Automoderator.imageOnly(message) + } + }; + + for (const rule of Object.values(automodRules)) { + if (await rule.check()) { + await rule.action(); + break; } } - } + }; if (message.guildId === client.config.dcServer.id && !automodded) client.userLevels.messageIncremental(message.author.id); // Mop gifs from banned channels without admins having to mop them. - const bannedChannels = [] - if (['tenor.com/view', 'giphy.com/gifs', 'giphy.com/media'].some(e=>message.content.toLowerCase().includes(e)) && bannedChannels.includes(message.channelId)) message.reply('Gifs are not allowed in this channel.').then(()=>message.delete()) + // const bannedChannels = [] + // if (['tenor.com/view', 'giphy.com/gifs', 'giphy.com/media'].some(e=>message.content.toLowerCase().includes(e)) && bannedChannels.includes(message.channelId)) message.reply('Gifs are not allowed in this channel.').then(()=>message.delete()) // Autoresponse:tm: if (client.config.botSwitches.autores && !automodded) { @@ -73,10 +93,22 @@ export default class MessageCreate { title: '*Monster has broken something*', } ]; + let dontMention = [ + { + user_id: '309373272594579456', + message: 'Please don\'t tag Daggerwin, read rule 14 in <#468846117405196289>', + type: undefined + }, + { + user_id: '215497515934416896', + message: 'Please don\'t tag Monster unless it\'s important!', + type: Discord.MessageType.Default + } + ] if (message.type === Discord.MessageType.GuildBoost && message.channelId === GeneralChatID) message.channel.send({content: outgoingArrays.guildBoost[Math.floor(Math.random() * outgoingArrays.guildBoost.length)], allowedMentions: {parse: ['users']}}) - if (message.mentions.members.has('309373272594579456') && !MessageTool.isStaff(message.member)) message.reply('Please don\'t tag Daggerwin, read rule 14 in <#468846117405196289>'); - if (message.mentions.members.has('215497515934416896') && !MessageTool.isStaff(message.member) && message.type != Discord.MessageType.Reply) message.reply('Please don\'t tag Monster unless it\'s important!'); + if (dontMention.some(e=>message.mentions.members.has(e.user_id) && !MessageTool.isStaff(message.member)) && (dontMention.find(e => message.mentions.has(e.user_id)).type === undefined || message.type === dontMention.find(e => message.mentions.has(e.user_id)).type)) message.reply(dontMention.find(e=>message.mentions.members.has(e.user_id)).message); + if (incomingArrays.password.some(e=>message.content.toLowerCase().includes(e))) message.reply('Password and other details can be found in <#543494084363288637>'); if (incomingArrays.cantRead.some(e=>message.content.toLowerCase().includes(e))) message.reply(picStorage.cantRead); if (message.content.toLowerCase().includes('is daggerbot working')) message.reply(picStorage.amAlive);