From 429ca2a4a359a2e1f580100911fe94352fa8192d Mon Sep 17 00:00:00 2001 From: Izan Date: Tue, 24 Aug 2021 15:39:41 +0100 Subject: Add constants.STAFF_PARTNERS_COMMUNITY_ROLES --- bot/constants.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot/constants.py b/bot/constants.py index 12b5c02e5..5b629a735 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -696,6 +696,7 @@ PROJECT_ROOT = os.path.abspath(os.path.join(BOT_DIR, os.pardir)) # Default role combinations MODERATION_ROLES = Guild.moderation_roles STAFF_ROLES = Guild.staff_roles +STAFF_PARTNERS_COMMUNITY_ROLES = STAFF_ROLES + [Roles.partners, Roles.python_community] # Channel combinations MODERATION_CHANNELS = Guild.moderation_channels -- cgit v1.2.3 From 2c93e2deedddb98efa26e9e513b54df1a457adf6 Mon Sep 17 00:00:00 2001 From: Izan Date: Tue, 24 Aug 2021 15:51:45 +0100 Subject: Allow partners & members of the python community to use commands in any channel Allow partners & members of the python community to use `!remind`, `!help` `!user`, `!snowflake`, `!ping`, `!charinfo` in any channel --- bot/exts/info/help.py | 4 ++-- bot/exts/info/information.py | 2 +- bot/exts/utils/ping.py | 4 ++-- bot/exts/utils/reminders.py | 6 +++--- bot/exts/utils/utils.py | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bot/exts/info/help.py b/bot/exts/info/help.py index 0235bbaf3..21a6cf752 100644 --- a/bot/exts/info/help.py +++ b/bot/exts/info/help.py @@ -10,7 +10,7 @@ from rapidfuzz import fuzz, process from rapidfuzz.utils import default_process from bot import constants -from bot.constants import Channels, STAFF_ROLES +from bot.constants import Channels, STAFF_PARTNERS_COMMUNITY_ROLES from bot.decorators import redirect_output from bot.pagination import LinePaginator from bot.utils.messages import wait_for_deletion @@ -54,7 +54,7 @@ class CustomHelpCommand(HelpCommand): def __init__(self): super().__init__(command_attrs={"help": "Shows help for bot commands"}) - @redirect_output(destination_channel=Channels.bot_commands, bypass_roles=STAFF_ROLES) + @redirect_output(destination_channel=Channels.bot_commands, bypass_roles=STAFF_PARTNERS_COMMUNITY_ROLES) async def command_callback(self, ctx: Context, *, command: str = None) -> None: """Attempts to match the provided query with a valid command or cog.""" # the only reason we need to tamper with this is because d.py does not support "categories", diff --git a/bot/exts/info/information.py b/bot/exts/info/information.py index a9ea403f7..67677a8ad 100644 --- a/bot/exts/info/information.py +++ b/bot/exts/info/information.py @@ -231,7 +231,7 @@ class Information(Cog): return # Will redirect to #bot-commands if it fails. - if in_whitelist_check(ctx, roles=constants.STAFF_ROLES): + if in_whitelist_check(ctx, roles=constants.STAFF_PARTNERS_COMMUNITY_ROLES): embed = await self.create_user_embed(ctx, user) await ctx.send(embed=embed) diff --git a/bot/exts/utils/ping.py b/bot/exts/utils/ping.py index c6d7bd900..cf0e3265e 100644 --- a/bot/exts/utils/ping.py +++ b/bot/exts/utils/ping.py @@ -5,7 +5,7 @@ from discord import Embed from discord.ext import commands from bot.bot import Bot -from bot.constants import Channels, STAFF_ROLES, URLs +from bot.constants import Channels, STAFF_PARTNERS_COMMUNITY_ROLES, URLs from bot.decorators import in_whitelist DESCRIPTIONS = ( @@ -23,7 +23,7 @@ class Latency(commands.Cog): self.bot = bot @commands.command() - @in_whitelist(channels=(Channels.bot_commands,), roles=STAFF_ROLES) + @in_whitelist(channels=(Channels.bot_commands,), roles=STAFF_PARTNERS_COMMUNITY_ROLES) async def ping(self, ctx: commands.Context) -> None: """ Gets different measures of latency within the bot. diff --git a/bot/exts/utils/reminders.py b/bot/exts/utils/reminders.py index 2e60f5030..8aa437895 100644 --- a/bot/exts/utils/reminders.py +++ b/bot/exts/utils/reminders.py @@ -11,7 +11,7 @@ from dateutil.parser import isoparse from discord.ext.commands import Cog, Context, Greedy, group from bot.bot import Bot -from bot.constants import Guild, Icons, MODERATION_ROLES, POSITIVE_REPLIES, Roles, STAFF_ROLES +from bot.constants import Guild, Icons, MODERATION_ROLES, POSITIVE_REPLIES, Roles, STAFF_PARTNERS_COMMUNITY_ROLES, STAFF_ROLES from bot.converters import Duration from bot.pagination import LinePaginator from bot.utils.checks import has_any_role_check, has_no_roles_check @@ -225,8 +225,8 @@ class Reminders(Cog): Expiration is parsed per: http://strftime.org/ """ - # If the user is not staff, we need to verify whether or not to make a reminder at all. - if await has_no_roles_check(ctx, *STAFF_ROLES): + # If the user is not staff, partner or part of the python community, we need to verify whether or not to make a reminder at all. + if await has_no_roles_check(ctx, *STAFF_PARTNERS_COMMUNITY_ROLES): # If they don't have permission to set a reminder in this channel if ctx.channel.id not in WHITELISTED_CHANNELS: diff --git a/bot/exts/utils/utils.py b/bot/exts/utils/utils.py index 98e43c32b..c131213e7 100644 --- a/bot/exts/utils/utils.py +++ b/bot/exts/utils/utils.py @@ -9,7 +9,7 @@ from discord.ext.commands import BadArgument, Cog, Context, clean_content, comma from discord.utils import snowflake_time from bot.bot import Bot -from bot.constants import Channels, MODERATION_ROLES, Roles, STAFF_ROLES +from bot.constants import Channels, MODERATION_ROLES, Roles, STAFF_PARTNERS_COMMUNITY_ROLES, STAFF_ROLES from bot.converters import Snowflake from bot.decorators import in_whitelist from bot.pagination import LinePaginator @@ -50,7 +50,7 @@ class Utils(Cog): self.bot = bot @command() - @in_whitelist(channels=(Channels.bot_commands, Channels.discord_py), roles=STAFF_ROLES) + @in_whitelist(channels=(Channels.bot_commands, Channels.discord_py), roles=STAFF_PARTNERS_COMMUNITY_ROLES) async def charinfo(self, ctx: Context, *, characters: str) -> None: """Shows you information on up to 50 unicode characters.""" match = re.match(r"<(a?):(\w+):(\d+)>", characters) @@ -157,7 +157,7 @@ class Utils(Cog): await ctx.send(embed=embed) @command(aliases=("snf", "snfl", "sf")) - @in_whitelist(channels=(Channels.bot_commands,), roles=STAFF_ROLES) + @in_whitelist(channels=(Channels.bot_commands,), roles=STAFF_PARTNERS_COMMUNITY_ROLES) async def snowflake(self, ctx: Context, *snowflakes: Snowflake) -> None: """Get Discord snowflake creation time.""" if len(snowflakes) > 1 and await has_no_roles_check(ctx, *STAFF_ROLES): -- cgit v1.2.3 From 675b96153bec329c9c18744536e1c0f06210497a Mon Sep 17 00:00:00 2001 From: Izan Date: Tue, 24 Aug 2021 16:04:24 +0100 Subject: Allow partners & members of the python community to use `!role` and `!roles` --- bot/exts/info/information.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/info/information.py b/bot/exts/info/information.py index 67677a8ad..f13567d02 100644 --- a/bot/exts/info/information.py +++ b/bot/exts/info/information.py @@ -94,7 +94,7 @@ class Information(Cog): {python_general.mention} cooldown: {python_general.slowmode_delay}s """) - @has_any_role(*constants.STAFF_ROLES) + @has_any_role(*constants.STAFF_PARTNERS_COMMUNITY_ROLES) @command(name="roles") async def roles_info(self, ctx: Context) -> None: """Returns a list of all roles and their corresponding IDs.""" @@ -114,7 +114,7 @@ class Information(Cog): await LinePaginator.paginate(role_list, ctx, embed, empty=False) - @has_any_role(*constants.STAFF_ROLES) + @has_any_role(*constants.STAFF_PARTNERS_COMMUNITY_ROLES) @command(name="role") async def role_info(self, ctx: Context, *roles: Union[Role, str]) -> None: """ -- cgit v1.2.3 From 5be8cd1ad40fcaaa8e7bdbfc7a0619aceca2660e Mon Sep 17 00:00:00 2001 From: Izan Date: Tue, 24 Aug 2021 16:07:00 +0100 Subject: Allow partners & members of the python community to bypass cooldown and use `!raw` in any channel --- bot/exts/info/information.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/info/information.py b/bot/exts/info/information.py index f13567d02..664b6cb13 100644 --- a/bot/exts/info/information.py +++ b/bot/exts/info/information.py @@ -453,9 +453,9 @@ class Information(Cog): # remove trailing whitespace return out.rstrip() - @cooldown_with_role_bypass(2, 60 * 3, BucketType.member, bypass_roles=constants.STAFF_ROLES) + @cooldown_with_role_bypass(2, 60 * 3, BucketType.member, bypass_roles=constants.STAFF_PARTNERS_COMMUNITY_ROLES) @group(invoke_without_command=True) - @in_whitelist(channels=(constants.Channels.bot_commands,), roles=constants.STAFF_ROLES) + @in_whitelist(channels=(constants.Channels.bot_commands,), roles=constants.STAFF_PARTNERS_COMMUNITY_ROLES) async def raw(self, ctx: Context, *, message: Message, json: bool = False) -> None: """Shows information about the raw API response.""" if ctx.author not in message.channel.members: -- cgit v1.2.3 From 5998a8e0df0b133bc8bc0ac1eaf25d0b4681ccb0 Mon Sep 17 00:00:00 2001 From: Izan Date: Tue, 24 Aug 2021 16:09:39 +0100 Subject: Minor linting fixes --- bot/exts/utils/reminders.py | 7 +++++-- bot/exts/utils/utils.py | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bot/exts/utils/reminders.py b/bot/exts/utils/reminders.py index 8aa437895..a97080a4c 100644 --- a/bot/exts/utils/reminders.py +++ b/bot/exts/utils/reminders.py @@ -11,7 +11,10 @@ from dateutil.parser import isoparse from discord.ext.commands import Cog, Context, Greedy, group from bot.bot import Bot -from bot.constants import Guild, Icons, MODERATION_ROLES, POSITIVE_REPLIES, Roles, STAFF_PARTNERS_COMMUNITY_ROLES, STAFF_ROLES +from bot.constants import ( + Guild, Icons, MODERATION_ROLES, POSITIVE_REPLIES, + Roles, STAFF_PARTNERS_COMMUNITY_ROLES, STAFF_ROLES +) from bot.converters import Duration from bot.pagination import LinePaginator from bot.utils.checks import has_any_role_check, has_no_roles_check @@ -136,7 +139,7 @@ class Reminders(Cog): """Converts Role and Member ids to their corresponding objects if possible.""" guild = self.bot.get_guild(Guild.id) for mention_id in mention_ids: - if (mentionable := (guild.get_member(mention_id) or guild.get_role(mention_id))): + if mentionable := (guild.get_member(mention_id) or guild.get_role(mention_id)): yield mentionable def schedule_reminder(self, reminder: dict) -> None: diff --git a/bot/exts/utils/utils.py b/bot/exts/utils/utils.py index c131213e7..c4a466943 100644 --- a/bot/exts/utils/utils.py +++ b/bot/exts/utils/utils.py @@ -55,15 +55,17 @@ class Utils(Cog): """Shows you information on up to 50 unicode characters.""" match = re.match(r"<(a?):(\w+):(\d+)>", characters) if match: - return await messages.send_denial( + await messages.send_denial( ctx, "**Non-Character Detected**\n" "Only unicode characters can be processed, but a custom Discord emoji " "was found. Please remove it and try again." ) + return if len(characters) > 50: - return await messages.send_denial(ctx, f"Too many characters ({len(characters)}/50)") + await messages.send_denial(ctx, f"Too many characters ({len(characters)}/50)") + return def get_info(char: str) -> Tuple[str, str]: digit = f"{ord(char):x}" -- cgit v1.2.3 From dc92d6e767931e1a6be01ff35b5bb60d603274d2 Mon Sep 17 00:00:00 2001 From: Izan Date: Tue, 24 Aug 2021 16:19:49 +0100 Subject: Ignore partners & members of the python community as well as staff from `!liststream` --- bot/exts/moderation/stream.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bot/exts/moderation/stream.py b/bot/exts/moderation/stream.py index 07ee4099e..e667006ff 100644 --- a/bot/exts/moderation/stream.py +++ b/bot/exts/moderation/stream.py @@ -9,7 +9,7 @@ from async_rediscache import RedisCache from discord.ext import commands from bot.bot import Bot -from bot.constants import Colours, Emojis, Guild, MODERATION_ROLES, Roles, STAFF_ROLES, VideoPermission +from bot.constants import Colours, Emojis, Guild, MODERATION_ROLES, Roles, STAFF_PARTNERS_COMMUNITY_ROLES, VideoPermission from bot.converters import Expiry from bot.pagination import LinePaginator from bot.utils.scheduling import Scheduler @@ -193,17 +193,19 @@ class Stream(commands.Cog): @commands.command(aliases=('lstream',)) @commands.has_any_role(*MODERATION_ROLES) async def liststream(self, ctx: commands.Context) -> None: - """Lists all non-staff users who have permission to stream.""" - non_staff_members_with_stream = [ + """ + Lists all users who aren't staff, partners or members of the python community and have permission to stream. + """ + non_staff_partners_community_members_with_stream = [ member for member in ctx.guild.get_role(Roles.video).members - if not any(role.id in STAFF_ROLES for role in member.roles) + if not any(role.id in STAFF_PARTNERS_COMMUNITY_ROLES for role in member.roles) ] # List of tuples (UtcPosixTimestamp, str) # So that the list can be sorted on the UtcPosixTimestamp before the message is passed to the paginator. streamer_info = [] - for member in non_staff_members_with_stream: + for member in non_staff_partners_community_members_with_stream: if revoke_time := await self.task_cache.get(member.id): # Member only has temporary streaming perms revoke_delta = Arrow.utcfromtimestamp(revoke_time).humanize() -- cgit v1.2.3 From b1aafff149eb2fd2262f4b06a950ebad460f7281 Mon Sep 17 00:00:00 2001 From: Izan Date: Tue, 24 Aug 2021 16:30:16 +0100 Subject: Allow partners & members of the python community to have mentions in `!remind` --- bot/exts/utils/reminders.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/utils/reminders.py b/bot/exts/utils/reminders.py index a97080a4c..847883fc7 100644 --- a/bot/exts/utils/reminders.py +++ b/bot/exts/utils/reminders.py @@ -13,7 +13,7 @@ from discord.ext.commands import Cog, Context, Greedy, group from bot.bot import Bot from bot.constants import ( Guild, Icons, MODERATION_ROLES, POSITIVE_REPLIES, - Roles, STAFF_PARTNERS_COMMUNITY_ROLES, STAFF_ROLES + Roles, STAFF_PARTNERS_COMMUNITY_ROLES ) from bot.converters import Duration from bot.pagination import LinePaginator @@ -113,7 +113,7 @@ class Reminders(Cog): If mentions aren't allowed, also return the type of mention(s) disallowed. """ - if await has_no_roles_check(ctx, *STAFF_ROLES): + if await has_no_roles_check(ctx, *STAFF_PARTNERS_COMMUNITY_ROLES): return False, "members/roles" elif await has_no_roles_check(ctx, *MODERATION_ROLES): return all(isinstance(mention, discord.Member) for mention in mentions), "roles" -- cgit v1.2.3 From f5246e1e8bf0c88320dba0480560bf4b2d2981d2 Mon Sep 17 00:00:00 2001 From: Izan Date: Tue, 24 Aug 2021 17:07:49 +0100 Subject: Fix linting --- bot/exts/moderation/stream.py | 9 +++++---- bot/exts/utils/reminders.py | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bot/exts/moderation/stream.py b/bot/exts/moderation/stream.py index e667006ff..01d2614b0 100644 --- a/bot/exts/moderation/stream.py +++ b/bot/exts/moderation/stream.py @@ -9,7 +9,10 @@ from async_rediscache import RedisCache from discord.ext import commands from bot.bot import Bot -from bot.constants import Colours, Emojis, Guild, MODERATION_ROLES, Roles, STAFF_PARTNERS_COMMUNITY_ROLES, VideoPermission +from bot.constants import ( + Colours, Emojis, Guild, MODERATION_ROLES, Roles, + STAFF_PARTNERS_COMMUNITY_ROLES, VideoPermission +) from bot.converters import Expiry from bot.pagination import LinePaginator from bot.utils.scheduling import Scheduler @@ -193,9 +196,7 @@ class Stream(commands.Cog): @commands.command(aliases=('lstream',)) @commands.has_any_role(*MODERATION_ROLES) async def liststream(self, ctx: commands.Context) -> None: - """ - Lists all users who aren't staff, partners or members of the python community and have permission to stream. - """ + """Lists all users who aren't staff, partners or members of the python community and have stream permissions.""" non_staff_partners_community_members_with_stream = [ member for member in ctx.guild.get_role(Roles.video).members diff --git a/bot/exts/utils/reminders.py b/bot/exts/utils/reminders.py index 847883fc7..2496ce5cc 100644 --- a/bot/exts/utils/reminders.py +++ b/bot/exts/utils/reminders.py @@ -228,7 +228,8 @@ class Reminders(Cog): Expiration is parsed per: http://strftime.org/ """ - # If the user is not staff, partner or part of the python community, we need to verify whether or not to make a reminder at all. + # If the user is not staff, partner or part of the python community, + # we need to verify whether or not to make a reminder at all. if await has_no_roles_check(ctx, *STAFF_PARTNERS_COMMUNITY_ROLES): # If they don't have permission to set a reminder in this channel -- cgit v1.2.3 From 8e2f515c277484145319d0642f588af9287b6af8 Mon Sep 17 00:00:00 2001 From: Izan Date: Tue, 24 Aug 2021 17:21:11 +0100 Subject: Fix linting --- bot/exts/utils/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/exts/utils/utils.py b/bot/exts/utils/utils.py index f91a9fee6..0139a6ad3 100644 --- a/bot/exts/utils/utils.py +++ b/bot/exts/utils/utils.py @@ -9,7 +9,7 @@ from discord.ext.commands import BadArgument, Cog, Context, clean_content, comma from discord.utils import snowflake_time from bot.bot import Bot -from bot.constants import Channels, MODERATION_ROLES, Roles, STAFF_PARTNERS_COMMUNITY_ROLES, STAFF_ROLES +from bot.constants import Channels, MODERATION_ROLES, Roles, STAFF_PARTNERS_COMMUNITY_ROLES from bot.converters import Snowflake from bot.decorators import in_whitelist from bot.pagination import LinePaginator -- cgit v1.2.3 From 93386c48ca775ff7897090b3af98303d66d1f116 Mon Sep 17 00:00:00 2001 From: Izan Date: Tue, 24 Aug 2021 17:47:38 +0100 Subject: Fix tests --- tests/bot/exts/info/test_information.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/bot/exts/info/test_information.py b/tests/bot/exts/info/test_information.py index 0aa41d889..d8250befb 100644 --- a/tests/bot/exts/info/test_information.py +++ b/tests/bot/exts/info/test_information.py @@ -507,7 +507,7 @@ class UserCommandTests(unittest.IsolatedAsyncioTestCase): @unittest.mock.patch("bot.exts.info.information.Information.create_user_embed") async def test_staff_members_can_bypass_channel_restriction(self, create_embed, constants): """Staff members should be able to bypass the bot-commands channel restriction.""" - constants.STAFF_ROLES = [self.moderator_role.id] + constants.STAFF_PARTNERS_COMMUNITY_ROLES = [self.moderator_role.id] ctx = helpers.MockContext(author=self.moderator, channel=helpers.MockTextChannel(id=200)) await self.cog.user_info(self.cog, ctx) @@ -519,7 +519,7 @@ class UserCommandTests(unittest.IsolatedAsyncioTestCase): async def test_moderators_can_target_another_member(self, create_embed, constants): """A moderator should be able to use `!user` targeting another user.""" constants.MODERATION_ROLES = [self.moderator_role.id] - constants.STAFF_ROLES = [self.moderator_role.id] + constants.STAFF_PARTNERS_COMMUNITY_ROLES = [self.moderator_role.id] ctx = helpers.MockContext(author=self.moderator, channel=helpers.MockTextChannel(id=50)) await self.cog.user_info(self.cog, ctx, self.target) -- cgit v1.2.3