diff options
Diffstat (limited to '')
| -rw-r--r-- | bot/constants.py | 4 | ||||
| -rw-r--r-- | bot/exts/info/information.py | 9 | ||||
| -rw-r--r-- | bot/exts/moderation/infraction/_scheduler.py | 9 | ||||
| -rw-r--r-- | bot/exts/moderation/infraction/management.py | 10 | ||||
| -rw-r--r-- | bot/utils/channel.py | 16 | ||||
| -rw-r--r-- | config-default.yml | 10 | 
6 files changed, 34 insertions, 24 deletions
diff --git a/bot/constants.py b/bot/constants.py index c79de012c..b615dcd19 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -471,6 +471,7 @@ class Guild(metaclass=YAMLGetter):      id: int      invite: str  # Discord invite, gets embedded in chat      moderation_channels: List[int] +    moderation_categories: List[int]      moderation_roles: List[int]      modlog_blacklist: List[int]      reminder_whitelist: List[int] @@ -639,6 +640,9 @@ STAFF_ROLES = Guild.staff_roles  # Channel combinations  MODERATION_CHANNELS = Guild.moderation_channels +# Category combinations +MODERATION_CATEGORIES = Guild.moderation_categories +  # Bot replies  NEGATIVE_REPLIES = [      "Noooooo!!", 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 bba80afaf..bebade0ae 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,11 +137,7 @@ class InfractionScheduler:              )              if reason:                  end_msg = f" (reason: {textwrap.shorten(reason, width=1500, placeholder='...')})" -        elif ctx.channel.id not in MODERATION_CHANNELS: -            log.trace( -                f"Infraction #{id_} context is not in a mod channel; omitting infraction count and id." -            ) -        else: +        elif is_mod_channel(ctx.channel):              log.trace(f"Fetching total infraction count for {user}.")              infractions = await self.bot.api_client.get( 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..6bf70bfde 100644 --- a/bot/utils/channel.py +++ b/bot/utils/channel.py @@ -2,6 +2,7 @@ import logging  import discord +from bot import constants  from bot.constants import Categories  log = logging.getLogger(__name__) @@ -15,6 +16,21 @@ 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: +    """True if `channel` is considered a mod channel.""" +    if channel.id in constants.MODERATION_CHANNELS: +        log.trace(f"Channel #{channel} is a configured mod channel") +        return True + +    elif any(is_in_category(channel, category) for category in constants.MODERATION_CATEGORIES): +        log.trace(f"Channel #{channel} is in a configured mod category") +        return True + +    else: +        log.trace(f"Channel #{channel} is not a mod channel") +        return False + +  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 c712d1eb7..71d4419a7 100644 --- a/config-default.yml +++ b/config-default.yml @@ -128,7 +128,8 @@ guild:          help_available:                     691405807388196926          help_in_use:                        696958401460043776          help_dormant:                       691405908919451718 -        modmail:                            714494672835444826 +        modmail:            &MODMAIL        714494672835444826 +        logs:               &LOGS           468520609152892958      channels:          # Public announcement and news channels @@ -180,7 +181,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 @@ -201,10 +202,13 @@ guild:          big_brother_logs:   &BB_LOGS        468507907357409333          talent_pool:        &TALENT_POOL    534321732593647616 +    moderation_categories: +        - *MODMAIL +        - *LOGS +      moderation_channels:          - *ADMINS          - *ADMIN_SPAM -        - *MOD_ALERTS          - *MODS          - *MOD_SPAM  |