Skip to content

Commit

Permalink
Add anti nitro spam measures (FO-nTTaX#39)
Browse files Browse the repository at this point in the history
* Add anti nitro spam stuff

* Add nitro triggers

* Update requirements.txt
  • Loading branch information
hjpalpha authored Jan 26, 2023
1 parent fe6f31d commit 3a7dcb7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
53 changes: 53 additions & 0 deletions ftsbot/cogs/antispam.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ftsbot import config
from ftsbot import data
from ftsbot.ui.reportform import reportform
from unidecode import unidecode


class antispam(
Expand Down Expand Up @@ -134,6 +135,58 @@ async def on_message(
)
# delete flagged message
await message.delete()
else:
cleaned_message_content = unidecode(message.content).lower()
if 'nitro' in cleaned_message_content:
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 not has_exception_role:
has_additional_triggers = 0
for trigger_word in data.nitro_spam_triggers:
if trigger_word in cleaned_message_content:
has_additional_triggers = has_additional_triggers + 1
if has_additional_triggers > 1:
# 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 nitro 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 nitro 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(
Expand Down
10 changes: 10 additions & 0 deletions ftsbot/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,13 @@
'nft',
'crypto',
]

nitro_spam_triggers = [
'discord',
'dissord',
'discrod',
'dissrod',
'free',
'gift',
'giveaway',
]
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
discord.py>=2.0.0
requests>=2.26.0
unidecode>=1.3.6

0 comments on commit 3a7dcb7

Please sign in to comment.