aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bot/cogs/filtering.py50
-rw-r--r--bot/constants.py6
-rw-r--r--config-default.yml7
3 files changed, 56 insertions, 7 deletions
diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py
index f5811d9d2..27ec6aad9 100644
--- a/bot/cogs/filtering.py
+++ b/bot/cogs/filtering.py
@@ -1,7 +1,8 @@
import logging
import re
-from discord import Colour, Member, Message
+import discord.errors
+from discord import Colour, DMChannel, Member, Message, TextChannel
from discord.ext.commands import Bot
from bot.cogs.modlog import ModLog
@@ -42,27 +43,41 @@ class Filtering:
"filter_zalgo": {
"enabled": Filter.filter_zalgo,
"function": self._has_zalgo,
- "type": "filter"
+ "type": "filter",
+ "user_notification": Filter.notify_user_zalgo,
+ "notification_msg": ""
},
"filter_invites": {
"enabled": Filter.filter_invites,
"function": self._has_invites,
- "type": "filter"
+ "type": "filter",
+ "user_notification": Filter.notify_user_invites,
+ "notification_msg": (
+ "Per Rule 10, your invite link has been removed. "
+ "If you believe this was a mistake, please the staff know!\n\n"
+ r"Our server rules can be found here: <https://pythondiscord.com/about/rules>"
+ )
},
"filter_domains": {
"enabled": Filter.filter_domains,
"function": self._has_urls,
- "type": "filter"
+ "type": "filter",
+ "user_notification": Filter.notify_user_domains,
+ "notification_msg": ""
},
"watch_words": {
"enabled": Filter.watch_words,
"function": self._has_watchlist_words,
- "type": "watchlist"
+ "type": "watchlist",
+ "user_notification": Filter.notify_user_words,
+ "notification_msg": ""
},
"watch_tokens": {
"enabled": Filter.watch_tokens,
"function": self._has_watchlist_tokens,
- "type": "watchlist"
+ "type": "watchlist",
+ "user_notification": False, # Hardcode intentional, already in token remover cog
+ "notification_msg": ""
},
}
@@ -111,10 +126,15 @@ class Filtering:
triggered = await _filter["function"](msg.content)
if triggered:
+ if isinstance(msg.channel, DMChannel):
+ channel_str = "via DM"
+ else:
+ channel_str = f"in <#{msg.channel.id}>"
+
message = (
f"The {filter_name} {_filter['type']} was triggered "
f"by **{msg.author.name}#{msg.author.discriminator}** "
- f"(`{msg.author.id}`) in <#{msg.channel.id}> with [the "
+ f"(`{msg.author.id}`) {channel_str} with [the "
f"following message]({msg.jump_url}):\n\n"
f"{msg.content}"
)
@@ -136,6 +156,10 @@ class Filtering:
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)
+
break # We don't want multiple filters to trigger
@staticmethod
@@ -247,6 +271,18 @@ class Filtering:
return True
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
+
+ First attempts to DM the user, fall back to in-channel notification if user has DMs disabled
+ """
+
+ try:
+ await filtered_member.send(reason)
+ except discord.errors.Forbidden:
+ await channel.send(f"{filtered_member.mention} {reason}")
+
def setup(bot: Bot):
bot.add_cog(Filtering(bot))
diff --git a/bot/constants.py b/bot/constants.py
index 05d2abf81..f67b7f45f 100644
--- a/bot/constants.py
+++ b/bot/constants.py
@@ -204,6 +204,12 @@ class Filter(metaclass=YAMLGetter):
watch_words: bool
watch_tokens: bool
+ notify_user_zalgo: bool
+ notify_user_invites: bool
+ notify_user_domains: bool
+ notify_user_words: bool
+ # Token notification intentionally ignored, notification is handled by the token remover cog
+
ping_everyone: bool
guild_invite_whitelist: List[int]
domain_blacklist: List[str]
diff --git a/config-default.yml b/config-default.yml
index 7a5960987..5ea9fc602 100644
--- a/config-default.yml
+++ b/config-default.yml
@@ -140,6 +140,13 @@ filter:
watch_words: true
watch_tokens: true
+ # Notify user on filter?
+ notify_user_zalgo: false
+ notify_user_invites: true
+ notify_user_domains: false
+ notify_user_words: false
+ # Token notification intentionally ignored, notification is handled by the token remover cog
+
# Filter configuration
ping_everyone: true # Ping @everyone when we send a mod-alert?