parent
16c8b4ebec
commit
a1123a0582
@ -1,33 +1,32 @@ |
||||
import asyncio |
||||
from typing import List, Callable, Awaitable |
||||
|
||||
import discord |
||||
from discord import Message, Embed, Emoji |
||||
from discord.ext.commands import Context |
||||
|
||||
|
||||
async def make_tabbed_message(ctx: Context, message: Message, emoji_ids: List[int], embeds: List[Embed], timeout=300): |
||||
emoji_ids = list(emoji_ids) |
||||
async def run_tabbed_message(ctx: Context, message: Message, emojis: List[Emoji], embeds: List[Embed], timeout=300): |
||||
async def callback(emoji, _ctx, _message): |
||||
await message.edit(embed=embeds[emojis.index(emoji)]) |
||||
|
||||
async def callback(emoji_id, _ctx, _message): |
||||
await message.edit(embed=embeds[emoji_ids.index(emoji_id)]) |
||||
await run_reaction_message(ctx, message, emojis, callback, timeout) |
||||
|
||||
await make_reaction_message(ctx, message, emoji_ids, callback, timeout) |
||||
|
||||
|
||||
async def make_reaction_message(ctx: Context, message: Message, emoji_ids: List[int], |
||||
callback: Callable[[int, Context, Message], Awaitable[None]], timeout=300): |
||||
for emoji_id in emoji_ids: |
||||
await message.add_reaction(ctx.bot.get_emoji(emoji_id)) |
||||
async def run_reaction_message(ctx: Context, message: Message, emojis: List[Emoji], |
||||
callback: Callable[[Emoji, Context, Message], Awaitable[None]], timeout=300): |
||||
for emoji in emojis: |
||||
await message.add_reaction(emoji) |
||||
|
||||
def check(rxn, usr): |
||||
return usr == ctx.author and rxn.emoji.id in emoji_ids and rxn.message.id == message.id |
||||
return usr == ctx.author and rxn.emoji in emojis and rxn.message.id == message.id |
||||
|
||||
while True: |
||||
try: |
||||
reaction, user = await ctx.bot.wait_for('reaction_add', timeout=timeout, check=check) |
||||
await callback(reaction.emoji.id, ctx, message) |
||||
await callback(reaction.emoji, ctx, message) |
||||
await message.remove_reaction(reaction, user) |
||||
except asyncio.TimeoutError: |
||||
for emoji_id in emoji_ids: |
||||
await message.remove_reaction(ctx.bot.get_emoji(emoji_id), ctx.bot.user) |
||||
for emoji in emojis: |
||||
await message.remove_reaction(ctx.bot.get_emoji(emoji), ctx.bot.user) |
||||
break |
||||
|
Loading…
Reference in new issue