@@ -43,27 +43,26 @@ class PaginatorSession:
43
43
44
44
def __init__ (self , ctx : commands .Context , * embeds , ** options ):
45
45
self .ctx = ctx
46
- self .timeout : int = options .get (' timeout' , 210 )
46
+ self .timeout : int = options .get (" timeout" , 210 )
47
47
self .embeds : typing .List [Embed ] = list (embeds )
48
48
self .running = False
49
49
self .base : Message = None
50
50
self .current = 0
51
- self .destination = options .get (' destination' , ctx )
51
+ self .destination = options .get (" destination" , ctx )
52
52
self .reaction_map = {
53
- '⏮' : self .first_page ,
54
- '◀' : self .previous_page ,
55
- '▶' : self .next_page ,
56
- '⏭' : self .last_page ,
57
- # '⏹' : self.close
53
+ "⏮" : self .first_page ,
54
+ "◀" : self .previous_page ,
55
+ "▶" : self .next_page ,
56
+ "⏭" : self .last_page ,
57
+ "🛑" : self .close ,
58
58
}
59
59
60
- if options .get (' edit_footer' , True ) and len (self .embeds ) > 1 :
60
+ if options .get (" edit_footer" , True ) and len (self .embeds ) > 1 :
61
61
for i , embed in enumerate (self .embeds ):
62
- footer_text = f' Page { i + 1 } of { len (self .embeds )} '
62
+ footer_text = f" Page { i + 1 } of { len (self .embeds )} "
63
63
if embed .footer .text :
64
- footer_text = footer_text + ' • ' + embed .footer .text
65
- embed .set_footer (text = footer_text ,
66
- icon_url = embed .footer .icon_url )
64
+ footer_text = footer_text + " • " + embed .footer .text
65
+ embed .set_footer (text = footer_text , icon_url = embed .footer .icon_url )
67
66
68
67
def add_page (self , embed : Embed ) -> None :
69
68
"""
@@ -77,7 +76,7 @@ def add_page(self, embed: Embed) -> None:
77
76
if isinstance (embed , Embed ):
78
77
self .embeds .append (embed )
79
78
else :
80
- raise TypeError (' Page must be an Embed object.' )
79
+ raise TypeError (" Page must be an Embed object." )
81
80
82
81
async def create_base (self , embed : Embed ) -> None :
83
82
"""
@@ -96,7 +95,7 @@ async def create_base(self, embed: Embed) -> None:
96
95
97
96
self .running = True
98
97
for reaction in self .reaction_map :
99
- if len (self .embeds ) == 2 and reaction in '⏮⏭' :
98
+ if len (self .embeds ) == 2 and reaction in "⏮⏭" :
100
99
continue
101
100
await self .base .add_reaction (reaction )
102
101
@@ -134,9 +133,11 @@ def react_check(self, reaction: Reaction, user: User) -> bool:
134
133
-------
135
134
bool
136
135
"""
137
- return (reaction .message .id == self .base .id and
138
- user .id == self .ctx .author .id and
139
- reaction .emoji in self .reaction_map .keys ())
136
+ return (
137
+ reaction .message .id == self .base .id
138
+ and user .id == self .ctx .author .id
139
+ and reaction .emoji in self .reaction_map .keys ()
140
+ )
140
141
141
142
async def run (self ) -> typing .Optional [Message ]:
142
143
"""
@@ -152,9 +153,7 @@ async def run(self) -> typing.Optional[Message]:
152
153
while self .running :
153
154
try :
154
155
reaction , user = await self .ctx .bot .wait_for (
155
- 'reaction_add' ,
156
- check = self .react_check ,
157
- timeout = self .timeout
156
+ "reaction_add" , check = self .react_check , timeout = self .timeout
158
157
)
159
158
except TimeoutError :
160
159
return await self .close (delete = False )
@@ -195,10 +194,7 @@ async def close(self, delete: bool = True) -> typing.Optional[Message]:
195
194
"""
196
195
self .running = False
197
196
198
- try :
199
- await self .ctx .message .add_reaction ('✅' )
200
- except (HTTPException , InvalidArgument ):
201
- pass
197
+ self .bot .loop .create
202
198
203
199
if delete :
204
200
return await self .base .delete ()
@@ -222,10 +218,11 @@ async def last_page(self) -> None:
222
218
223
219
224
220
class MessagePaginatorSession :
225
- def __init__ (self , ctx : commands .Context , * messages ,
226
- embed : Embed = None , ** options ):
221
+ def __init__ (
222
+ self , ctx : commands .Context , * messages , embed : Embed = None , ** options
223
+ ):
227
224
self .ctx = ctx
228
- self .timeout : int = options .get (' timeout' , 180 )
225
+ self .timeout : int = options .get (" timeout" , 180 )
229
226
self .messages : typing .List [str ] = list (messages )
230
227
231
228
self .running = False
@@ -238,11 +235,11 @@ def __init__(self, ctx: commands.Context, *messages,
238
235
239
236
self .current = 0
240
237
self .reaction_map = {
241
- '⏮' : self .first_page ,
242
- '◀' : self .previous_page ,
243
- '▶' : self .next_page ,
244
- '⏭' : self .last_page ,
245
- # '⏹' : self.close
238
+ "⏮" : self .first_page ,
239
+ "◀" : self .previous_page ,
240
+ "▶" : self .next_page ,
241
+ "⏭" : self .last_page ,
242
+ "🛑" : self .close ,
246
243
}
247
244
248
245
def add_page (self , msg : str ) -> None :
@@ -257,7 +254,7 @@ def add_page(self, msg: str) -> None:
257
254
if isinstance (msg , str ):
258
255
self .messages .append (msg )
259
256
else :
260
- raise TypeError (' Page must be a str object.' )
257
+ raise TypeError (" Page must be a str object." )
261
258
262
259
async def create_base (self , msg : str ) -> None :
263
260
"""
@@ -269,11 +266,10 @@ async def create_base(self, msg: str) -> None:
269
266
The message content to fill the base `Message`.
270
267
"""
271
268
if self .embed is not None :
272
- footer_text = f' Page { self .current + 1 } of { len (self .messages )} '
269
+ footer_text = f" Page { self .current + 1 } of { len (self .messages )} "
273
270
if self .footer_text :
274
- footer_text = footer_text + ' • ' + self .footer_text
275
- self .embed .set_footer (text = footer_text ,
276
- icon_url = self .embed .footer .icon_url )
271
+ footer_text = footer_text + " • " + self .footer_text
272
+ self .embed .set_footer (text = footer_text , icon_url = self .embed .footer .icon_url )
277
273
278
274
self .base = await self .ctx .send (content = msg , embed = self .embed )
279
275
@@ -283,7 +279,7 @@ async def create_base(self, msg: str) -> None:
283
279
284
280
self .running = True
285
281
for reaction in self .reaction_map :
286
- if len (self .messages ) == 2 and reaction in '⏮⏭' :
282
+ if len (self .messages ) == 2 and reaction in "⏮⏭" :
287
283
continue
288
284
await self .base .add_reaction (reaction )
289
285
@@ -303,11 +299,10 @@ async def show_page(self, index: int) -> None:
303
299
page = self .messages [index ]
304
300
305
301
if self .embed is not None :
306
- footer_text = f' Page { self .current + 1 } of { len (self .messages )} '
302
+ footer_text = f" Page { self .current + 1 } of { len (self .messages )} "
307
303
if self .footer_text :
308
- footer_text = footer_text + ' • ' + self .footer_text
309
- self .embed .set_footer (text = footer_text ,
310
- icon_url = self .embed .footer .icon_url )
304
+ footer_text = footer_text + " • " + self .footer_text
305
+ self .embed .set_footer (text = footer_text , icon_url = self .embed .footer .icon_url )
311
306
312
307
if self .running :
313
308
await self .base .edit (content = page , embed = self .embed )
@@ -328,9 +323,11 @@ def react_check(self, reaction: Reaction, user: User) -> bool:
328
323
-------
329
324
bool
330
325
"""
331
- return (reaction .message .id == self .base .id and
332
- user .id == self .ctx .author .id and
333
- reaction .emoji in self .reaction_map .keys ())
326
+ return (
327
+ reaction .message .id == self .base .id
328
+ and user .id == self .ctx .author .id
329
+ and reaction .emoji in self .reaction_map .keys ()
330
+ )
334
331
335
332
async def run (self ) -> typing .Optional [Message ]:
336
333
"""
@@ -346,9 +343,7 @@ async def run(self) -> typing.Optional[Message]:
346
343
while self .running :
347
344
try :
348
345
reaction , user = await self .ctx .bot .wait_for (
349
- 'reaction_add' ,
350
- check = self .react_check ,
351
- timeout = self .timeout
346
+ "reaction_add" , check = self .react_check , timeout = self .timeout
352
347
)
353
348
except TimeoutError :
354
349
return await self .close (delete = False )
@@ -389,10 +384,7 @@ async def close(self, delete: bool = True) -> typing.Optional[Message]:
389
384
"""
390
385
self .running = False
391
386
392
- try :
393
- await self .ctx .message .add_reaction ('✅' )
394
- except (HTTPException , InvalidArgument ):
395
- pass
387
+ self .ctx .bot .loop .create_task (self .ctx .message .add_reaction ("✅" ))
396
388
397
389
if delete :
398
390
return await self .base .delete ()
0 commit comments