From fe6f31d5f86a862c522aaedb05b25946e4b71f66 Mon Sep 17 00:00:00 2001 From: hjpalpha <75081997+hjpalpha@users.noreply.github.com> Date: Tue, 24 Jan 2023 02:03:13 +0100 Subject: [PATCH] Add anti invite spam measures (#37) * add bad words * add comment * add anti invite spam measures * remove trailing `/` for `discord.gg` * adjust text * exclude bot --- ftsbot/cogs/antispam.py | 51 +++++++++++++++++++++++++++++++++++++++++ ftsbot/data.py | 15 ++++++++++++ 2 files changed, 66 insertions(+) diff --git a/ftsbot/cogs/antispam.py b/ftsbot/cogs/antispam.py index 65a9968..7f3c3a6 100644 --- a/ftsbot/cogs/antispam.py +++ b/ftsbot/cogs/antispam.py @@ -9,6 +9,7 @@ from discord import app_commands from discord.ext import commands from ftsbot import config +from ftsbot import data from ftsbot.ui.reportform import reportform @@ -83,6 +84,56 @@ async def on_message( ) # delete flagged message await message.delete() + elif 'discord.gg' in message.content.lower(): + has_bad_word = False + for bad_word in data.bad_words: + if bad_word in message.content.lower(): + has_bad_word = True + break + has_exception_role = False + for role in message.author.roles: + if role.name in [ + 'Discord Admins', + 'Liquipedia Employee', + 'Administrator', + 'Bot', + ]: + has_exception_role = True + break + if has_bad_word and not has_exception_role: + # give muted role + mutedrole = discord.utils.get(message.guild.roles, name='Muted') + await message.author.add_roles(mutedrole) + # post message in staff channel + reporttarget = self.bot.get_channel(config.reporttarget) + time = message.created_at + await reporttarget.send( + embed=discord.Embed( + title=( + 'Muted for potential discord invite link spam - ' + + message.author.mention + ' in ' + message.channel.mention + + ' on ' + str(time)[:-7] + ' UTC:' + ), + color=discord.Color.blue(), + description=( + message.content + # Workaround for mentions not working in embed title on windows + + '\n\nsource: ' + message.author.mention + ' in ' + message.channel.mention + ) + ) + ) + # post response message so that user knows what is going on + await message.channel.send( + embed=discord.Embed( + colour=discord.Colour(0xff0000), + description=( + message.author.mention + ' you have been muted due to potential discord invite spam. ' + + 'This is a spam bot prevention. Admins will review it at their earliest convenience.' + ) + ) + ) + # delete flagged message + await message.delete() if 'liquidpedia' in message.content.lower(): await message.channel.send( embed=discord.Embed( diff --git a/ftsbot/data.py b/ftsbot/data.py index cb3b458..2d88584 100644 --- a/ftsbot/data.py +++ b/ftsbot/data.py @@ -178,3 +178,18 @@ 'R6 Predictions', 'Templates', ] + +# Words regularly used in invite spams +bad_words = [ + 'nudde', + 'nude', + 'sex', + 's3x', + 'seex', + 'tiktok', + '18+', + 'kiss', + 'onlyfans', + 'nft', + 'crypto', +]