mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-22 02:37:57 -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:
@@ -15,6 +15,7 @@ from redbot.core.i18n import Translator, cog_i18n
|
||||
from redbot.core.utils.mod import is_admin_or_superior
|
||||
from redbot.core.utils.chat_formatting import warning, pagify
|
||||
from redbot.core.utils.menus import menu, DEFAULT_CONTROLS
|
||||
from redbot.core.utils.predicates import MessagePredicate
|
||||
|
||||
_ = Translator("Warnings", __file__)
|
||||
|
||||
@@ -363,12 +364,11 @@ class Warnings(commands.Cog):
|
||||
"""Handles getting description and points for custom reasons"""
|
||||
to_add = {"points": 0, "description": ""}
|
||||
|
||||
def same_author_check(m):
|
||||
return m.author == ctx.author
|
||||
|
||||
await ctx.send(_("How many points should be given for this reason?"))
|
||||
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:
|
||||
await ctx.send(_("Ok then."))
|
||||
return
|
||||
@@ -385,7 +385,9 @@ class Warnings(commands.Cog):
|
||||
|
||||
await ctx.send(_("Enter a description for this reason."))
|
||||
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:
|
||||
await ctx.send(_("Ok then."))
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user