From 69befe316b604f78f4ebc4f9445efa758ad6c3e3 Mon Sep 17 00:00:00 2001 From: GDWR Date: Tue, 1 Feb 2022 19:11:10 +0000 Subject: 🚸 Ping moderators when a bad username is detected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/exts/filters/filtering.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bot/exts/filters/filtering.py b/bot/exts/filters/filtering.py index 1f83acf9b..0ac6dfe51 100644 --- a/bot/exts/filters/filtering.py +++ b/bot/exts/filters/filtering.py @@ -261,7 +261,8 @@ class Filtering(Cog): title="Username filtering alert", text=log_string, channel_id=Channels.mod_alerts, - thumbnail=member.display_avatar.url + thumbnail=member.display_avatar.url, + ping_everyone=True ) # Update time when alert sent -- cgit v1.2.3 From c51fb9c9c98b02c393ae56867d4365b41cd3f77d Mon Sep 17 00:00:00 2001 From: GDWR Date: Tue, 1 Feb 2022 19:19:33 +0000 Subject: ✨ Check for bad username when user joins or switches voice channel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/exts/filters/filtering.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bot/exts/filters/filtering.py b/bot/exts/filters/filtering.py index 0ac6dfe51..7b708f9a9 100644 --- a/bot/exts/filters/filtering.py +++ b/bot/exts/filters/filtering.py @@ -12,7 +12,7 @@ import tldextract from async_rediscache import RedisCache from botcore.regex import DISCORD_INVITE from dateutil.relativedelta import relativedelta -from discord import Colour, HTTPException, Member, Message, NotFound, TextChannel +from discord import Colour, HTTPException, Member, Message, NotFound, TextChannel, VoiceState from discord.ext.commands import Cog from discord.utils import escape_markdown @@ -207,6 +207,12 @@ class Filtering(Cog): delta = relativedelta(after.edited_at, before.edited_at).microseconds await self._filter_message(after, delta) + @Cog.listener() + async def on_voice_state_update(self, member: Member, before: VoiceState, after: VoiceState): + """When a member initially joins a voice channel or switches to a new one, check for a bad name in username.""" + if after.channel and not before.channel: + await self.check_bad_words_in_name(member) + def get_name_match(self, name: str) -> Optional[re.Match]: """Check bad words from passed string (name). Return the first match found.""" normalised_name = unicodedata.normalize("NFKC", name) -- cgit v1.2.3 From a350a90c4cc1fba003eb07d6269a57e02708c240 Mon Sep 17 00:00:00 2001 From: GDWR Date: Tue, 1 Feb 2022 19:24:28 +0000 Subject: ♻️Import errors from `discord` explicitly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/exts/filters/filtering.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bot/exts/filters/filtering.py b/bot/exts/filters/filtering.py index 7b708f9a9..f16e2af02 100644 --- a/bot/exts/filters/filtering.py +++ b/bot/exts/filters/filtering.py @@ -6,13 +6,13 @@ from typing import Any, Dict, List, Mapping, NamedTuple, Optional, Tuple, Union import arrow import dateutil.parser -import discord.errors +import discord import regex import tldextract from async_rediscache import RedisCache from botcore.regex import DISCORD_INVITE from dateutil.relativedelta import relativedelta -from discord import Colour, HTTPException, Member, Message, NotFound, TextChannel, VoiceState +from discord import Colour, HTTPException, Member, Message, NotFound, TextChannel, VoiceState, Forbidden from discord.ext.commands import Cog from discord.utils import escape_markdown @@ -360,7 +360,7 @@ class Filtering(Cog): # 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: + except NotFound: return # Notify the user if the filter specifies @@ -664,7 +664,7 @@ class Filtering(Cog): """ try: await filtered_member.send(reason) - except discord.errors.Forbidden: + except Forbidden: await channel.send(f"{filtered_member.mention} {reason}") def schedule_msg_delete(self, msg: dict) -> None: -- cgit v1.2.3 From ab6579caf693a537818ea8c173efe3d1821027ad Mon Sep 17 00:00:00 2001 From: GDWR Date: Tue, 1 Feb 2022 19:29:43 +0000 Subject: 🚨 Reorder imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/exts/filters/filtering.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/filters/filtering.py b/bot/exts/filters/filtering.py index f16e2af02..593d4b7bb 100644 --- a/bot/exts/filters/filtering.py +++ b/bot/exts/filters/filtering.py @@ -12,7 +12,7 @@ import tldextract from async_rediscache import RedisCache from botcore.regex import DISCORD_INVITE from dateutil.relativedelta import relativedelta -from discord import Colour, HTTPException, Member, Message, NotFound, TextChannel, VoiceState, Forbidden +from discord import Colour, Forbidden, HTTPException, Member, Message, NotFound, TextChannel, VoiceState from discord.ext.commands import Cog from discord.utils import escape_markdown -- cgit v1.2.3 From fdb702d3e186a6d5020c9b3cd32c2f0588542c56 Mon Sep 17 00:00:00 2001 From: GDWR Date: Tue, 1 Feb 2022 19:30:08 +0000 Subject: 🚨 Make docstring more concise MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/exts/filters/filtering.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/filters/filtering.py b/bot/exts/filters/filtering.py index 593d4b7bb..6c70ab397 100644 --- a/bot/exts/filters/filtering.py +++ b/bot/exts/filters/filtering.py @@ -208,8 +208,8 @@ class Filtering(Cog): await self._filter_message(after, delta) @Cog.listener() - async def on_voice_state_update(self, member: Member, before: VoiceState, after: VoiceState): - """When a member initially joins a voice channel or switches to a new one, check for a bad name in username.""" + async def on_voice_state_update(self, member: Member, before: VoiceState, after: VoiceState) -> None: + """Checks for bad words in usernames when users join or change voice channels.""" if after.channel and not before.channel: await self.check_bad_words_in_name(member) -- cgit v1.2.3 From f68b27768db44cabbc2ae4e66a42fa040a937958 Mon Sep 17 00:00:00 2001 From: GDWR Date: Tue, 1 Feb 2022 20:56:14 +0000 Subject: 💡 Correct docstring to explain functionality MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/exts/filters/filtering.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/filters/filtering.py b/bot/exts/filters/filtering.py index 6c70ab397..5ea18d8f1 100644 --- a/bot/exts/filters/filtering.py +++ b/bot/exts/filters/filtering.py @@ -209,7 +209,7 @@ class Filtering(Cog): @Cog.listener() async def on_voice_state_update(self, member: Member, before: VoiceState, after: VoiceState) -> None: - """Checks for bad words in usernames when users join or change voice channels.""" + """Checks for bad words in usernames when users initially joins a voice channel.""" if after.channel and not before.channel: await self.check_bad_words_in_name(member) -- cgit v1.2.3 From 2fc4f53bd7c3c669fc744ca307163d5c59eaa8a0 Mon Sep 17 00:00:00 2001 From: GDWR Date: Wed, 2 Feb 2022 20:07:20 +0000 Subject: ♻️Remove `import discord` in favour of using `from discord` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/exts/filters/filtering.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/bot/exts/filters/filtering.py b/bot/exts/filters/filtering.py index 5ea18d8f1..983c2a56c 100644 --- a/bot/exts/filters/filtering.py +++ b/bot/exts/filters/filtering.py @@ -6,13 +6,14 @@ from typing import Any, Dict, List, Mapping, NamedTuple, Optional, Tuple, Union import arrow import dateutil.parser -import discord import regex import tldextract from async_rediscache import RedisCache from botcore.regex import DISCORD_INVITE from dateutil.relativedelta import relativedelta -from discord import Colour, Forbidden, HTTPException, Member, Message, NotFound, TextChannel, VoiceState +from discord import ( + ChannelType, Colour, Embed, Forbidden, HTTPException, Member, Message, NotFound, TextChannel, VoiceState +) from discord.ext.commands import Cog from discord.utils import escape_markdown @@ -63,14 +64,14 @@ AUTO_BAN_REASON = ( ) AUTO_BAN_DURATION = timedelta(days=4) -FilterMatch = Union[re.Match, dict, bool, List[discord.Embed]] +FilterMatch = Union[re.Match, dict, bool, List[Embed]] class Stats(NamedTuple): """Additional stats on a triggered filter to append to a mod log.""" message_content: str - additional_embeds: Optional[List[discord.Embed]] + additional_embeds: Optional[List[Embed]] class Filtering(Cog): @@ -345,7 +346,7 @@ class Filtering(Cog): match = result if match: - is_private = msg.channel.type is discord.ChannelType.private + is_private = msg.channel.type is ChannelType.private # If this is a filter (not a watchlist) and not in a DM, delete the message. if _filter["type"] == "filter" and not is_private: @@ -415,14 +416,14 @@ class Filtering(Cog): self, filter_name: str, _filter: Dict[str, Any], - msg: discord.Message, + msg: Message, stats: Stats, reason: Optional[str] = None, *, is_eval: bool = False, ) -> None: """Send a mod log for a triggered filter.""" - if msg.channel.type is discord.ChannelType.private: + if msg.channel.type is ChannelType.private: channel_str = "via DM" ping_everyone = False else: @@ -480,7 +481,7 @@ class Filtering(Cog): additional_embeds = [] for _, data in match.items(): reason = f"Reason: {data['reason']} | " if data.get('reason') else "" - embed = discord.Embed(description=( + embed = Embed(description=( f"**Members:**\n{data['members']}\n" f"**Active:**\n{data['active']}" )) @@ -628,7 +629,7 @@ class Filtering(Cog): return invite_data if invite_data else False @staticmethod - async def _has_rich_embed(msg: Message) -> Union[bool, List[discord.Embed]]: + async def _has_rich_embed(msg: Message) -> Union[bool, List[Embed]]: """Determines if `msg` contains any rich embeds not auto-generated from a URL.""" if msg.embeds: for embed in msg.embeds: -- cgit v1.2.3 From 6e696174412371f48b8404d5dc303fe57c62c548 Mon Sep 17 00:00:00 2001 From: GDWR Date: Mon, 14 Feb 2022 00:40:40 +0000 Subject: 👌 Run bad word check on all voice state updates. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/exts/filters/filtering.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bot/exts/filters/filtering.py b/bot/exts/filters/filtering.py index 983c2a56c..ae4ce5343 100644 --- a/bot/exts/filters/filtering.py +++ b/bot/exts/filters/filtering.py @@ -209,10 +209,9 @@ class Filtering(Cog): await self._filter_message(after, delta) @Cog.listener() - async def on_voice_state_update(self, member: Member, before: VoiceState, after: VoiceState) -> None: - """Checks for bad words in usernames when users initially joins a voice channel.""" - if after.channel and not before.channel: - await self.check_bad_words_in_name(member) + async def on_voice_state_update(self, member: Member, *_) -> None: + """Checks for bad words in usernames when users join, switch or leave a voice channel.""" + await self.check_bad_words_in_name(member) def get_name_match(self, name: str) -> Optional[re.Match]: """Check bad words from passed string (name). Return the first match found.""" -- cgit v1.2.3 From f8b5ef489b971224872a11e7a43f0b041192e336 Mon Sep 17 00:00:00 2001 From: GDWR Date: Mon, 14 Feb 2022 00:49:58 +0000 Subject: 🚨 Remove unused imported MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/exts/filters/filtering.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bot/exts/filters/filtering.py b/bot/exts/filters/filtering.py index ae4ce5343..73962a667 100644 --- a/bot/exts/filters/filtering.py +++ b/bot/exts/filters/filtering.py @@ -11,9 +11,7 @@ import tldextract from async_rediscache import RedisCache from botcore.regex import DISCORD_INVITE from dateutil.relativedelta import relativedelta -from discord import ( - ChannelType, Colour, Embed, Forbidden, HTTPException, Member, Message, NotFound, TextChannel, VoiceState -) +from discord import ChannelType, Colour, Embed, Forbidden, HTTPException, Member, Message, NotFound, TextChannel from discord.ext.commands import Cog from discord.utils import escape_markdown -- cgit v1.2.3