1
0
Fork 0
mirror of https://github.com/uhIgnacio/EmoteManager.git synced 2024-08-15 02:23:13 +00:00

add export command (closes #2)

This commit is contained in:
Io Mintz 2019-10-15 21:59:34 +00:00
parent a42f72f2f5
commit e32890fb60
4 changed files with 72 additions and 21 deletions

11
utils/converter.py Normal file
View file

@ -0,0 +1,11 @@
_emote_type_predicates = {
'': lambda _: True, # allow usage as a "consume rest" converter
'all': lambda _: True,
'static': lambda e: not e.animated,
'animated': lambda e: e.animated}
def emote_type_filter(argument):
try:
return _emote_type_predicates[argument.lower()]
except KeyError:
raise commands.BadArgument('Invalid emote type. Specify “static”, “animated”, “all”.')

View file

@ -1,10 +1,12 @@
#!/usr/bin/env python3
# encoding: utf-8
import discord
"""various utilities for use within the bot"""
import asyncio
import discord
def format_user(bot, id, *, mention=False):
"""Format a user ID for human readable display."""
user = bot.get_user(id)
@ -37,3 +39,16 @@ def strip_angle_brackets(string):
if string.startswith('<') and string.endswith('>'):
return string[1:-1]
return string
async def gather_or_cancel(*awaitables, loop=None):
"""run the awaitables in the sequence concurrently. If any of them raise an exception,
propagate the first exception raised and cancel all other awaitables.
"""
gather_task = asyncio.gather(*awaitables, loop=loop)
try:
return await gather_task
except asyncio.CancelledError:
raise
except:
gather_task.cancel()
raise