diff options
-rw-r--r-- | bot/cogs/moderation/management.py | 10 | ||||
-rw-r--r-- | bot/constants.py | 6 | ||||
-rw-r--r-- | bot/utils/checks.py | 6 | ||||
-rw-r--r-- | config-default.yml | 3 | ||||
-rw-r--r-- | tests/utils/test_checks.py | 0 |
5 files changed, 19 insertions, 6 deletions
diff --git a/bot/cogs/moderation/management.py b/bot/cogs/moderation/management.py index 491f6d400..44a508436 100644 --- a/bot/cogs/moderation/management.py +++ b/bot/cogs/moderation/management.py @@ -11,7 +11,7 @@ from bot import constants from bot.converters import InfractionSearchQuery from bot.pagination import LinePaginator from bot.utils import time -from bot.utils.checks import with_role_check +from bot.utils.checks import in_channel_check, with_role_check from . import utils from .infractions import Infractions from .modlog import ModLog @@ -256,8 +256,12 @@ class ModManagement(commands.Cog): # This cannot be static (must have a __func__ attribute). def cog_check(self, ctx: Context) -> bool: - """Only allow moderators to invoke the commands in this cog.""" - return with_role_check(ctx, *constants.MODERATION_ROLES) + """Only allow moderators from moderator channels to invoke the commands in this cog.""" + checks = [ + with_role_check(ctx, *constants.MODERATION_ROLES), + in_channel_check(ctx, *constants.MODERATION_CHANNELS) + ] + return all(checks) # This cannot be static (must have a __func__ attribute). async def cog_command_error(self, ctx: Context, error: Exception) -> None: diff --git a/bot/constants.py b/bot/constants.py index 4beae84e9..1efad8d92 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -328,6 +328,7 @@ class Channels(metaclass=YAMLGetter): subsection = "channels" admins: int + admin_spam: int announcements: int big_brother_logs: int bot: int @@ -348,6 +349,8 @@ class Channels(metaclass=YAMLGetter): meta: int mod_alerts: int modlog: int + mods: int + mod_spam: int off_topic_0: int off_topic_1: int off_topic_2: int @@ -507,6 +510,9 @@ PROJECT_ROOT = os.path.abspath(os.path.join(BOT_DIR, os.pardir)) MODERATION_ROLES = Roles.moderator, Roles.admin, Roles.owner STAFF_ROLES = Roles.helpers, Roles.moderator, Roles.admin, Roles.owner +# Default Channel combinations +MODERATION_CHANNELS = Channels.admins, Channels.admin_spam, Channels.mod_alerts, Channels.mods, Channels.mod_spam + # Bot replies NEGATIVE_REPLIES = [ diff --git a/bot/utils/checks.py b/bot/utils/checks.py index ad892e512..db56c347c 100644 --- a/bot/utils/checks.py +++ b/bot/utils/checks.py @@ -38,9 +38,9 @@ def without_role_check(ctx: Context, *role_ids: int) -> bool: return check -def in_channel_check(ctx: Context, channel_id: int) -> bool: - """Checks if the command was executed inside of the specified channel.""" - check = ctx.channel.id == channel_id +def in_channel_check(ctx: Context, *channel_ids: int) -> bool: + """Checks if the command was executed inside the list of specified channels.""" + check = ctx.channel.id in channel_ids log.trace(f"{ctx.author} tried to call the '{ctx.command.name}' command. " f"The result of the in_channel check was {check}.") return check diff --git a/config-default.yml b/config-default.yml index 197743296..af024e5de 100644 --- a/config-default.yml +++ b/config-default.yml @@ -90,6 +90,7 @@ guild: channels: admins: &ADMINS 365960823622991872 + admin_spam: 563594791770914816 announcements: 354619224620138496 big_brother_logs: &BBLOGS 468507907357409333 bot: 267659945086812160 @@ -110,6 +111,8 @@ guild: meta: 429409067623251969 mod_alerts: 473092532147060736 modlog: &MODLOG 282638479504965634 + mods: 305126844661760000 + mod_spam: 620607373828030464 off_topic_0: 291284109232308226 off_topic_1: 463035241142026251 off_topic_2: 463035268514185226 diff --git a/tests/utils/test_checks.py b/tests/utils/test_checks.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/utils/test_checks.py |