Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions bot/exts/moderation/modlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,19 +525,30 @@ def is_message_blacklisted(self, message: Message) -> bool:
if message.author.bot or not message.guild:
return True

return self.is_raw_message_blacklisted(message.guild.id, message.channel.id)
return self.is_channel_ignored(message.channel.id)

def is_raw_message_blacklisted(self, guild_id: t.Optional[int], channel_id: int) -> bool:
"""Return true if the message constructed from raw parameter is in a blacklisted thread or channel."""
# Ignore DMs or messages outside of the main guild
if not guild_id or guild_id != GuildConstant.id:
return True
def is_channel_ignored(self, channel_id: int) -> bool:
"""
Return true if the channel, or parent channel in the case of threads, passed should be ignored by modlog.
Comment thread
Xithrius marked this conversation as resolved.

Currently ignored channels are:
1. Channels not in the guild we care about (constants.Guild.id).
2. Channels that mods do not have view permissions to
3. Channels in constants.Guild.modlog_blacklist
"""
channel = self.bot.get_channel(channel_id)

# Look at the parent channel of a thread
# Ignore not found channels, DMs, and messages outside of the main guild.
if not channel or channel.guild and channel.guild.id != GuildConstant.id:
return True

# Look at the parent channel of a thread.
if isinstance(channel, Thread):
return channel.parent.id in GuildConstant.modlog_blacklist
channel = channel.parent

# Mod team doesn't have view permission to the channel.
if not channel.permissions_for(channel.guild.get_role(Roles.mod_team)).view_channel:
return True

return channel.id in GuildConstant.modlog_blacklist

Expand Down Expand Up @@ -602,7 +613,7 @@ async def on_message_delete(self, message: discord.Message) -> None:
@Cog.listener()
async def on_raw_message_delete(self, event: discord.RawMessageDeleteEvent) -> None:
"""Log raw message delete event to message change log."""
if self.is_raw_message_blacklisted(event.guild_id, event.channel_id):
if self.is_channel_ignored(event.channel_id):
return

await asyncio.sleep(1) # Wait here in case the normal event was fired
Expand Down Expand Up @@ -827,7 +838,8 @@ async def on_voice_state_update(
"""Log member voice state changes to the voice log channel."""
if (
member.guild.id != GuildConstant.id
or (before.channel and before.channel.id in GuildConstant.modlog_blacklist)
or (before.channel and self.is_channel_ignored(before.channel.id))
or (after.channel and self.is_channel_ignored(after.channel.id))
):
return

Expand Down
6 changes: 2 additions & 4 deletions config-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,13 @@ guild:
- *ADMIN_SPAM
- *MODS

# Modlog cog ignores events which occur in these channels
# Modlog cog explicitly ignores events which occur in these channels.
# This is on top of implicitly ignoring events in channels that the mod team cannot view.
modlog_blacklist:
- *ADMINS
- *ADMINS_VOICE
- *ATTACH_LOG
- *MESSAGE_LOG
- *MOD_LOG
- *STAFF_VOICE
- *DEV_CORE_VOTING

reminder_whitelist:
- *BOT_CMD
Expand Down