From c2e5e3f5f6f225b1367905682ec21bd814bb7a2f Mon Sep 17 00:00:00 2001 From: Asterisk* <226386-aster.codes@users.noreply.gitlab.com> Date: Wed, 7 Jul 2021 23:04:28 -0400 Subject: [PATCH 1/3] Fixed issue in blurple.io.reply.Reply._validate_reply. Documentation states that Reply super classes should be able to accept a Callable and the Callable will recieve the reply object. Currently the Callable does not recieve the reply object. --- blurple/io/reply.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/blurple/io/reply.py b/blurple/io/reply.py index 99ab387..ac1bc5c 100644 --- a/blurple/io/reply.py +++ b/blurple/io/reply.py @@ -1,13 +1,14 @@ from __future__ import annotations -import re + +import asyncio import inspect +import re import typing as t from abc import ABC -import discord -from discord.ext import commands -import asyncio import blurple.ui as ui +import discord +from discord.ext import commands class Reply(ABC): @@ -131,8 +132,8 @@ async def _validate_reply(cls, reply, valid: t.Union[str, t.Container, t.Callabl return content in valid if callable(valid): if inspect.iscoroutinefunction(object): - return await valid() - return valid() + return await valid(reply) + return valid(reply) @staticmethod def _get_reply_content(reply): From 06254f5f4b7bb27ddc01b30951435d3a9b9a2a7b Mon Sep 17 00:00:00 2001 From: Asterisk* <226386-aster.codes@users.noreply.gitlab.com> Date: Wed, 7 Jul 2021 23:27:31 -0400 Subject: [PATCH 2/3] Suggestion: Separate ReactionAddReply into two classes. Because ReactionAddReply uses message.remove_reaction() and message.clear_reactions(), they cannot be used in direct messages. This PR separates ReactionAddReply into two classes DirectMessageReactionAddReply(ReactionAddBasic) which takes on_reply_init and reply_check ReactionAddReply(DirectMessageReactionAddReply) which adds on_reply_attempt and on_reply_complete ---- Having a class that works by default with DM's seems like a fairly common use case. --- blurple/io/reaction.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/blurple/io/reaction.py b/blurple/io/reaction.py index 0476309..5c36aea 100644 --- a/blurple/io/reaction.py +++ b/blurple/io/reaction.py @@ -1,6 +1,5 @@ -import discord - import blurple.io as io +import discord class ReactionAddBasic(io.Reply): @@ -24,7 +23,7 @@ class ReactionRemoveBasic(ReactionAddBasic): event = "raw_reaction_remove" -class ReactionAddReply(ReactionAddBasic): +class DirectMessageReactionAddReply(ReactionAddBasic): """ Ask for the user's reaction reply. :Example Usage: @@ -45,6 +44,8 @@ def reply_check(self, payload: discord.RawReactionActionEvent): return payload.user_id == self.ctx.author.id and \ payload.message_id == self.message.id + +class ReactionAddReply(DirectMessageReactionAddReply): async def on_reply_attempt(self, payload: discord.RawReactionActionEvent): """Specialized to remove the user's reaction.""" await self.message.remove_reaction(payload.emoji, self.ctx.bot.get_user(payload.user_id)) From 20afb56c4d07343862bb32caea2bcd342f924249 Mon Sep 17 00:00:00 2001 From: Asterisk* <226386-aster.codes@users.noreply.gitlab.com> Date: Wed, 7 Jul 2021 23:27:59 -0400 Subject: [PATCH 3/3] Added additional documentation. --- blurple/io/reaction.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/blurple/io/reaction.py b/blurple/io/reaction.py index 5c36aea..6126fdb 100644 --- a/blurple/io/reaction.py +++ b/blurple/io/reaction.py @@ -24,7 +24,7 @@ class ReactionRemoveBasic(ReactionAddBasic): class DirectMessageReactionAddReply(ReactionAddBasic): - """ Ask for the user's reaction reply. + """ Ask for the user's reaction reply. Safe to use in Direct Messages. :Example Usage: .. code-block:: python @@ -46,6 +46,13 @@ def reply_check(self, payload: discord.RawReactionActionEvent): class ReactionAddReply(DirectMessageReactionAddReply): + """ Ask for the user's reaction reply. + + :Example Usage: + .. code-block:: python + + reply = await io.ReactionAddBasic(ctx, validate=["✅", "❎"]).result() + """ async def on_reply_attempt(self, payload: discord.RawReactionActionEvent): """Specialized to remove the user's reaction.""" await self.message.remove_reaction(payload.emoji, self.ctx.bot.get_user(payload.user_id))