From 9e379f23528bef0faf4ffafbdd2470526bd78773 Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Sun, 6 Jan 2019 02:14:04 +0100 Subject: Adding 'rich embed' filter to filtering, 'embed'-support to modlog, and 'rich embed' filtering options to config --- bot/cogs/filtering.py | 73 ++++++++++++++++++++++++++++++++++++++++++++------- bot/cogs/modlog.py | 17 ++++++++++++ config-default.yml | 18 +++++++------ 3 files changed, 91 insertions(+), 17 deletions(-) diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py index 247ee26b8..f6a1e7b4d 100644 --- a/bot/cogs/filtering.py +++ b/bot/cogs/filtering.py @@ -45,6 +45,7 @@ class Filtering: "enabled": Filter.filter_zalgo, "function": self._has_zalgo, "type": "filter", + "content_only": True, "user_notification": Filter.notify_user_zalgo, "notification_msg": ( "Your post has been removed for abusing Unicode character rendering (aka Zalgo text). " @@ -55,6 +56,7 @@ class Filtering: "enabled": Filter.filter_invites, "function": self._has_invites, "type": "filter", + "content_only": True, "user_notification": Filter.notify_user_invites, "notification_msg": ( f"Per Rule 10, your invite link has been removed. {_staff_mistake_str}\n\n" @@ -65,20 +67,36 @@ class Filtering: "enabled": Filter.filter_domains, "function": self._has_urls, "type": "filter", + "content_only": True, "user_notification": Filter.notify_user_domains, "notification_msg": ( f"Your URL has been removed because it matched a blacklisted domain. {_staff_mistake_str}" ) }, + "filter_rich_embeds": { + "enabled": Filter.filter_rich_embeds, + "function": self._has_rich_embed, + "type": "filter", + "content_only": False, + "user_notification": Filter.notify_user_rich_embeds, + "notification_msg": ( + "Your post has been removed because it contained a rich embed. " + "This indicates that you're either using an unofficial discord client or are using a self-bot, " + "both of which violate Discord's Terms of Service.\n\n" + f"Please don't use a self-bot or an unofficial Discord client on our server. {_staff_mistake_str}" + ) + }, "watch_words": { "enabled": Filter.watch_words, "function": self._has_watchlist_words, "type": "watchlist", + "content_only": True, }, "watch_tokens": { "enabled": Filter.watch_tokens, "function": self._has_watchlist_tokens, "type": "watchlist", + "content_only": True, }, } @@ -115,18 +133,46 @@ class Filtering: ) # If we're running the bot locally, ignore role whitelist and only listen to #dev-test + # if DEBUG_MODE: + # filter_message = not msg.author.bot and msg.channel.id == Channels.devtest + if DEBUG_MODE: - filter_message = not msg.author.bot and msg.channel.id == Channels.devtest + filter_message = msg.author.id != 414020331980980234 and msg.channel.id == Channels.devtest # If none of the above, we can start filtering. if filter_message: + for filter_name, _filter in self.filters.items(): # Is this specific filter enabled in the config? if _filter["enabled"]: - triggered = await _filter["function"](msg.content) + # Does the filter only need the message content or the full message? + if _filter["content_only"]: + triggered = await _filter["function"](msg.content) + else: + triggered = await _filter["function"](msg) if triggered: + # If this is a filter (not a watchlist), we should delete the message. + if _filter["type"] == "filter": + try: + # Embeds (can) trigger both the `on_message` and `on_message_edit` + # event handlers, triggering filtering twice for the same message. + # + # If `on_message`-triggered filtering already deleted the message + # then `on_message_edit`-triggered filtering will raise exception + # since the message no longer exists. + # + # In addition, to avoid sending two notifications to the user, the + # logs, and mod_alert, we return if the message no longer exists. + await msg.delete() + except discord.errors.NotFound: + return + + # Notify the user if the filter specifies + if _filter["user_notification"]: + await self.notify_member(msg.author, _filter["notification_msg"], msg.channel) + if isinstance(msg.channel, DMChannel): channel_str = "via DM" else: @@ -153,13 +199,12 @@ class Filtering: ping_everyone=Filter.ping_everyone, ) - # If this is a filter (not a watchlist), we should delete the message. - if _filter["type"] == "filter": - await msg.delete() - - # Notify the user if the filter specifies - if _filter["user_notification"]: - await self.notify_member(msg.author, _filter["notification_msg"], msg.channel) + if filter_name == "filter_rich_embeds": + await self.mod_log.send_log_embeds( + embeds=msg.embeds, + content="The message contained the following embed(s):\n", + channel_id=Channels.mod_alerts, + ) break # We don't want multiple filters to trigger @@ -272,6 +317,16 @@ class Filtering: return True return False + @staticmethod + async def _has_rich_embed(msg: Message): + """ + Returns True if any of the embeds in the message + are of type 'rich', returns False otherwise + """ + if msg.embeds: + return any(embed.type == "rich" for embed in msg.embeds) + return False + async def notify_member(self, filtered_member: Member, reason: str, channel: TextChannel): """ Notify filtered_member about a moderation action with the reason str diff --git a/bot/cogs/modlog.py b/bot/cogs/modlog.py index 0561b5afb..a167ba9e8 100644 --- a/bot/cogs/modlog.py +++ b/bot/cogs/modlog.py @@ -127,6 +127,23 @@ class ModLog: await self.bot.get_channel(channel_id).send(content=content, embed=embed, files=files) + async def send_log_embeds( + self, embeds: List[Embed], content: Optional[str], + channel_id: int = Channels.modlog, ping_everyone: bool = False, + ): + + if ping_everyone: + if content: + content = f"@everyone\n{content}" + else: + content = "@everyone" + + if content: + await self.bot.get_channel(channel_id).send(content=content) + + for embed in embeds: + await self.bot.get_channel(channel_id).send(embed=embed) + async def on_guild_channel_create(self, channel: GUILD_CHANNEL): if channel.guild.id != GuildConstant.id: return diff --git a/config-default.yml b/config-default.yml index ad87e44ac..ad3487c78 100644 --- a/config-default.yml +++ b/config-default.yml @@ -134,17 +134,19 @@ guild: filter: # What do we filter? - filter_zalgo: false - filter_invites: true - filter_domains: true - watch_words: true - watch_tokens: true + filter_zalgo: false + filter_invites: true + filter_domains: true + filter_rich_embeds: true + watch_words: true + watch_tokens: true # Notify user on filter? # Notifications are not expected for "watchlist" type filters - notify_user_zalgo: false - notify_user_invites: true - notify_user_domains: false + notify_user_zalgo: false + notify_user_invites: true + notify_user_domains: false + notify_user_rich_embeds: true # Filter configuration ping_everyone: true # Ping @everyone when we send a mod-alert? -- cgit v1.2.3 From d9130047e7fcbedd0e033c23c6b82f608cd9039b Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Sun, 6 Jan 2019 02:38:17 +0100 Subject: Restoring DEBUG_MODE filtering condition and adding comment --- bot/cogs/filtering.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py index f6a1e7b4d..9324314df 100644 --- a/bot/cogs/filtering.py +++ b/bot/cogs/filtering.py @@ -133,11 +133,8 @@ class Filtering: ) # If we're running the bot locally, ignore role whitelist and only listen to #dev-test - # if DEBUG_MODE: - # filter_message = not msg.author.bot and msg.channel.id == Channels.devtest - if DEBUG_MODE: - filter_message = msg.author.id != 414020331980980234 and msg.channel.id == Channels.devtest + filter_message = not msg.author.bot and msg.channel.id == Channels.devtest # If none of the above, we can start filtering. if filter_message: @@ -199,6 +196,7 @@ class Filtering: ping_everyone=Filter.ping_everyone, ) + # If filtering rich embeds, also send the removed embeds to mod_alerts if filter_name == "filter_rich_embeds": await self.mod_log.send_log_embeds( embeds=msg.embeds, -- cgit v1.2.3 From 990a901d9a1d00340d401ea9f2c87f648056a144 Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Sun, 6 Jan 2019 20:48:20 +0100 Subject: Clarifying comment --- bot/cogs/filtering.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py index 9324314df..67ff9d0bf 100644 --- a/bot/cogs/filtering.py +++ b/bot/cogs/filtering.py @@ -153,7 +153,7 @@ class Filtering: # If this is a filter (not a watchlist), we should delete the message. if _filter["type"] == "filter": try: - # Embeds (can) trigger both the `on_message` and `on_message_edit` + # Embeds (can?) trigger both the `on_message` and `on_message_edit` # event handlers, triggering filtering twice for the same message. # # If `on_message`-triggered filtering already deleted the message -- cgit v1.2.3 From 5f4e617a98422a588e98e1e0d067e638877c5d65 Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Mon, 7 Jan 2019 19:45:57 +0100 Subject: Reverting modlog.py to original state --- bot/cogs/modlog.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/bot/cogs/modlog.py b/bot/cogs/modlog.py index a167ba9e8..0561b5afb 100644 --- a/bot/cogs/modlog.py +++ b/bot/cogs/modlog.py @@ -127,23 +127,6 @@ class ModLog: await self.bot.get_channel(channel_id).send(content=content, embed=embed, files=files) - async def send_log_embeds( - self, embeds: List[Embed], content: Optional[str], - channel_id: int = Channels.modlog, ping_everyone: bool = False, - ): - - if ping_everyone: - if content: - content = f"@everyone\n{content}" - else: - content = "@everyone" - - if content: - await self.bot.get_channel(channel_id).send(content=content) - - for embed in embeds: - await self.bot.get_channel(channel_id).send(embed=embed) - async def on_guild_channel_create(self, channel: GUILD_CHANNEL): if channel.guild.id != GuildConstant.id: return -- cgit v1.2.3 From fafa80ebcb29e4de5986a276ff85fb84e1d267be Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Mon, 7 Jan 2019 19:47:22 +0100 Subject: Modifying 'send_log_message' so it supports sending additional embeds to the specified (log) channel --- bot/cogs/modlog.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bot/cogs/modlog.py b/bot/cogs/modlog.py index 0561b5afb..c96838a54 100644 --- a/bot/cogs/modlog.py +++ b/bot/cogs/modlog.py @@ -106,7 +106,7 @@ class ModLog: async def send_log_message( self, icon_url: Optional[str], colour: Colour, title: Optional[str], text: str, thumbnail: str = None, channel_id: int = Channels.modlog, ping_everyone: bool = False, - files: List[File] = None, content: str = None + files: List[File] = None, content: str = None, additional_embeds: List[Embed] = None, ): embed = Embed(description=text) @@ -125,7 +125,14 @@ class ModLog: else: content = "@everyone" - await self.bot.get_channel(channel_id).send(content=content, embed=embed, files=files) + channel = self.bot.get_channel(channel_id) + + await channel.send(content=content, embed=embed, files=files) + + if additional_embeds: + await channel.send("With the following embed(s):") + for additional_embed in additional_embeds: + await channel.send(embed=additional_embed) async def on_guild_channel_create(self, channel: GUILD_CHANNEL): if channel.guild.id != GuildConstant.id: -- cgit v1.2.3 From e3ace591d9dca2d4ab95c7b07d6af3e6fc84b7c3 Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Mon, 7 Jan 2019 19:51:16 +0100 Subject: Changing the way in which the filter_rich_embed sends the embeds to mod_log.send_log_message --- bot/cogs/filtering.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py index 67ff9d0bf..5c6ed9c26 100644 --- a/bot/cogs/filtering.py +++ b/bot/cogs/filtering.py @@ -185,6 +185,8 @@ class Filtering: log.debug(message) + additional_embeds = msg.embeds if filter_name == "filter_rich_embeds" else None + # Send pretty mod log embed to mod-alerts await self.mod_log.send_log_message( icon_url=Icons.filtering, @@ -194,16 +196,10 @@ class Filtering: thumbnail=msg.author.avatar_url_as(static_format="png"), channel_id=Channels.mod_alerts, ping_everyone=Filter.ping_everyone, + additional_embeds=additional_embeds, ) # If filtering rich embeds, also send the removed embeds to mod_alerts - if filter_name == "filter_rich_embeds": - await self.mod_log.send_log_embeds( - embeds=msg.embeds, - content="The message contained the following embed(s):\n", - channel_id=Channels.mod_alerts, - ) - break # We don't want multiple filters to trigger @staticmethod -- cgit v1.2.3 From a78ac6d6e1661d2647dd61ca114ab695b5aa72af Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Mon, 7 Jan 2019 20:00:37 +0100 Subject: Including the filter_rich_embeds constants in bot/constants.py --- bot/constants.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bot/constants.py b/bot/constants.py index bbe6c1604..c1375bb13 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -201,6 +201,7 @@ class Filter(metaclass=YAMLGetter): filter_zalgo: bool filter_invites: bool filter_domains: bool + filter_rich_embeds: bool watch_words: bool watch_tokens: bool @@ -208,6 +209,7 @@ class Filter(metaclass=YAMLGetter): notify_user_zalgo: bool notify_user_invites: bool notify_user_domains: bool + notify_user_rich_embeds: bool ping_everyone: bool guild_invite_whitelist: List[int] -- cgit v1.2.3 From 543b2ae88c82fd5558785cee224680ff0285c7ad Mon Sep 17 00:00:00 2001 From: Daniel Brown Date: Mon, 7 Jan 2019 13:04:09 -0600 Subject: Corrected the delete_reminder() method to use the correct _delete_reminder method(). Signed-off-by: Daniel Brown --- bot/cogs/reminders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/reminders.py b/bot/cogs/reminders.py index f6ed111dc..ddf5cc1f3 100644 --- a/bot/cogs/reminders.py +++ b/bot/cogs/reminders.py @@ -398,7 +398,7 @@ class Reminders(Scheduler): ) if not failed: - self.cancel_reminder(response_data["reminder_id"]) + await self._delete_reminder(response_data["reminder_id"]) def setup(bot: Bot): -- cgit v1.2.3 From 16afa8d6cfa7ff70d73639ea3665bb47c5814586 Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Mon, 7 Jan 2019 20:44:00 +0100 Subject: Removing orphaned comment and restructuring user notification for filter_rich_embed --- bot/cogs/filtering.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py index 5c6ed9c26..42424cd05 100644 --- a/bot/cogs/filtering.py +++ b/bot/cogs/filtering.py @@ -82,8 +82,8 @@ class Filtering: "notification_msg": ( "Your post has been removed because it contained a rich embed. " "This indicates that you're either using an unofficial discord client or are using a self-bot, " - "both of which violate Discord's Terms of Service.\n\n" - f"Please don't use a self-bot or an unofficial Discord client on our server. {_staff_mistake_str}" + f"both of which violate Discord's Terms of Service. {_staff_mistake_str}\n\n" + "Please don't use a self-bot or an unofficial Discord client on our server." ) }, "watch_words": { @@ -140,7 +140,6 @@ class Filtering: if filter_message: for filter_name, _filter in self.filters.items(): - # Is this specific filter enabled in the config? if _filter["enabled"]: # Does the filter only need the message content or the full message? @@ -199,7 +198,6 @@ class Filtering: additional_embeds=additional_embeds, ) - # If filtering rich embeds, also send the removed embeds to mod_alerts break # We don't want multiple filters to trigger @staticmethod -- cgit v1.2.3 From 84437e0ddfed04b87c4d98d47f432e5f7d2e136f Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Mon, 7 Jan 2019 20:45:37 +0100 Subject: Deleting unnecessary additional line --- bot/cogs/filtering.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py index 42424cd05..570d6549f 100644 --- a/bot/cogs/filtering.py +++ b/bot/cogs/filtering.py @@ -138,7 +138,6 @@ class Filtering: # If none of the above, we can start filtering. if filter_message: - for filter_name, _filter in self.filters.items(): # Is this specific filter enabled in the config? if _filter["enabled"]: -- cgit v1.2.3 From 623923780bd5bb2aa1c9624e27faa20229c150a7 Mon Sep 17 00:00:00 2001 From: sco1 Date: Tue, 8 Jan 2019 13:40:04 -0500 Subject: Add RLBot to server whitelist Yay partners! --- config-default.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config-default.yml b/config-default.yml index ad87e44ac..4f4c79fa1 100644 --- a/config-default.yml +++ b/config-default.yml @@ -154,6 +154,7 @@ filter: - 267624335836053506 # Python Discord - 440186186024222721 # Python Discord: ModLog Emojis - 273944235143593984 # STEM + - 348658686962696195 # RLBot domain_blacklist: - pornhub.com -- cgit v1.2.3 From e9134a769b39e2cad58d03193d139760d3840bd7 Mon Sep 17 00:00:00 2001 From: sco1 Date: Tue, 8 Jan 2019 13:59:41 -0500 Subject: Add Pallets to server whitelist Yay partners! --- config-default.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config-default.yml b/config-default.yml index 4f4c79fa1..a51d00778 100644 --- a/config-default.yml +++ b/config-default.yml @@ -155,6 +155,7 @@ filter: - 440186186024222721 # Python Discord: ModLog Emojis - 273944235143593984 # STEM - 348658686962696195 # RLBot + - 531221516914917387 # Pallets domain_blacklist: - pornhub.com -- cgit v1.2.3 From e61a818b394a40185b934d67fe7a2a943edf81fc Mon Sep 17 00:00:00 2001 From: SebastiaanZ <33516116+SebastiaanZ@users.noreply.github.com> Date: Wed, 9 Jan 2019 19:05:06 +0100 Subject: Patch to make \!help work outside of #bot-commands again. We should look into a proper rewrite later. --- bot/cogs/help.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bot/cogs/help.py b/bot/cogs/help.py index d30ff0dfb..c82a25417 100644 --- a/bot/cogs/help.py +++ b/bot/cogs/help.py @@ -9,11 +9,13 @@ from discord.ext import commands from fuzzywuzzy import fuzz, process from bot import constants +from bot.decorators import InChannelCheckFailure from bot.pagination import ( DELETE_EMOJI, FIRST_EMOJI, LAST_EMOJI, LEFT_EMOJI, LinePaginator, RIGHT_EMOJI, ) + REACTIONS = { FIRST_EMOJI: 'first', LEFT_EMOJI: 'back', @@ -427,7 +429,15 @@ class HelpSession: # see if the user can run the command strikeout = '' - can_run = await command.can_run(self._ctx) + + # Patch to make the !help command work outside of #bot-commands again + # This probably needs a proper rewrite, but this will make it work in + # the mean time. + try: + can_run = await command.can_run(self._ctx) + except InChannelCheckFailure: + can_run = False + if not can_run: # skip if we don't show commands they can't run if self._only_can_run: -- cgit v1.2.3