From 11d00e7f846748fb87f02b5f0bfecc92feac198c Mon Sep 17 00:00:00 2001 From: Izan Date: Fri, 8 Oct 2021 14:45:02 +0100 Subject: Rename `Roles.moderator` to `Roles.moderation_team` --- bot/constants.py | 4 ++-- bot/exts/fun/snakes/_utils.py | 2 +- bot/exts/fun/trivia_quiz.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'bot') diff --git a/bot/constants.py b/bot/constants.py index 6e45632f..c5443393 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -332,8 +332,8 @@ class Reddit: # Default role combinations -MODERATION_ROLES = Roles.moderator, Roles.admin, Roles.owner -STAFF_ROLES = Roles.helpers, Roles.moderator, Roles.admin, Roles.owner +MODERATION_ROLES = Roles.moderation_team, Roles.admin, Roles.owner +STAFF_ROLES = Roles.helpers, Roles.moderation_team, Roles.admin, Roles.owner # Whitelisted channels WHITELISTED_CHANNELS = ( diff --git a/bot/exts/fun/snakes/_utils.py b/bot/exts/fun/snakes/_utils.py index de51339d..46834c2c 100644 --- a/bot/exts/fun/snakes/_utils.py +++ b/bot/exts/fun/snakes/_utils.py @@ -718,4 +718,4 @@ class SnakeAndLaddersGame: @staticmethod def _is_moderator(user: Member) -> bool: """Return True if the user is a Moderator.""" - return any(Roles.moderator == role.id for role in user.roles) + return any(Roles.moderation_team == role.id for role in user.roles) diff --git a/bot/exts/fun/trivia_quiz.py b/bot/exts/fun/trivia_quiz.py index 712c8a12..60afbb06 100644 --- a/bot/exts/fun/trivia_quiz.py +++ b/bot/exts/fun/trivia_quiz.py @@ -550,7 +550,7 @@ class TriviaQuiz(commands.Cog): if self.game_status[ctx.channel.id]: # Check if the author is the game starter or a moderator. if ctx.author == self.game_owners[ctx.channel.id] or any( - Roles.moderator == role.id for role in ctx.author.roles + Roles.moderation_team == role.id for role in ctx.author.roles ): self.game_status[ctx.channel.id] = False del self.game_owners[ctx.channel.id] -- cgit v1.2.3 From 71d800add94df3d678786ab482747ae904290129 Mon Sep 17 00:00:00 2001 From: Izan Date: Fri, 8 Oct 2021 15:04:35 +0100 Subject: Rename `Roles.admin` to `Roles.admins` --- bot/constants.py | 10 +++++----- bot/exts/core/internal_eval/_internal_eval.py | 6 +++--- bot/exts/events/advent_of_code/_cog.py | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'bot') diff --git a/bot/constants.py b/bot/constants.py index c5443393..92b40914 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -280,9 +280,9 @@ if Client.month_override is not None: class Roles(NamedTuple): - owner = 267627879762755584 - admin = int(environ.get("BOT_ADMIN_ROLE_ID", 267628507062992896)) - moderator = 267629731250176001 + owners = 267627879762755584 + admins = int(environ.get("BOT_ADMIN_ROLE_ID", 267628507062992896)) + moderation_team = 267629731250176001 helpers = int(environ.get("ROLE_HELPERS", 267630620367257601)) core_developers = 587606783669829632 everyone = int(environ.get("BOT_GUILD", 267624335836053506)) @@ -332,8 +332,8 @@ class Reddit: # Default role combinations -MODERATION_ROLES = Roles.moderation_team, Roles.admin, Roles.owner -STAFF_ROLES = Roles.helpers, Roles.moderation_team, Roles.admin, Roles.owner +MODERATION_ROLES = Roles.moderation_team, Roles.admins, Roles.owner +STAFF_ROLES = Roles.helpers, Roles.moderation_team, Roles.admins, Roles.owner # Whitelisted channels WHITELISTED_CHANNELS = ( diff --git a/bot/exts/core/internal_eval/_internal_eval.py b/bot/exts/core/internal_eval/_internal_eval.py index 4f6b4321..47e564a5 100644 --- a/bot/exts/core/internal_eval/_internal_eval.py +++ b/bot/exts/core/internal_eval/_internal_eval.py @@ -146,14 +146,14 @@ class InternalEval(commands.Cog): await self._send_output(ctx, eval_context.format_output()) @commands.group(name="internal", aliases=("int",)) - @with_role(Roles.admin) + @with_role(Roles.admins) async def internal_group(self, ctx: commands.Context) -> None: """Internal commands. Top secret!""" if not ctx.invoked_subcommand: await invoke_help_command(ctx) @internal_group.command(name="eval", aliases=("e",)) - @with_role(Roles.admin) + @with_role(Roles.admins) async def eval(self, ctx: commands.Context, *, code: str) -> None: """Run eval in a REPL-like format.""" if match := list(FORMATTED_CODE_REGEX.finditer(code)): @@ -172,7 +172,7 @@ class InternalEval(commands.Cog): await self._eval(ctx, code) @internal_group.command(name="reset", aliases=("clear", "exit", "r", "c")) - @with_role(Roles.admin) + @with_role(Roles.admins) async def reset(self, ctx: commands.Context) -> None: """Reset the context and locals of the eval session.""" self.locals = {} diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index ca60e517..4d811fa4 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -251,7 +251,7 @@ class AdventOfCode(commands.Cog): info_embed = _helpers.get_summary_embed(leaderboard) await ctx.send(f"```\n{table}\n```", embed=info_embed) - @with_role(Roles.admin) + @with_role(Roles.admins) @adventofcode_group.command( name="refresh", aliases=("fetch",), -- cgit v1.2.3 From dc5f73be8c18ef11c701822e8c600c8fca7b149c Mon Sep 17 00:00:00 2001 From: Izan Date: Fri, 8 Oct 2021 15:06:07 +0100 Subject: Rename `Roles.owner` to `Roles.owners` --- bot/constants.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/constants.py b/bot/constants.py index 92b40914..b4191c5e 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -332,8 +332,8 @@ class Reddit: # Default role combinations -MODERATION_ROLES = Roles.moderation_team, Roles.admins, Roles.owner -STAFF_ROLES = Roles.helpers, Roles.moderation_team, Roles.admins, Roles.owner +MODERATION_ROLES = Roles.moderation_team, Roles.admins, Roles.owners +STAFF_ROLES = Roles.helpers, Roles.moderation_team, Roles.admins, Roles.owners # Whitelisted channels WHITELISTED_CHANNELS = ( -- cgit v1.2.3 From e2da188b554aba07b6c5a7a25b8af0baa74973cb Mon Sep 17 00:00:00 2001 From: Izan Date: Sat, 9 Oct 2021 21:20:46 +0100 Subject: Check role id in MODERATION_ROLES instead of comparing to moderation_team and safeguard `.roles` attribute --- bot/exts/fun/snakes/_utils.py | 25 +++++++++++++------------ bot/exts/fun/trivia_quiz.py | 4 ++-- 2 files changed, 15 insertions(+), 14 deletions(-) (limited to 'bot') diff --git a/bot/exts/fun/snakes/_utils.py b/bot/exts/fun/snakes/_utils.py index 46834c2c..182fa9d9 100644 --- a/bot/exts/fun/snakes/_utils.py +++ b/bot/exts/fun/snakes/_utils.py @@ -6,13 +6,14 @@ import math import random from itertools import product from pathlib import Path +from typing import Union from PIL import Image from PIL.ImageDraw import ImageDraw -from discord import File, Member, Reaction +from discord import File, Member, Reaction, User from discord.ext.commands import Cog, Context -from bot.constants import Roles +from bot.constants import MODERATION_ROLES SNAKE_RESOURCES = Path("bot/resources/fun/snakes").absolute() @@ -395,7 +396,7 @@ class SnakeAndLaddersGame: Listen for reactions until players have joined, and the game has been started. """ - def startup_event_check(reaction_: Reaction, user_: Member) -> bool: + def startup_event_check(reaction_: Reaction, user_: Union[User, Member]) -> bool: """Make sure that this reaction is what we want to operate on.""" return ( all(( @@ -460,7 +461,7 @@ class SnakeAndLaddersGame: await self.cancel_game() return # We're done, no reactions for the last 5 minutes - async def _add_player(self, user: Member) -> None: + async def _add_player(self, user: Union[User, Member]) -> None: """Add player to game.""" self.players.append(user) self.player_tiles[user.id] = 1 @@ -469,7 +470,7 @@ class SnakeAndLaddersGame: im = Image.open(io.BytesIO(avatar_bytes)).resize((BOARD_PLAYER_SIZE, BOARD_PLAYER_SIZE)) self.avatar_images[user.id] = im - async def player_join(self, user: Member) -> None: + async def player_join(self, user: Union[User, Member]) -> None: """ Handle players joining the game. @@ -495,7 +496,7 @@ class SnakeAndLaddersGame: delete_after=10 ) - async def player_leave(self, user: Member) -> bool: + async def player_leave(self, user: Union[User, Member]) -> bool: """ Handle players leaving the game. @@ -530,7 +531,7 @@ class SnakeAndLaddersGame: await self.channel.send("**Snakes and Ladders**: Game has been canceled.") self._destruct() - async def start_game(self, user: Member) -> None: + async def start_game(self, user: Union[User, Member]) -> None: """ Allow the game author to begin the game. @@ -551,7 +552,7 @@ class SnakeAndLaddersGame: async def start_round(self) -> None: """Begin the round.""" - def game_event_check(reaction_: Reaction, user_: Member) -> bool: + def game_event_check(reaction_: Reaction, user_: Union[User, Member]) -> bool: """Make sure that this reaction is what we want to operate on.""" return ( all(( @@ -644,7 +645,7 @@ class SnakeAndLaddersGame: if not is_surrendered: await self._complete_round() - async def player_roll(self, user: Member) -> None: + async def player_roll(self, user: Union[User, Member]) -> None: """Handle the player's roll.""" if user.id not in self.player_tiles: await self.channel.send(user.mention + " You are not in the match.", delete_after=10) @@ -691,7 +692,7 @@ class SnakeAndLaddersGame: await self.channel.send("**Snakes and Ladders**: " + winner.mention + " has won the game! :tada:") self._destruct() - def _check_winner(self) -> Member: + def _check_winner(self) -> Union[User, Member]: """Return a winning member if we're in the post-round state and there's a winner.""" if self.state != "post_round": return None @@ -716,6 +717,6 @@ class SnakeAndLaddersGame: return x_level, y_level @staticmethod - def _is_moderator(user: Member) -> bool: + def _is_moderator(user: Union[User, Member]) -> bool: """Return True if the user is a Moderator.""" - return any(Roles.moderation_team == role.id for role in user.roles) + return any(role.id in MODERATION_ROLES for role in getattr(user, 'roles', [])) diff --git a/bot/exts/fun/trivia_quiz.py b/bot/exts/fun/trivia_quiz.py index 60afbb06..4a1cec5b 100644 --- a/bot/exts/fun/trivia_quiz.py +++ b/bot/exts/fun/trivia_quiz.py @@ -16,7 +16,7 @@ from discord.ext import commands, tasks from rapidfuzz import fuzz from bot.bot import Bot -from bot.constants import Client, Colours, NEGATIVE_REPLIES, Roles +from bot.constants import Client, Colours, MODERATION_ROLES, NEGATIVE_REPLIES logger = logging.getLogger(__name__) @@ -550,7 +550,7 @@ class TriviaQuiz(commands.Cog): if self.game_status[ctx.channel.id]: # Check if the author is the game starter or a moderator. if ctx.author == self.game_owners[ctx.channel.id] or any( - Roles.moderation_team == role.id for role in ctx.author.roles + role.id in MODERATION_ROLES for role in getattr(ctx.author, 'roles', []) ): self.game_status[ctx.channel.id] = False del self.game_owners[ctx.channel.id] -- cgit v1.2.3 From aa272dbe789e86013969bc6f4e506d70ddfc63be Mon Sep 17 00:00:00 2001 From: Izan Date: Mon, 11 Oct 2021 14:47:16 +0100 Subject: Check role id in STAFF_ROLES instead of comparing to helpers --- bot/exts/events/advent_of_code/_cog.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 4d811fa4..0a18c261 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -9,7 +9,7 @@ from discord.ext import commands from bot.bot import Bot from bot.constants import ( - AdventOfCode as AocConfig, Channels, Colours, Emojis, Month, Roles, WHITELISTED_CHANNELS, + AdventOfCode as AocConfig, Channels, Colours, Emojis, Month, Roles, STAFF_ROLES, WHITELISTED_CHANNELS, ) from bot.exts.events.advent_of_code import _helpers from bot.utils.decorators import InChannelCheckFailure, in_month, whitelist_override, with_role @@ -145,7 +145,7 @@ class AdventOfCode(commands.Cog): author = ctx.author log.info(f"{author.name} ({author.id}) has requested a PyDis AoC leaderboard code") - if AocConfig.staff_leaderboard_id and any(r.id == Roles.helpers for r in author.roles): + if AocConfig.staff_leaderboard_id and any(r.id in STAFF_ROLES for r in author.roles): join_code = AocConfig.leaderboards[AocConfig.staff_leaderboard_id].join_code else: try: -- cgit v1.2.3 From a94ce986832694a572ce31b8fedd2b98c2c7747a Mon Sep 17 00:00:00 2001 From: Izan Date: Mon, 11 Oct 2021 14:59:31 +0100 Subject: Make certain AOC commands guild-only --- bot/exts/events/advent_of_code/_cog.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'bot') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 0a18c261..3bd4873c 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -55,6 +55,7 @@ class AdventOfCode(commands.Cog): if not ctx.invoked_subcommand: await invoke_help_command(ctx) + @commands.guild_only() @adventofcode_group.command( name="subscribe", aliases=("sub", "notifications", "notify", "notifs"), @@ -84,6 +85,7 @@ class AdventOfCode(commands.Cog): ) @in_month(Month.DECEMBER) + @commands.guild_only() @adventofcode_group.command(name="unsubscribe", aliases=("unsub",), brief="Notifications for new days") @whitelist_override(channels=AOC_WHITELIST) async def aoc_unsubscribe(self, ctx: commands.Context) -> None: @@ -133,6 +135,7 @@ class AdventOfCode(commands.Cog): """Respond with an explanation of all things Advent of Code.""" await ctx.send(embed=self.cached_about_aoc) + @commands.guild_only() @adventofcode_group.command(name="join", aliases=("j",), brief="Learn how to join the leaderboard (via DM)") @whitelist_override(channels=AOC_WHITELIST) async def join_leaderboard(self, ctx: commands.Context) -> None: -- cgit v1.2.3 From be7da6f34e50b7a99ef6c3a7eb67a48b24b818ed Mon Sep 17 00:00:00 2001 From: Izan Date: Mon, 29 Nov 2021 09:11:17 +0000 Subject: Change `MODERATION_ROLES` and `STAFF_ROLES` constants to be a set --- bot/constants.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/constants.py b/bot/constants.py index b4191c5e..bef7f3d1 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -332,8 +332,8 @@ class Reddit: # Default role combinations -MODERATION_ROLES = Roles.moderation_team, Roles.admins, Roles.owners -STAFF_ROLES = Roles.helpers, Roles.moderation_team, Roles.admins, Roles.owners +MODERATION_ROLES = {Roles.moderation_team, Roles.admins, Roles.owners} +STAFF_ROLES = {Roles.helpers, Roles.moderation_team, Roles.admins, Roles.owners} # Whitelisted channels WHITELISTED_CHANNELS = ( -- cgit v1.2.3 From a958d1c1f6a3308b5ffd03cb7f9ef846b0871265 Mon Sep 17 00:00:00 2001 From: Izan Date: Mon, 29 Nov 2021 09:34:31 +0000 Subject: Revert change to if statement checking if staff in `.aoc join` --- bot/exts/events/advent_of_code/_cog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index c3073fd5..34ade5b1 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -148,7 +148,7 @@ class AdventOfCode(commands.Cog): author = ctx.author log.info(f"{author.name} ({author.id}) has requested a PyDis AoC leaderboard code") - if AocConfig.staff_leaderboard_id and any(r.id in STAFF_ROLES for r in author.roles): + if AocConfig.staff_leaderboard_id and any(r.id == Roles.helpers for r in author.roles): join_code = AocConfig.leaderboards[AocConfig.staff_leaderboard_id].join_code else: try: -- cgit v1.2.3