From c5152309a6e2bee64f3187638e79bc1d1b6911e8 Mon Sep 17 00:00:00 2001 From: bmintz Date: Mon, 30 Jul 2018 00:15:09 -0500 Subject: [PATCH] add remove command --- cogs/emoji.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/cogs/emoji.py b/cogs/emoji.py index cbcaa25..ca2a502 100644 --- a/cogs/emoji.py +++ b/cogs/emoji.py @@ -95,7 +95,6 @@ class Emotes: try: emote = await self.add_from_url(guild, name, url, author_id) except discord.HTTPException as ex: - logger.error(traceback.format_exc()) return ( 'An error occurred while creating the emote:\n' + utils.format_http_exception(ex)) @@ -206,6 +205,40 @@ class Emotes: return (old_width * new_height//old_height, new_height) return new_width, old_height * new_width//old_width + @commands.command() + async def remove(self, context, name): + emote = await self.disambiguate(context, name) + await emote.delete(reason=f'Removed by {utils.format_user(self.bot, context.author.id)}') + await context.send(f'Emote \:{emote.name}: successfully removed.') + + async def disambiguate(self, context, name): + candidates = [e for e in context.guild.emojis if e.name.lower() == name.lower() and e.require_colons] + if not candidates: + raise errors.EmoteNotFoundError(name) + + if len(candidates) == 1: + return candidates[0] + + message = ['Multiple emotes were found with that name. Which one do you mean?'] + for i, emote in enumerate(candidates, 1): + message.append(f'{i}. {emote} (\:{emote.name}:)') + + await context.send('\n'.join(message)) + + def check(message): + try: + int(message.content) + except ValueError: + return False + else: + return message.author == context.author + + try: + message = await self.bot.wait_for('message', check=check, timeout=30) + except asyncio.TimeoutError: + raise commands.UserInputError('Sorry, you took too long. Try again.') + + return candidates[int(message.content)-1] def setup(bot):