aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar mbaruh <[email protected]>2020-10-17 16:01:28 +0300
committerGravatar mbaruh <[email protected]>2020-10-17 16:01:28 +0300
commit7c5c8fa776e351263ecf6aa24f3d69570443b622 (patch)
tree69a0aff118e3dc15bbae2d4ff260219e9cfc9250
parentPR #1157 Reddit: filter NSFW posts (diff)
Centralize moderation channel checks
-rw-r--r--bot/exts/info/information.py9
-rw-r--r--bot/exts/moderation/infraction/_scheduler.py5
-rw-r--r--bot/exts/moderation/infraction/management.py10
-rw-r--r--bot/utils/channel.py10
-rw-r--r--config-default.yml4
5 files changed, 18 insertions, 20 deletions
diff --git a/bot/exts/info/information.py b/bot/exts/info/information.py
index 0f50138e7..2d9cab94b 100644
--- a/bot/exts/info/information.py
+++ b/bot/exts/info/information.py
@@ -14,6 +14,7 @@ from bot import constants
from bot.bot import Bot
from bot.decorators import in_whitelist
from bot.pagination import LinePaginator
+from bot.utils.channel import is_mod_channel
from bot.utils.checks import cooldown_with_role_bypass, has_no_roles_check, in_whitelist_check
from bot.utils.time import time_since
@@ -241,14 +242,8 @@ class Information(Cog):
),
]
- # Use getattr to future-proof for commands invoked via DMs.
- show_verbose = (
- ctx.channel.id in constants.MODERATION_CHANNELS
- or getattr(ctx.channel, "category_id", None) == constants.Categories.modmail
- )
-
# Show more verbose output in moderation channels for infractions and nominations
- if show_verbose:
+ if is_mod_channel(ctx.channel):
fields.append(await self.expanded_user_infraction_counts(user))
fields.append(await self.user_nomination_counts(user))
else:
diff --git a/bot/exts/moderation/infraction/_scheduler.py b/bot/exts/moderation/infraction/_scheduler.py
index 814b17830..12d831453 100644
--- a/bot/exts/moderation/infraction/_scheduler.py
+++ b/bot/exts/moderation/infraction/_scheduler.py
@@ -12,11 +12,12 @@ from discord.ext.commands import Context
from bot import constants
from bot.api import ResponseCodeError
from bot.bot import Bot
-from bot.constants import Colours, MODERATION_CHANNELS
+from bot.constants import Colours
from bot.exts.moderation.infraction import _utils
from bot.exts.moderation.infraction._utils import UserSnowflake
from bot.exts.moderation.modlog import ModLog
from bot.utils import messages, scheduling, time
+from bot.utils.channel import is_mod_channel
log = logging.getLogger(__name__)
@@ -136,7 +137,7 @@ class InfractionScheduler:
)
if reason:
end_msg = f" (reason: {textwrap.shorten(reason, width=1500, placeholder='...')})"
- elif ctx.channel.id not in MODERATION_CHANNELS:
+ elif not is_mod_channel(ctx.channel):
log.trace(
f"Infraction #{id_} context is not in a mod channel; omitting infraction count."
)
diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py
index cdab1a6c7..394f63da3 100644
--- a/bot/exts/moderation/infraction/management.py
+++ b/bot/exts/moderation/infraction/management.py
@@ -15,7 +15,7 @@ from bot.exts.moderation.infraction.infractions import Infractions
from bot.exts.moderation.modlog import ModLog
from bot.pagination import LinePaginator
from bot.utils import messages, time
-from bot.utils.checks import in_whitelist_check
+from bot.utils.channel import is_mod_channel
log = logging.getLogger(__name__)
@@ -295,13 +295,7 @@ class ModManagement(commands.Cog):
"""Only allow moderators inside moderator channels to invoke the commands in this cog."""
checks = [
await commands.has_any_role(*constants.MODERATION_ROLES).predicate(ctx),
- in_whitelist_check(
- ctx,
- channels=constants.MODERATION_CHANNELS,
- categories=[constants.Categories.modmail],
- redirect=None,
- fail_silently=True,
- )
+ is_mod_channel(ctx.channel)
]
return all(checks)
diff --git a/bot/utils/channel.py b/bot/utils/channel.py
index 851f9e1fe..d55faab57 100644
--- a/bot/utils/channel.py
+++ b/bot/utils/channel.py
@@ -2,7 +2,7 @@ import logging
import discord
-from bot.constants import Categories
+from bot.constants import Categories, MODERATION_CHANNELS
log = logging.getLogger(__name__)
@@ -15,6 +15,14 @@ def is_help_channel(channel: discord.TextChannel) -> bool:
return any(is_in_category(channel, category) for category in categories)
+def is_mod_channel(channel: discord.TextChannel) -> bool:
+ """Return True if `channel` is one of the moderation channels or in one of the moderation categories."""
+ log.trace(f"Checking if #{channel} is a mod channel.")
+ categories = (Categories.modmail, Categories.logs)
+
+ return channel.id in MODERATION_CHANNELS or any(is_in_category(channel, category) for category in categories)
+
+
def is_in_category(channel: discord.TextChannel, category_id: int) -> bool:
"""Return True if `channel` is within a category with `category_id`."""
return getattr(channel, "category_id", None) == category_id
diff --git a/config-default.yml b/config-default.yml
index c93ab9e0c..12f6582ec 100644
--- a/config-default.yml
+++ b/config-default.yml
@@ -129,6 +129,7 @@ guild:
help_in_use: 696958401460043776
help_dormant: 691405908919451718
modmail: 714494672835444826
+ logs: 468520609152892958
channels:
# Public announcement and news channels
@@ -179,7 +180,7 @@ guild:
incidents: 714214212200562749
incidents_archive: 720668923636351037
mods: &MODS 305126844661760000
- mod_alerts: &MOD_ALERTS 473092532147060736
+ mod_alerts: 473092532147060736
mod_spam: &MOD_SPAM 620607373828030464
organisation: &ORGANISATION 551789653284356126
staff_lounge: &STAFF_LOUNGE 464905259261755392
@@ -202,7 +203,6 @@ guild:
moderation_channels:
- *ADMINS
- *ADMIN_SPAM
- - *MOD_ALERTS
- *MODS
- *MOD_SPAM