mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 03:38:53 -05:00
Allow menu() to listen to both adding and removing reactions (#4517)
This commit is contained in:
parent
a9dc93cf81
commit
34b912bc7c
@ -88,11 +88,20 @@ async def menu(
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
react, user = await ctx.bot.wait_for(
|
predicates = ReactionPredicate.with_emojis(tuple(controls.keys()), message, ctx.author)
|
||||||
"reaction_add",
|
tasks = [
|
||||||
check=ReactionPredicate.with_emojis(tuple(controls.keys()), message, ctx.author),
|
asyncio.ensure_future(ctx.bot.wait_for("reaction_add", check=predicates)),
|
||||||
timeout=timeout,
|
asyncio.ensure_future(ctx.bot.wait_for("reaction_remove", check=predicates)),
|
||||||
|
]
|
||||||
|
done, pending = await asyncio.wait(
|
||||||
|
tasks, timeout=timeout, return_when=asyncio.FIRST_COMPLETED
|
||||||
)
|
)
|
||||||
|
for task in pending:
|
||||||
|
task.cancel()
|
||||||
|
|
||||||
|
if len(done) == 0:
|
||||||
|
raise asyncio.TimeoutError()
|
||||||
|
react, user = done.pop().result()
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
if not ctx.me:
|
if not ctx.me:
|
||||||
return
|
return
|
||||||
@ -126,10 +135,6 @@ async def next_page(
|
|||||||
timeout: float,
|
timeout: float,
|
||||||
emoji: str,
|
emoji: str,
|
||||||
):
|
):
|
||||||
perms = message.channel.permissions_for(ctx.me)
|
|
||||||
if perms.manage_messages: # Can manage messages, so remove react
|
|
||||||
with contextlib.suppress(discord.NotFound):
|
|
||||||
await message.remove_reaction(emoji, ctx.author)
|
|
||||||
if page == len(pages) - 1:
|
if page == len(pages) - 1:
|
||||||
page = 0 # Loop around to the first item
|
page = 0 # Loop around to the first item
|
||||||
else:
|
else:
|
||||||
@ -146,10 +151,6 @@ async def prev_page(
|
|||||||
timeout: float,
|
timeout: float,
|
||||||
emoji: str,
|
emoji: str,
|
||||||
):
|
):
|
||||||
perms = message.channel.permissions_for(ctx.me)
|
|
||||||
if perms.manage_messages: # Can manage messages, so remove react
|
|
||||||
with contextlib.suppress(discord.NotFound):
|
|
||||||
await message.remove_reaction(emoji, ctx.author)
|
|
||||||
if page == 0:
|
if page == 0:
|
||||||
page = len(pages) - 1 # Loop around to the last item
|
page = len(pages) - 1 # Loop around to the last item
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user