aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2021-10-14 16:28:59 +0100
committerGravatar Chris Lovering <[email protected]>2021-10-17 09:55:44 +0100
commit1a1d7c79b06ed52616b5f681270cd2238b32e792 (patch)
tree407d3a24cd97c2a08d0d6189aa015826f5770012
parentModlog: remove tzinfo from member_join (#1877) (diff)
Ignore channels mod team can't view in modlog
The main purpose of this is so that we don't need to keep adding to the modlog_blacklist for every new channel we want to ignore, since it now implicitly ignores channels mods don't have read perms to. This is done by making use of Discord.py 2.0's updated behaviour of Channel.permissions_for() where it can now accept a role and determines the permissions of users in that role for a given channel. This takes into account default permissions as well as channel overrides. Co-authored-by: Xithrius <[email protected]>
-rw-r--r--bot/exts/moderation/modlog.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/bot/exts/moderation/modlog.py b/bot/exts/moderation/modlog.py
index 3e19083ac..375956dd3 100644
--- a/bot/exts/moderation/modlog.py
+++ b/bot/exts/moderation/modlog.py
@@ -527,17 +527,28 @@ class ModLog(Cog, name="ModLog"):
return self.is_raw_message_blacklisted(message.guild.id, 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_raw_message_blacklisted(self, channel_id: int) -> bool:
+ """
+ Return true if the channel, or parent channel in the case of threads, passed should be ignored by modlog.
+
+ 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