Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion bot/exts/code_jams/_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
5 changes: 4 additions & 1 deletion bot/exts/code_jams/_creation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down
3 changes: 2 additions & 1 deletion bot/exts/code_jams/_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion bot/exts/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
1 change: 1 addition & 0 deletions bot/exts/summer_aoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
23 changes: 0 additions & 23 deletions bot/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import contextlib
import re
import string
from collections.abc import Iterable
Expand Down Expand Up @@ -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)