@@ -196,31 +196,42 @@ async def thread_triple(thread: discord.Thread):
196
196
count_thread_reactions (thread , starter_message ),
197
197
)
198
198
199
- thread_triples = sorted (
200
- [
201
- triple
202
- for thread in itertools .chain (
203
- sorted (channel .threads , key = lambda t : t .id , reverse = True ),
204
- [
205
- thread
206
- async for thread in channel .archived_threads (
207
- limit = amount
208
- - len (channel .threads ), # subtract active threads
209
- before = before ,
210
- )
211
- ],
212
- )
213
- if (
214
- before_ts is None
215
- or discord .utils .snowflake_time (thread .id ) < before_ts
216
- )
217
- and (
218
- after_ts is None
219
- or discord .utils .snowflake_time (thread .id ) > after_ts
220
- )
221
- and (triple := (await thread_triple (thread )))
222
- and any (tag .name .lower () in tags for tag in triple [0 ].applied_tags )
223
- ][:amount ],
199
+ max_archived_threads = max (
200
+ amount - len (channel .threads ), 0
201
+ ) # subtract active threads
202
+
203
+ thread_triples = sorted ( # sort triples by reaction count
204
+ (
205
+ sorted_thread_triples := [
206
+ # retrieve threads as
207
+ # (thread, message, reaction_count) tuples within time range
208
+ # in descending order
209
+ triple
210
+ for thread in itertools .chain (
211
+ sorted (channel .threads , key = lambda t : t .id , reverse = True ),
212
+ (
213
+ [
214
+ thread
215
+ async for thread in channel .archived_threads (
216
+ limit = max_archived_threads ,
217
+ )
218
+ ]
219
+ if max_archived_threads
220
+ else (())
221
+ ),
222
+ )
223
+ if (
224
+ before_ts is None
225
+ or discord .utils .snowflake_time (thread .id ) < before_ts
226
+ )
227
+ and (
228
+ after_ts is None
229
+ or discord .utils .snowflake_time (thread .id ) > after_ts
230
+ )
231
+ and (triple := (await thread_triple (thread )))
232
+ and any (tag .name .lower () in tags for tag in triple [0 ].applied_tags )
233
+ ][:amount ]
234
+ ),
224
235
key = lambda tup : tup [2 ],
225
236
reverse = True ,
226
237
)
@@ -233,8 +244,24 @@ async def thread_triple(thread: discord.Thread):
233
244
embed_dict = {
234
245
"title" : f"Showcase Rankings for { channel .mention } Posts by Emoji\n "
235
246
f"({ len (thread_triples )} selected, from "
236
- f"<t:{ int (discord .utils .snowflake_time (thread_triples [0 ][0 ].id ).timestamp ())} > "
237
- f"to <t:{ int (discord .utils .snowflake_time (thread_triples [- 1 ][0 ].id ).timestamp ())} >)" ,
247
+ "<t:"
248
+ + str (
249
+ int (
250
+ discord .utils .snowflake_time (
251
+ sorted_thread_triples [- 1 ][0 ].id
252
+ ).timestamp ()
253
+ )
254
+ )
255
+ + "> "
256
+ f"to <t:"
257
+ + str (
258
+ int (
259
+ discord .utils .snowflake_time (
260
+ sorted_thread_triples [0 ][0 ].id
261
+ ).timestamp ()
262
+ )
263
+ )
264
+ + ">)" ,
238
265
"color" : self .theme_color .value ,
239
266
"fields" : [],
240
267
}
@@ -260,10 +287,12 @@ async def thread_triple(thread: discord.Thread):
260
287
)
261
288
)
262
289
290
+ # divide embed dict into lists of multiple embed dicts if necessary
263
291
response_embed_dict_lists = [
264
292
snakecore .utils .embeds .split_embed_dict (embed_dict )
265
293
]
266
294
295
+ # group those lists based on the total character count of the embeds
267
296
for i in range (len (response_embed_dict_lists )):
268
297
response_embed_dicts_list = response_embed_dict_lists [i ]
269
298
total_char_count = 0
@@ -275,8 +304,11 @@ async def thread_triple(thread: discord.Thread):
275
304
response_embed_dict
276
305
)
277
306
) > snakecore .utils .embeds .EMBED_TOTAL_CHAR_LIMIT :
278
- response_embed_dict_lists .insert ( # slice up the response embed dict list to fit the character limit per message
279
- i + 1 , response_embed_dicts_list [j : j + 1 ]
307
+ response_embed_dict_lists .insert (
308
+ # slice up the response embed dict list to fit the character
309
+ # limit per message
310
+ i + 1 ,
311
+ response_embed_dicts_list [j : j + 1 ],
280
312
)
281
313
response_embed_dict_lists [i ] = response_embed_dicts_list [:j ]
282
314
else :
0 commit comments