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

add list command

This commit is contained in:
bmintz 2018-07-30 00:43:30 -05:00
parent 52bd87300a
commit 9eac167a57
2 changed files with 30 additions and 0 deletions

View file

@ -5,6 +5,7 @@ import io
import imghdr
import asyncio
import logging
import weakref
import traceback
import contextlib
@ -23,6 +24,7 @@ from discord.ext import commands
import utils
import utils.image
from utils import errors
from utils.paginator import ListPaginator
class Emotes:
def __init__(self, bot):
@ -32,6 +34,17 @@ class Emotes:
self.bot.config['user_agent'] + ' '
+ self.bot.http.user_agent
})
# keep track of paginators so we can end them when the cog is unloaded
self.paginators = weakref.WeakSet()
def __unload(self):
self.bot.loop.create_task(self.http.close())
async def stop_all_paginators():
for paginator in self.paginators:
await paginator.stop()
self.bot.loop.create_task(stop_all_paginators())
async def __local_check(self, context):
if not context.guild:
@ -171,6 +184,20 @@ class Emotes:
await context.send(f'Emote \:{old_name}: successfully renamed to \:{new_name}:')
@commands.command()
async def list(self, context):
emotes = sorted(
filter(lambda e: e.require_colons, context.guild.emojis),
key=lambda e: e.name.lower())
processed = []
for emote in emotes:
processed.append(f'{emote} (\:{emote.name}:)')
paginator = ListPaginator(context, processed)
self.paginators.add(paginator)
await paginator.begin()
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:

View file

@ -4,3 +4,6 @@
from .misc import *
from . import emote
from . import errors
from . import paginator
# note: do not import .image in case the user doesn't want it
# since importing image can take a long time.