diff options
| -rw-r--r-- | bot/exts/info/information.py | 21 | ||||
| -rw-r--r-- | bot/utils/channel.py | 16 | 
2 files changed, 19 insertions, 18 deletions
diff --git a/bot/exts/info/information.py b/bot/exts/info/information.py index 73a377bf0..c20dfc6f0 100644 --- a/bot/exts/info/information.py +++ b/bot/exts/info/information.py @@ -5,8 +5,7 @@ import textwrap  from collections import defaultdict  from typing import Any, DefaultDict, Dict, Mapping, Optional, Tuple, Union -from discord import ChannelType, Colour, Embed, Guild, Message, Role, utils -from discord.abc import GuildChannel +from discord import Colour, Embed, Guild, Message, Role, utils  from discord.ext.commands import BucketType, Cog, Context, Paginator, command, group, has_any_role  from bot import constants @@ -15,7 +14,7 @@ from bot.bot import Bot  from bot.converters import FetchedMember  from bot.decorators import in_whitelist  from bot.pagination import LinePaginator -from bot.utils.channel import is_mod_channel +from bot.utils.channel import is_mod_channel, is_staff_channel  from bot.utils.checks import cooldown_with_role_bypass, has_no_roles_check, in_whitelist_check  from bot.utils.time import time_since @@ -29,26 +28,12 @@ class Information(Cog):          self.bot = bot      @staticmethod -    def is_staff_channel(guild: Guild, channel: GuildChannel) -> bool: -        """Determines if a given channel is staff-only.""" -        if channel.type is ChannelType.category: -            return False - -        # Channel is staff-only if staff have explicit read allow perms -        # and @everyone has explicit read deny perms -        return any( -            channel.overwrites_for(guild.get_role(staff_role)).read_messages is True -            and channel.overwrites_for(guild.default_role).read_messages is False -            for staff_role in constants.STAFF_ROLES -        ) - -    @staticmethod      def get_channel_type_counts(guild: Guild) -> DefaultDict[str, int]:          """Return the total amounts of the various types of channels in `guild`."""          channel_counter = defaultdict(int)          for channel in guild.channels: -            if Information.is_staff_channel(guild, channel): +            if is_staff_channel(channel):                  channel_counter["staff"] += 1              else:                  channel_counter[str(channel.type)] += 1 diff --git a/bot/utils/channel.py b/bot/utils/channel.py index 0c072184c..72603c521 100644 --- a/bot/utils/channel.py +++ b/bot/utils/channel.py @@ -32,6 +32,22 @@ def is_mod_channel(channel: discord.TextChannel) -> bool:          return False +def is_staff_channel(channel: discord.TextChannel) -> bool: +    """True if `channel` is considered a staff channel.""" +    guild = bot.instance.get_guild(constants.Guild.id) + +    if channel.type is discord.ChannelType.category: +        return False + +    # Channel is staff-only if staff have explicit read allow perms +    # and @everyone has explicit read deny perms +    return any( +        channel.overwrites_for(guild.get_role(staff_role)).read_messages is True +        and channel.overwrites_for(guild.default_role).read_messages is False +        for staff_role in constants.STAFF_ROLES +    ) + +  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  |