diff --git a/bot/__main__.py b/bot/__main__.py index a4fe4c7..beb292b 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -58,6 +58,11 @@ async def main() -> None: guild_id=constants.Bot.guild, allowed_roles=allowed_roles, command_prefix=constants.Bot.prefix, + allowed_mentions=discord.AllowedMentions( + everyone=False, + roles=False, + users=True, + ), activity=discord.Game("The Not-Quite-So-Bot-as-Sir-Lancebot"), intents=_intents, ) diff --git a/bot/exts/code_jams/_cog.py b/bot/exts/code_jams/_cog.py index d9644ad..a08a218 100644 --- a/bot/exts/code_jams/_cog.py +++ b/bot/exts/code_jams/_cog.py @@ -272,7 +272,7 @@ async def ping_codejam_team(self, ctx: commands.Context) -> None: log.error("Failed to find '%s' in CJMS.", ctx.channel.name) await ctx.send("Failed to find team role id in database.") return - await ctx.send(f"<@&{role_id}>") + await ctx.send(f"<@&{role_id}>", allowed_mentions=discord.AllowedMentions(roles=[discord.Object(role_id)])) @staticmethod def jam_categories(guild: Guild) -> list[discord.CategoryChannel]: diff --git a/bot/exts/code_jams/_creation_utils.py b/bot/exts/code_jams/_creation_utils.py index 165e9e6..d469b00 100644 --- a/bot/exts/code_jams/_creation_utils.py +++ b/bot/exts/code_jams/_creation_utils.py @@ -179,7 +179,10 @@ async def _send_status_update(guild: discord.Guild, message: str) -> None: """Inform the events lead with a status update when the command is ran.""" channel: discord.TextChannel = guild.get_channel(Channels.code_jam_planning) - await channel.send(f"<@&{Roles.events_lead}>\n\n{message}") + await channel.send( + f"<@&{Roles.events_lead}>\n\n{message}", + allowed_mentions=discord.AllowedMentions(roles=[discord.Object(Roles.events_lead)]), + ) async def _add_team_leader_roles(members: list[dict[str: discord.Member, str: bool]], diff --git a/bot/exts/code_jams/_views.py b/bot/exts/code_jams/_views.py index 8354390..701800a 100644 --- a/bot/exts/code_jams/_views.py +++ b/bot/exts/code_jams/_views.py @@ -66,7 +66,8 @@ async def announce(self, interaction: discord.Interaction, button: discord.ui.Bu await announcements.send( f"<@&{Roles.code_jam_participants}> ! You have been sorted into a team!" " Click the button below to get a detailed description!", - view=JamTeamInfoView(self.bot) + view=JamTeamInfoView(self.bot), + allowed_mentions=discord.AllowedMentions(roles=[discord.Object(id=Roles.code_jam_participants)]) ) teams = await self.bot.code_jam_mgmt_api.get( diff --git a/bot/exts/games.py b/bot/exts/games.py index 35880c8..8f90d80 100644 --- a/bot/exts/games.py +++ b/bot/exts/games.py @@ -284,7 +284,8 @@ async def join(self, ctx: commands.Context) -> None: adjective: str = random.choice(TEAM_ADJECTIVES[team_with_fewest_members]) await ctx.reply( - f"You seem to be extremely {adjective}. You shall be assigned to... {role_with_fewest_members.mention}!" + f"You seem to be extremely {adjective}. You shall be assigned to... {role_with_fewest_members.mention}!", + allowed_mentions=discord.AllowedMentions(roles=False, replied_user=True), ) @games_command_group.command(aliases=("score", "points", "leaderboard", "lb")) diff --git a/bot/exts/summer_aoc.py b/bot/exts/summer_aoc.py index 856cf76..c002807 100644 --- a/bot/exts/summer_aoc.py +++ b/bot/exts/summer_aoc.py @@ -300,6 +300,7 @@ async def post_puzzle(self) -> None: thread_starter = await channel.send( f"<@&{Roles.summer_aoc}>", embed=self.get_puzzle_embed(), + allowed_mentions=discord.AllowedMentions(roles=[discord.Object(Roles.summer_aoc)]) ) await thread_starter.create_thread(name=f"Day {self.current_day} Spoilers") diff --git a/bot/utils/__init__.py b/bot/utils/__init__.py index 5aa6e05..33a08bc 100644 --- a/bot/utils/__init__.py +++ b/bot/utils/__init__.py @@ -1,5 +1,4 @@ import asyncio -import contextlib import re import string from collections.abc import Iterable @@ -153,25 +152,3 @@ def _repl(match: re.Match) -> str: return replacement.lower() return regex.sub(_repl, sentence) - - -@contextlib.asynccontextmanager -async def unlocked_role(role: discord.Role, delay: int = 5) -> None: - """ - Create a context in which `role` is unlocked, relocking it automatically after use. - - A configurable `delay` is added before yielding the context and directly after exiting the - context to allow the role settings change to properly propagate at Discord's end. This - prevents things like role mentions from failing because of synchronization issues. - - Usage: - >>> async with unlocked_role(role, delay=5): - ... await ctx.send(f"Hey {role.mention}, free pings for everyone!") - """ - await role.edit(mentionable=True) - await asyncio.sleep(delay) - try: - yield - finally: - await asyncio.sleep(delay) - await role.edit(mentionable=False)