-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add confirmation upon q!deny/approve (fixes #5)
- Loading branch information
Showing
3 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import discord | ||
from discord.ext import commands | ||
|
||
|
||
class Context(commands.Context): | ||
async def confirm(self, description=None, *, embed=None, color=None): | ||
decision_emojis = [ | ||
self.bot.get_emoji(self.bot.config.approve_emoji_id), | ||
self.bot.get_emoji(self.bot.config.deny_emoji_id) | ||
] | ||
embed = embed or discord.Embed() | ||
embed.color = color or discord.Colour.red() | ||
embed.title = 'Are you sure?' | ||
embed.set_footer(text=str(self.author), icon_url=self.author.avatar_url) | ||
embed.description = description | ||
message = await self.send(embed=embed) | ||
for emoji in decision_emojis: | ||
await message.add_reaction(emoji) | ||
|
||
def check(reaction, user): | ||
return user == self.author and \ | ||
isinstance(reaction.emoji, discord.Emoji) and \ | ||
reaction.emoji in decision_emojis | ||
|
||
try: | ||
reaction, user = await self.bot.wait_for('reaction_add', check=check, timeout=60.0) | ||
except TimeoutError: | ||
await self.send('Timed out.') | ||
return | ||
result = reaction.emoji == decision_emojis[0] | ||
if not result: | ||
await self.send('Cancelled.') | ||
return result |