-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
executable file
·56 lines (48 loc) · 1.8 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'''
Credit for this code goes to Aadi, from VandyHacks!
Check him out: https://github.com/aadibajpai
'''
from asyncio import TimeoutError
# emoji reactions
left = "⬅"
right = "➡"
async def paginate_embed(bot, channel, embeds):
"""
async def modifier_func(type, curr_page) type: 1 for forward, -1 for backward.
"""
total_pages = len(embeds)
curr_page = 0
og_msg = await channel.send(embed=embeds[curr_page].set_footer(text=f"Page {curr_page+1}/{total_pages}"))
if total_pages <= 1:
return
await og_msg.add_reaction(left)
await og_msg.add_reaction(right)
def check(reaction, user):
return (
not user.bot
and reaction.message.channel == channel
and reaction.message.id == og_msg.id
)
try:
while True:
reaction, user = await bot.wait_for(
"reaction_add", timeout=120.0, check=check
)
if str(reaction.emoji) == right:
if curr_page < total_pages - 1:
curr_page += 1
await og_msg.edit(
embed=embeds[curr_page].set_footer(text=f"Page {curr_page+1}/{total_pages}"))
await og_msg.remove_reaction(right, user)
elif str(reaction.emoji) == left:
if curr_page > 0:
curr_page -= 1
await og_msg.edit(
embed=embeds[curr_page].set_footer(text=f"Page {curr_page+1}/{total_pages}"))
await og_msg.remove_reaction(left, user)
else:
continue
except TimeoutError:
await og_msg.remove_reaction(left, bot.user)
await og_msg.remove_reaction(right, bot.user)
return