30
30
31
31
import constants
32
32
import core
33
-
33
+ from core . utils . paginator import TextPager
34
34
35
35
class LibEnum (Enum ):
36
36
wavelink = ("https://wavelink.readthedocs.io/en/latest" , constants .Colours .PYTHONISTA_BG , "wavelink" )
@@ -94,6 +94,19 @@ def _smart_guess_lib(self, ctx: core.Context) -> LibEnum | None:
94
94
return LibEnum .twitchio
95
95
96
96
return None
97
+
98
+ async def context_reply (
99
+ self ,
100
+ ctx : core .Context ,
101
+ content : str | None = discord .utils .MISSING ,
102
+ embed : discord .Embed | None = discord .utils .MISSING ,
103
+ reference : discord .MessageReference | None = None ,
104
+ mention_author : bool = True
105
+ ) -> discord .Message :
106
+ if ctx .message .reference and not reference :
107
+ reference = ctx .message .reference
108
+
109
+ return await ctx .send (content = content , embed = embed , reference = reference , mention_author = mention_author )
97
110
98
111
@commands .command (
99
112
"rtfm" ,
@@ -127,7 +140,7 @@ async def rtfm(self, ctx: core.Context, *, query: str) -> None:
127
140
await ctx .reply ("Sorry, I couldn't apply a default library to this channel. Try again with a library?" )
128
141
return
129
142
130
- await ctx . reply ( str (lib .value ))
143
+ await self . context_reply ( ctx , str (lib .value ))
131
144
return
132
145
133
146
labels = False
@@ -160,7 +173,7 @@ async def rtfm(self, ctx: core.Context, *, query: str) -> None:
160
173
return
161
174
162
175
if not final_query :
163
- await ctx . reply ( str (lib .value [0 ]))
176
+ await self . context_reply ( ctx , str (lib .value [0 ]))
164
177
return
165
178
166
179
url = self .target .with_path ("/api/public/rtfm.sphinx" ).with_query (
@@ -225,7 +238,7 @@ async def rtfs(self, ctx: core.Context, *, query: str) -> None:
225
238
await ctx .reply ("Sorry, I couldn't apply a default library to this channel. Try again with a library?" )
226
239
return
227
240
228
- await ctx . reply ( str (lib .value ))
241
+ await self . context_reply ( ctx , str (lib .value ))
229
242
return
230
243
231
244
source = False
@@ -279,13 +292,13 @@ async def rtfs(self, ctx: core.Context, *, query: str) -> None:
279
292
await ctx .send ("Could not find anything. Sorry." )
280
293
return
281
294
282
- nodes = matches ["nodes" ]
295
+ nodes : dict [ str , str ] = matches ["nodes" ]
283
296
284
297
if not source :
285
298
out = [f"[{ name } ]({ url } )" for name , url in nodes .items ()]
286
299
287
300
author : str = f"query Time: { float (matches ['query_time' ]):.03f} • commit { matches ['commit' ][:6 ]} "
288
- footer : str = f"Is the api behind on commits? Use { discord .utils .escape_mentions (ctx .prefix )} rtfs-reload"
301
+ footer : str = f"Is the api behind on commits? Use { discord .utils .escape_mentions (ctx .prefix )} rtfs-reload" # type: ignore
289
302
290
303
embed : discord .Embed = discord .Embed (title = f"{ lib .name .title ()} : { final_query } " , colour = lib .value [1 ])
291
304
embed .description = "\n " .join (out )
@@ -296,7 +309,7 @@ async def rtfs(self, ctx: core.Context, *, query: str) -> None:
296
309
297
310
else :
298
311
n = next (iter (nodes .items ()))
299
- await ctx . reply ( f"Showing source for `{ n [0 ]} `\n Commit: { matches ['commit' ][:6 ]} " , mention_author = False )
312
+ await self . context_reply ( ctx , f"Showing source for `{ n [0 ]} `\n Commit: { matches ['commit' ][:6 ]} " , mention_author = False )
300
313
301
314
pages = TextPager (ctx , n [1 ], prefix = "```py" )
302
315
await pages .paginate ()
0 commit comments