mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-22 10:47:58 -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:
@@ -8,9 +8,11 @@ from contextlib import redirect_stdout
|
||||
from copy import copy
|
||||
|
||||
import discord
|
||||
|
||||
from . import checks, commands
|
||||
from .i18n import Translator
|
||||
from .utils.chat_formatting import box, pagify
|
||||
from .utils.predicates import MessagePredicate
|
||||
|
||||
"""
|
||||
Notice:
|
||||
@@ -218,12 +220,8 @@ class Dev(commands.Cog):
|
||||
self.sessions.add(ctx.channel.id)
|
||||
await ctx.send(_("Enter code to execute or evaluate. `exit()` or `quit` to exit."))
|
||||
|
||||
msg_check = lambda m: (
|
||||
m.author == ctx.author and m.channel == ctx.channel and m.content.startswith("`")
|
||||
)
|
||||
|
||||
while True:
|
||||
response = await ctx.bot.wait_for("message", check=msg_check)
|
||||
response = await ctx.bot.wait_for("message", check=MessagePredicate.regex(r"^`", ctx))
|
||||
|
||||
cleaned = self.cleanup_code(response.content)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user