v 2.0.0
This commit is contained in:
1 parent
67ad573dd6
commit
d94d0b976a
12 files changed
+1244
-564
No files matched your search
@@ -0,0 +1,44 @@
|
||||
async def embed_list_paginated(bot, pre, items, item_fct, base_embed, footer_prefix='', msg=None, start=0, per_page=10):
|
||||
embed = base_embed
|
||||
|
||||
# generate list
|
||||
embed.title = f'{items.__len__()} entries'
|
||||
text = '\n'
|
||||
for item in items[start:start+per_page]:
|
||||
text += item_fct(item) + '\n'
|
||||
embed.description = text
|
||||
|
||||
# footer text
|
||||
#footer_text = f'Type {pre}show <label> to show a poll. '
|
||||
if start > 0:
|
||||
footer_prefix += f'React with ⏪ to show the last {per_page} entries. '
|
||||
if items.__len__() > start+per_page:
|
||||
footer_prefix += f'React with ⏩ to show the next {per_page} entries. '
|
||||
if footer_prefix.__len__() > 0:
|
||||
embed.set_footer(text=footer_prefix)
|
||||
|
||||
# post / edit message
|
||||
if msg is not None:
|
||||
await bot.edit_message(msg, embed=embed)
|
||||
await bot.clear_reactions(msg)
|
||||
else:
|
||||
msg = await bot.say(embed=embed)
|
||||
|
||||
# add reactions
|
||||
if start > 0:
|
||||
await bot.add_reaction(msg, '⏪')
|
||||
if items.__len__() > start+per_page:
|
||||
await bot.add_reaction(msg, '⏩')
|
||||
|
||||
# wait for reactions (2 minutes)
|
||||
def check(reaction, user):
|
||||
return reaction.emoji if user != bot.user else False
|
||||
res = await bot.wait_for_reaction(emoji=['⏪', '⏩'], message=msg, timeout=120, check=check)
|
||||
|
||||
# redirect on reaction
|
||||
if res is None:
|
||||
return
|
||||
elif res.reaction.emoji == '⏪' and start > 0:
|
||||
await embed_list_paginated(bot, pre, items, item_fct, base_embed, msg=msg, start=start-per_page, per_page=per_page)
|
||||
elif res.reaction.emoji == '⏩' and items.__len__() > start+per_page:
|
||||
await embed_list_paginated(bot, pre, items, item_fct, base_embed, msg=msg, start=start+per_page, per_page=per_page)
|
||||
Reference in new issue
Block a user