Skip to content

Commit 96e5f63

Browse files
Merge pull request #163 from onerandomusername/qt/allowed_mentions
fix: use allowed mentions where needed
1 parent 3f02057 commit 96e5f63

File tree

7 files changed

+15
-27
lines changed

7 files changed

+15
-27
lines changed

bot/__main__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ async def main() -> None:
5858
guild_id=constants.Bot.guild,
5959
allowed_roles=allowed_roles,
6060
command_prefix=constants.Bot.prefix,
61+
allowed_mentions=discord.AllowedMentions(
62+
everyone=False,
63+
roles=False,
64+
users=True,
65+
),
6166
activity=discord.Game("The Not-Quite-So-Bot-as-Sir-Lancebot"),
6267
intents=_intents,
6368
)

bot/exts/code_jams/_cog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ async def ping_codejam_team(self, ctx: commands.Context) -> None:
272272
log.error("Failed to find '%s' in CJMS.", ctx.channel.name)
273273
await ctx.send("Failed to find team role id in database.")
274274
return
275-
await ctx.send(f"<@&{role_id}>")
275+
await ctx.send(f"<@&{role_id}>", allowed_mentions=discord.AllowedMentions(roles=[discord.Object(role_id)]))
276276

277277
@staticmethod
278278
def jam_categories(guild: Guild) -> list[discord.CategoryChannel]:

bot/exts/code_jams/_creation_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ async def _send_status_update(guild: discord.Guild, message: str) -> None:
179179
"""Inform the events lead with a status update when the command is ran."""
180180
channel: discord.TextChannel = guild.get_channel(Channels.code_jam_planning)
181181

182-
await channel.send(f"<@&{Roles.events_lead}>\n\n{message}")
182+
await channel.send(
183+
f"<@&{Roles.events_lead}>\n\n{message}",
184+
allowed_mentions=discord.AllowedMentions(roles=[discord.Object(Roles.events_lead)]),
185+
)
183186

184187

185188
async def _add_team_leader_roles(members: list[dict[str: discord.Member, str: bool]],

bot/exts/code_jams/_views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ async def announce(self, interaction: discord.Interaction, button: discord.ui.Bu
6666
await announcements.send(
6767
f"<@&{Roles.code_jam_participants}> ! You have been sorted into a team!"
6868
" Click the button below to get a detailed description!",
69-
view=JamTeamInfoView(self.bot)
69+
view=JamTeamInfoView(self.bot),
70+
allowed_mentions=discord.AllowedMentions(roles=[discord.Object(id=Roles.code_jam_participants)])
7071
)
7172

7273
teams = await self.bot.code_jam_mgmt_api.get(

bot/exts/games.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ async def join(self, ctx: commands.Context) -> None:
284284

285285
adjective: str = random.choice(TEAM_ADJECTIVES[team_with_fewest_members])
286286
await ctx.reply(
287-
f"You seem to be extremely {adjective}. You shall be assigned to... {role_with_fewest_members.mention}!"
287+
f"You seem to be extremely {adjective}. You shall be assigned to... {role_with_fewest_members.mention}!",
288+
allowed_mentions=discord.AllowedMentions(roles=False, replied_user=True),
288289
)
289290

290291
@games_command_group.command(aliases=("score", "points", "leaderboard", "lb"))

bot/exts/summer_aoc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ async def post_puzzle(self) -> None:
300300
thread_starter = await channel.send(
301301
f"<@&{Roles.summer_aoc}>",
302302
embed=self.get_puzzle_embed(),
303+
allowed_mentions=discord.AllowedMentions(roles=[discord.Object(Roles.summer_aoc)])
303304
)
304305
await thread_starter.create_thread(name=f"Day {self.current_day} Spoilers")
305306

bot/utils/__init__.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import contextlib
32
import re
43
import string
54
from collections.abc import Iterable
@@ -153,25 +152,3 @@ def _repl(match: re.Match) -> str:
153152
return replacement.lower()
154153

155154
return regex.sub(_repl, sentence)
156-
157-
158-
@contextlib.asynccontextmanager
159-
async def unlocked_role(role: discord.Role, delay: int = 5) -> None:
160-
"""
161-
Create a context in which `role` is unlocked, relocking it automatically after use.
162-
163-
A configurable `delay` is added before yielding the context and directly after exiting the
164-
context to allow the role settings change to properly propagate at Discord's end. This
165-
prevents things like role mentions from failing because of synchronization issues.
166-
167-
Usage:
168-
>>> async with unlocked_role(role, delay=5):
169-
... await ctx.send(f"Hey {role.mention}, free pings for everyone!")
170-
"""
171-
await role.edit(mentionable=True)
172-
await asyncio.sleep(delay)
173-
try:
174-
yield
175-
finally:
176-
await asyncio.sleep(delay)
177-
await role.edit(mentionable=False)

0 commit comments

Comments
 (0)