diff options
| author | 2018-08-11 00:36:28 +0200 | |
|---|---|---|
| committer | 2018-08-11 00:36:28 +0200 | |
| commit | 85add87aa8c12ce01a5a1821480c23664783fc1f (patch) | |
| tree | 22805cbe4d37ac3144962aafd2a49d610cdd2400 | |
| parent | [Constants] Specify encoding for YAML files (diff) | |
Fixing bug where antispam would not ignore message ids, making antispam mod-alerts into beautiful embeds, adding IDs to all filtering and antispam embeds.
| -rw-r--r-- | bot/__main__.py | 3 | ||||
| -rw-r--r-- | bot/cogs/antispam.py | 59 | ||||
| -rw-r--r-- | bot/cogs/filtering.py | 6 |
3 files changed, 40 insertions, 28 deletions
diff --git a/bot/__main__.py b/bot/__main__.py index aa73e42bd..30d1b4c9a 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -41,6 +41,7 @@ bot.load_extension("bot.cogs.logging") bot.load_extension("bot.cogs.security") bot.load_extension("bot.cogs.events") bot.load_extension("bot.cogs.filtering") +bot.load_extension("bot.cogs.modlog") # Commands, etc bot.load_extension("bot.cogs.antispam") @@ -49,9 +50,9 @@ bot.load_extension("bot.cogs.bot") bot.load_extension("bot.cogs.clean") bot.load_extension("bot.cogs.cogs") + # Only load this in production if not DEBUG_MODE: - bot.load_extension("bot.cogs.modlog") bot.load_extension("bot.cogs.verification") # Feature cogs diff --git a/bot/cogs/antispam.py b/bot/cogs/antispam.py index fa30e53ac..9f8821d35 100644 --- a/bot/cogs/antispam.py +++ b/bot/cogs/antispam.py @@ -5,14 +5,15 @@ from datetime import datetime, timedelta from typing import Dict, List from dateutil.relativedelta import relativedelta -from discord import Member, Message, Object, TextChannel +from discord import Colour, Member, Message, Object, TextChannel from discord.ext.commands import Bot from bot import rules +from bot.cogs.modlog import ModLog from bot.constants import ( AntiSpam as AntiSpamConfig, Channels, - Colours, Guild as GuildConfig, - Icons, Roles + Colours, DEBUG_MODE, Event, + Guild as GuildConfig, Icons, Roles, ) from bot.utils.time import humanize as humanize_delta @@ -45,6 +46,10 @@ class AntiSpam: self.bot = bot self.muted_role = None + @property + def mod_log(self) -> ModLog: + return self.bot.get_cog("ModLog") + async def on_ready(self): role_id = AntiSpamConfig.punishment['role_id'] self.muted_role = Object(role_id) @@ -53,8 +58,8 @@ class AntiSpam: if ( message.guild.id != GuildConfig.id or message.author.bot - or message.channel.id in WHITELISTED_CHANNELS - or message.author.top_role.id in WHITELISTED_ROLES + or (message.channel.id in WHITELISTED_CHANNELS and not DEBUG_MODE) + or (message.author.top_role.id in WHITELISTED_ROLES and not DEBUG_MODE) ): return @@ -107,36 +112,40 @@ class AntiSpam: duration_delta = relativedelta(seconds=remove_role_after) human_duration = humanize_delta(duration_delta) - mod_alert_channel = self.bot.get_channel(Channels.mod_alerts) - if mod_alert_channel is not None: - await mod_alert_channel.send( - f"<:messagefiltered:473092874289020929> Spam detected in {msg.channel.mention}. " - f"See the message and mod log for further details." - ) - else: - log.warning( - "Tried logging spam event to the mod-alerts channel, but it could not be found." - ) + mod_alert_message = ( + f"**Triggered by:** {member.display_name}#{member.discriminator} (`{member.id}`)\n" + f"**Channel:** {msg.channel.mention}\n" + f"**Reason:** {reason}\n" + "See the message and mod log for further details." + ) + await self.mod_log.send_log_message( + icon_url=Icons.filtering, + colour=Colour(Colours.soft_red), + title=f"Spam detected!", + text=mod_alert_message, + thumbnail=msg.author.avatar_url_as(static_format="png"), + channel_id=Channels.mod_alerts, + ping_everyone=True + ) await member.add_roles(self.muted_role, reason=reason) description = textwrap.dedent(f""" - **Channel**: {msg.channel.mention} - **User**: {msg.author.mention} (`{msg.author.id}`) - **Reason**: {reason} - Role will be removed after {human_duration}. + **Channel**: {msg.channel.mention} + **User**: {msg.author.mention} (`{msg.author.id}`) + **Reason**: {reason} + Role will be removed after {human_duration}. """) - modlog = self.bot.get_cog('ModLog') - await modlog.send_log_message( - icon_url=Icons.user_mute, colour=Colours.soft_red, + await self.mod_log.send_log_message( + icon_url=Icons.user_mute, colour=Colour(Colours.soft_red), title="User muted", text=description ) await asyncio.sleep(remove_role_after) await member.remove_roles(self.muted_role, reason="AntiSpam mute expired") - await modlog.send_log_message( - icon_url=Icons.user_mute, colour=Colours.soft_green, + await self.mod_log.send_log_message( + icon_url=Icons.user_mute, colour=Colour(Colours.soft_green), title="User unmuted", text=f"Was muted by `AntiSpam` cog for {human_duration}." ) @@ -147,6 +156,8 @@ class AntiSpam: # If we have more than one message, we can use bulk delete. if len(messages) > 1: + message_ids = [message.id for message in messages] + self.mod_log.ignore(Event.message_delete, *message_ids) await channel.delete_messages(messages) # Otherwise, the bulk delete endpoint will throw up. diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py index 89735e57c..586c99174 100644 --- a/bot/cogs/filtering.py +++ b/bot/cogs/filtering.py @@ -110,13 +110,13 @@ class Filtering: if triggered: message = ( f"The {filter_name} {_filter['type']} was triggered " - f"by **{msg.author.name}#{msg.author.discriminator}** in " - f"<#{msg.channel.id}> with the following message:\n\n" + f"by **{msg.author.name}#{msg.author.discriminator}** " + f"(`{msg.author.id}`) in <#{msg.channel.id}> with the " + f"following message:\n\n" f"{msg.content}" ) log.debug(message) - log.debug(Channels.mod_alerts) # Send pretty mod log embed to mod-alerts await self.mod_log.send_log_message( |