@@ -97,6 +97,49 @@ def _smart_guess_lib(self, ctx: core.Context) -> LibEnum | None:
97
97
98
98
return None
99
99
100
+ async def get_lib (self , ctx : core .Context , query : str ) -> tuple [LibEnum , str , str ] | None : # enum, query, notice
101
+ if not query :
102
+ lib = self ._smart_guess_lib (ctx )
103
+
104
+ if not lib :
105
+ await ctx .reply ("Sorry, I couldn't apply a default library to this channel. Try again with a library?" )
106
+ return None
107
+
108
+ await ctx .send (str (lib .value ), reference = ctx .replied_message )
109
+ return None
110
+
111
+ view = StringView (query )
112
+ maybe_lib = view .get_word ()
113
+ view .skip_ws ()
114
+ final_query = view .read_rest ()
115
+
116
+ tip = ""
117
+ lib : LibEnum | None = None
118
+
119
+ if maybe_lib in lib_names :
120
+ lib = lib_names [maybe_lib ]
121
+ else :
122
+ maybe_lib = None
123
+ final_query = query # ignore the stringview stuff then
124
+
125
+ if lib is None :
126
+ lib = self ._smart_guess_lib (ctx )
127
+
128
+ if lib is None :
129
+ await ctx .reply ("Sorry, I couldn't find a library that matched. Try again with a different library?" )
130
+ return None
131
+
132
+ elif (
133
+ maybe_lib
134
+ and isinstance (ctx .channel , discord .Thread )
135
+ and ctx .channel .parent_id == constants .Channels .HELP_FORUM
136
+ and lib == self ._smart_guess_lib (ctx )
137
+ ):
138
+ if 1006717008613740596 not in ctx .channel ._applied_tags : # type: ignore # other-help tag, that one doesnt get a smart guess
139
+ tip += "\n • Tip: Forum posts with tags will automatically have the relevant libraries used, no need to specify it!"
140
+
141
+ return lib , final_query , tip
142
+
100
143
@commands .command (
101
144
"rtfm" ,
102
145
brief = "Searches documentation" ,
@@ -111,28 +154,18 @@ async def rtfm(self, ctx: core.Context, *, query: str) -> None:
111
154
On its own it will do its best to figure out the most relevant documentation,
112
155
but you can always specify by prefixing the query with the library you wish to use.
113
156
The following libraries are supported (you can use either the full name or the shorthand):
114
- ```
115
- - wavelink | wl
116
- - twitchio | tio
117
- - python | py
118
- - discordpy | dpy
119
- ```
120
157
121
- The following flags are available for this command:
122
- ```
123
- - --labels (Include labels in search results)
124
- - --clear (Clearly labels labels with a `label:` prefix. If --labels has not be set it will be implicitly set)
125
- """
126
- if not query :
127
- lib = self ._smart_guess_lib (ctx )
158
+ • wavelink | wl
159
+ • twitchio | tio
160
+ • python | py
161
+ • discordpy | dpy
128
162
129
- if not lib :
130
- await ctx .reply ("Sorry, I couldn't apply a default library to this channel. Try again with a library?" )
131
- return
132
163
133
- await ctx .send (str (lib .value ), reference = ctx .replied_message )
134
- return
164
+ The following flags are available for this command:
135
165
166
+ • --labels (Include labels in search results)
167
+ • --clear (Clearly labels labels with a `label:` prefix. If --labels has not be set it will be implicitly set)
168
+ """
136
169
labels = False
137
170
clear_labels = False
138
171
@@ -144,26 +177,14 @@ async def rtfm(self, ctx: core.Context, *, query: str) -> None:
144
177
labels = clear_labels = True # implicitly set --labels
145
178
query = query .replace ("--clear" , "" )
146
179
147
- view = StringView (query )
148
- maybe_lib = view .get_word ()
149
- view .skip_ws ()
150
- final_query = view .read_rest ()
151
- lib : LibEnum | None = None
152
-
153
- if maybe_lib in lib_names :
154
- lib = lib_names [maybe_lib ]
155
- else :
156
- final_query = query # ignore the stringview stuff then
157
-
158
- if lib is None :
159
- lib = self ._smart_guess_lib (ctx )
160
-
161
- if lib is None :
162
- await ctx .reply ("Sorry, I couldn't find a library that matched. Try again with a different library?" )
180
+ optional = await self .get_lib (ctx , query )
181
+ if not optional :
163
182
return
164
183
184
+ lib , final_query , tip = optional
185
+
165
186
if not final_query :
166
- await ctx .send (str (lib .value [0 ]), reference = ctx .replied_message )
187
+ await ctx .send (str (lib .value [0 ]) + tip , reference = ctx .replied_message )
167
188
return
168
189
169
190
url = self .target .with_path ("/api/public/rtfm.sphinx" ).with_query (
@@ -196,7 +217,7 @@ async def rtfm(self, ctx: core.Context, *, query: str) -> None:
196
217
e .description = "\n " .join (f"[`{ key } `]({ url } )" for key , url in matches ["nodes" ].items ())
197
218
e .set_author (name = f"Query Time: { float (matches ['query_time' ]):.2f} " )
198
219
199
- await ctx .send (embed = e )
220
+ await ctx .send (tip or None , embed = e )
200
221
201
222
@commands .command (
202
223
name = "rtfs" ,
@@ -212,53 +233,31 @@ async def rtfs(self, ctx: core.Context, *, query: str) -> None:
212
233
On its own it will do its best to figure out the most relevant library,
213
234
but you can always specify by prefixing the query with the library you wish to use.
214
235
The following libraries are supported (you can use either the full name or the shorthand):
215
- ```
216
- - wavelink | wl
217
- - twitchio | tio
218
- - discordpy | dpy
219
- - aiohttp |
220
- ```
221
236
222
- The following flags are available for this command:
223
- ```
224
- - --source (Sends source code instead of links to the github repository)
225
- """
226
- if not query :
227
- lib = self ._smart_guess_lib (ctx )
237
+ • wavelink | wl
238
+ • twitchio | tio
239
+ • discordpy | dpy
240
+ • aiohttp |
228
241
229
- if not lib :
230
- await ctx .reply ("Sorry, I couldn't apply a default library to this channel. Try again with a library?" )
231
- return
242
+ The following flags are available for this command:
232
243
233
- await ctx . send ( str ( lib . value ), reference = ctx . replied_message )
234
- return
244
+ • --source (Sends source code instead of links to the github repository )
245
+ """
235
246
236
247
source = False
237
248
238
249
if "--source" in query :
239
250
source = True
240
251
query = query .replace ("--source" , "" )
241
252
242
- view = StringView (query )
243
- maybe_lib = view .get_word ()
244
- view .skip_ws ()
245
- final_query = view .read_rest ()
246
- lib : LibEnum | None = None
247
-
248
- if maybe_lib in lib_names :
249
- lib = lib_names [maybe_lib ]
250
- else :
251
- final_query = query # ignore the stringview stuff then
252
-
253
- if lib is None :
254
- lib = self ._smart_guess_lib (ctx )
255
-
256
- if lib is None :
257
- await ctx .reply ("Sorry, I couldn't find a library that matched. Try again with a different library?" )
253
+ optional = await self .get_lib (ctx , query )
254
+ if not optional :
258
255
return
259
256
257
+ lib , final_query , tip = optional
258
+
260
259
if not final_query :
261
- await ctx .reply (str (lib .value [0 ]))
260
+ await ctx .reply (str (lib .value [0 ]) + tip )
262
261
return
263
262
264
263
url = self .target .with_path ("/api/public/rtfs" ).with_query (
@@ -291,7 +290,7 @@ async def rtfs(self, ctx: core.Context, *, query: str) -> None:
291
290
out = [f"[{ name } ]({ url } )" for name , url in nodes .items ()]
292
291
293
292
author : str = f"query Time: { float (matches ['query_time' ]):.03f} • commit { matches ['commit' ][:6 ]} "
294
- footer : str = f"Is the api behind on commits? Use { discord . utils . escape_mentions ( ctx . prefix ) } rtfs-reload" # type: ignore
293
+ footer : str | None = tip or None
295
294
296
295
embed : discord .Embed = discord .Embed (title = f"{ lib .name .title ()} : { final_query } " , colour = lib .value [1 ])
297
296
embed .description = "\n " .join (out )
@@ -302,9 +301,11 @@ async def rtfs(self, ctx: core.Context, *, query: str) -> None:
302
301
303
302
else :
304
303
n = next (iter (nodes .items ()))
305
- await ctx .send (f"Showing source for `{ n [0 ]} `\n Commit: { matches ['commit' ][:6 ]} " , reference = ctx .replied_message )
304
+ await ctx .send (
305
+ f"Showing source for `{ n [0 ]} `\n Commit: { matches ['commit' ][:6 ]} " + tip , reference = ctx .replied_message
306
+ )
306
307
307
- pages = TextPager (ctx , n [1 ], prefix = "```py" )
308
+ pages = TextPager (ctx , n [1 ], prefix = "```py" , reply_author_takes_paginator = True )
308
309
await pages .paginate ()
309
310
310
311
0 commit comments