mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-22 18:57:59 -05:00
[Utils] Finish and Refactor Predicate Utility (#2169)
* Uses classmethods to create predicates * Classmethods allow using a combination of different parameters to describe context * Some predicates assign a captured `result` to the predicate object on success * Added `ReactionPredicate` equivalent to `MessagePredicate` * Added `utils.menus.start_adding_reactions`, a non-blocking method for adding reactions asynchronously * Added documentation * Uses these new utils throughout the core bot Happened to also find some bugs in places, and places where we were waiting for events without catching `asyncio.TimeoutError` Signed-off-by: Toby Harradine <tobyharradine@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import discord
|
||||
|
||||
from redbot.core import Config, checks, commands
|
||||
from redbot.core.i18n import Translator
|
||||
from redbot.core.utils.predicates import MessagePredicate
|
||||
|
||||
_ = Translator("Warnings", __file__)
|
||||
|
||||
@@ -95,11 +96,10 @@ async def get_command_for_exceeded_points(ctx: commands.Context):
|
||||
|
||||
await ctx.send(_("You may enter your response now."))
|
||||
|
||||
def same_author_check(m):
|
||||
return m.author == ctx.author
|
||||
|
||||
try:
|
||||
msg = await ctx.bot.wait_for("message", check=same_author_check, timeout=30)
|
||||
msg = await ctx.bot.wait_for(
|
||||
"message", check=MessagePredicate.same_context(ctx), timeout=30
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
return None
|
||||
else:
|
||||
@@ -140,11 +140,10 @@ async def get_command_for_dropping_points(ctx: commands.Context):
|
||||
|
||||
await ctx.send(_("You may enter your response now."))
|
||||
|
||||
def same_author_check(m):
|
||||
return m.author == ctx.author
|
||||
|
||||
try:
|
||||
msg = await ctx.bot.wait_for("message", check=same_author_check, timeout=30)
|
||||
msg = await ctx.bot.wait_for(
|
||||
"message", check=MessagePredicate.same_context(ctx), timeout=30
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
return None
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user