mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-22 02:37:57 -05:00
[Mod] Add kick and warn to mention spam (#4038)
* Mention spam addition Adjust code to allow for warning and kicking in mention spam automoderation. Added new subcommand group, mentionspam. Which will display settings of warn, kick, ban, mentionspam when called. Adjust config to account for this. * Condense config + removal of comments Condense config into one variable to make one call. Removed unneeded comments I left. * Add warning casetype Copied over from warnings cog * Update strings + change function names * Changed prints and logs. Account for showsettings, removed blocking. If this style breaks, blame draper... * Black format...still blaming draper. * Adding period at end of description Co-authored-by: Flame442 <34169552+Flame442@users.noreply.github.com> * config migration * Fix TypeError, add default information. * Max_mention wording change Thanks to @zephyrkul for suggesting the word changes. * Require argument for max_mention * Fix warn modlog case creation * Fix casetype conflict maaaaaaaaaagicccccccccc timeeeeeeeeeeeeeeeeeeeeeeeee Co-authored-by: Draper <27962761+Drapersniper@users.noreply.github.com> Co-authored-by: Flame442 <34169552+Flame442@users.noreply.github.com>
This commit is contained in:
@@ -42,18 +42,19 @@ class Events(MixinMeta):
|
||||
return False
|
||||
|
||||
async def check_mention_spam(self, message):
|
||||
guild = message.guild
|
||||
author = message.author
|
||||
guild, author = message.guild, message.author
|
||||
mention_spam = await self.config.guild(guild).mention_spam.all()
|
||||
|
||||
max_mentions = await self.config.guild(guild).ban_mention_spam()
|
||||
if max_mentions:
|
||||
mentions = set(message.mentions)
|
||||
if len(mentions) >= max_mentions:
|
||||
mentions = set(message.mentions)
|
||||
if mention_spam["ban"]:
|
||||
if len(mentions) >= mention_spam["ban"]:
|
||||
try:
|
||||
await guild.ban(author, reason=_("Mention spam (Autoban)"))
|
||||
except discord.HTTPException:
|
||||
log.info(
|
||||
"Failed to ban member for mention spam in server {}.".format(guild.id)
|
||||
log.warning(
|
||||
"Failed to ban a member ({member}) for mention spam in server {guild}.".format(
|
||||
member=author.id, guild=guild.id
|
||||
)
|
||||
)
|
||||
else:
|
||||
await modlog.create_case(
|
||||
@@ -68,6 +69,62 @@ class Events(MixinMeta):
|
||||
channel=None,
|
||||
)
|
||||
return True
|
||||
|
||||
if mention_spam["kick"]:
|
||||
if len(mentions) >= mention_spam["kick"]:
|
||||
try:
|
||||
await guild.kick(author, reason=_("Mention Spam (Autokick)"))
|
||||
except discord.HTTPException:
|
||||
log.warning(
|
||||
"Failed to kick a member ({member}) for mention spam in server {guild}".format(
|
||||
member=author.id, guild=guild.id
|
||||
)
|
||||
)
|
||||
else:
|
||||
await modlog.create_case(
|
||||
self.bot,
|
||||
guild,
|
||||
message.created_at,
|
||||
"kick",
|
||||
author,
|
||||
guild.me,
|
||||
_("Mention spam (Autokick)"),
|
||||
until=None,
|
||||
channel=None,
|
||||
)
|
||||
return True
|
||||
|
||||
if mention_spam["warn"]:
|
||||
if len(mentions) >= mention_spam["warn"]:
|
||||
try:
|
||||
await author.send(_("Please do not mass mention people!"))
|
||||
except (discord.HTTPException, discord.Forbidden):
|
||||
try:
|
||||
await message.channel.send(
|
||||
_("{member}, Please do not mass mention people!").format(
|
||||
member=author.mention
|
||||
)
|
||||
)
|
||||
except (discord.HTTPException, discord.Forbidden):
|
||||
log.warning(
|
||||
"Failed to warn a member ({member}) for mention spam in server {guild}".format(
|
||||
member=author.id, guild=guild.id
|
||||
)
|
||||
)
|
||||
return False
|
||||
|
||||
await modlog.create_case(
|
||||
self.bot,
|
||||
guild,
|
||||
message.created_at,
|
||||
"warning",
|
||||
author,
|
||||
guild.me,
|
||||
_("Mention spam (Autowarn)"),
|
||||
until=None,
|
||||
channel=None,
|
||||
)
|
||||
return True
|
||||
return False
|
||||
|
||||
@commands.Cog.listener()
|
||||
|
||||
Reference in New Issue
Block a user