Skip to content

Dm safe #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions blurple/io/reaction.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import discord

import blurple.io as io
import discord


class ReactionAddBasic(io.Reply):
Expand All @@ -24,8 +23,8 @@ class ReactionRemoveBasic(ReactionAddBasic):
event = "raw_reaction_remove"


class ReactionAddReply(ReactionAddBasic):
""" Ask for the user's reaction reply.
class DirectMessageReactionAddReply(ReactionAddBasic):
""" Ask for the user's reaction reply. Safe to use in Direct Messages.

:Example Usage:
.. code-block:: python
Expand All @@ -45,6 +44,15 @@ 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):
""" 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))
Expand Down
13 changes: 7 additions & 6 deletions blurple/io/reply.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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):
Expand Down