Skip to content

Commit c976fbd

Browse files
committed
set botlevel allowed_mentions and also fix ctx.reply
1 parent e070195 commit c976fbd

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

core/bot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(self):
6464
super().__init__(
6565
command_prefix=commands.when_mentioned_or(CONFIG["prefix"]),
6666
intents=discord.Intents.all(),
67+
allowed_mentions=discord.AllowedMentions.none(),
6768
)
6869
self._previous_websocket_events: deque[Any] = deque(maxlen=10)
6970

core/context.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Any, TYPE_CHECKING, TypeAlias
3+
from typing import TYPE_CHECKING, TypeAlias
44

55
import discord
66
from discord.ext import commands
@@ -23,6 +23,19 @@
2323

2424

2525
class Context(commands.Context["Bot"]):
26+
@discord.utils.cached_property
27+
def replied_reference(self) -> discord.MessageReference | None:
28+
ref = self.message.reference
29+
if ref and isinstance(ref.resolved, discord.Message):
30+
return ref.resolved.to_reference()
31+
return None
32+
33+
@discord.utils.cached_property
34+
def replied_message(self) -> discord.Message | None:
35+
ref = self.message.reference
36+
if ref and isinstance(ref.resolved, discord.Message):
37+
return ref.resolved
38+
return None
2639

2740
def author_is_mod(self) -> bool:
2841
member: discord.Member
@@ -46,13 +59,6 @@ def author_is_mod(self) -> bool:
4659
roles = member._roles # type: ignore # we know this won't change for a while
4760
return roles.has(Roles.ADMIN) or roles.has(Roles.MODERATOR)
4861

49-
@discord.utils.copy_doc(commands.Context.reply) # type: ignore
50-
async def reply(self, content: str | None = None, **kwargs: Any) -> discord.Message:
51-
if "mention_author" not in kwargs:
52-
kwargs["mention_author"] = False
53-
54-
return await super().reply(content, **kwargs)
55-
5662

5763
class GuildContext(Context):
5864
guild: discord.Guild # type: ignore # type lie due to narrowing

modules/manuals.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,6 @@ def _smart_guess_lib(self, ctx: core.Context) -> LibEnum | None:
9696

9797
return None
9898

99-
async def context_reply(
100-
self,
101-
ctx: core.Context,
102-
content: str | None = discord.utils.MISSING,
103-
embed: discord.Embed | None = discord.utils.MISSING,
104-
reference: discord.MessageReference | None = None,
105-
mention_author: bool = True,
106-
) -> discord.Message:
107-
if ctx.message.reference and not reference:
108-
reference = ctx.message.reference
109-
110-
return await ctx.send(content=content, embed=embed, reference=reference, mention_author=mention_author)
111-
11299
@commands.command(
113100
"rtfm",
114101
brief="Searches documentation",
@@ -141,7 +128,7 @@ async def rtfm(self, ctx: core.Context, *, query: str) -> None:
141128
await ctx.reply("Sorry, I couldn't apply a default library to this channel. Try again with a library?")
142129
return
143130

144-
await self.context_reply(ctx, str(lib.value))
131+
await ctx.reply(str(lib.value), reference=ctx.replied_message)
145132
return
146133

147134
labels = False
@@ -174,7 +161,7 @@ async def rtfm(self, ctx: core.Context, *, query: str) -> None:
174161
return
175162

176163
if not final_query:
177-
await self.context_reply(ctx, str(lib.value[0]))
164+
await ctx.reply(str(lib.value[0]), reference=ctx.replied_message)
178165
return
179166

180167
url = self.target.with_path("/api/public/rtfm.sphinx").with_query(
@@ -239,7 +226,7 @@ async def rtfs(self, ctx: core.Context, *, query: str) -> None:
239226
await ctx.reply("Sorry, I couldn't apply a default library to this channel. Try again with a library?")
240227
return
241228

242-
await self.context_reply(ctx, str(lib.value))
229+
await ctx.reply(str(lib.value), reference=ctx.replied_message)
243230
return
244231

245232
source = False
@@ -310,9 +297,7 @@ async def rtfs(self, ctx: core.Context, *, query: str) -> None:
310297

311298
else:
312299
n = next(iter(nodes.items()))
313-
await self.context_reply(
314-
ctx, f"Showing source for `{n[0]}`\nCommit: {matches['commit'][:6]}", mention_author=False
315-
)
300+
await ctx.reply(f"Showing source for `{n[0]}`\nCommit: {matches['commit'][:6]}", reference=ctx.replied_message)
316301

317302
pages = TextPager(ctx, n[1], prefix="```py")
318303
await pages.paginate()

0 commit comments

Comments
 (0)