add-from-ec: use the last public dump of EC's emotes

This commit is contained in:
io mintz 2021-06-03 07:46:19 +00:00
parent a4e4120a63
commit c1592969d5
2 changed files with 101499 additions and 20 deletions

View File

@ -18,6 +18,7 @@ import cgi
import collections import collections
import contextlib import contextlib
import io import io
import json
import logging import logging
import operator import operator
import posixpath import posixpath
@ -28,14 +29,12 @@ import zipfile
import warnings import warnings
import weakref import weakref
import aioec
import aiohttp import aiohttp
import discord import discord
import humanize import humanize
from discord.ext import commands from discord.ext import commands
import utils import utils
import utils.archive
import utils.image import utils.image
from utils import errors from utils import errors
from utils.converter import emote_type_filter_default from utils.converter import emote_type_filter_default
@ -76,17 +75,15 @@ class Emotes(commands.Cog):
+ self.bot.http.user_agent + self.bot.http.user_agent
}) })
self.aioec = aioec.Client( with open('data/ec-emotes-final.json') as f:
loop=self.bot.loop, self.ec_emotes = json.load(f)
connector=connector,
base_url=self.bot.config.get('ec_api_base_url'))
# keep track of paginators so we can end them when the cog is unloaded # keep track of paginators so we can end them when the cog is unloaded
self.paginators = weakref.WeakSet() self.paginators = weakref.WeakSet()
def cog_unload(self): def cog_unload(self):
async def close(): async def close():
await self.http.close() await self.http.close()
await self.aioec.close()
for paginator in self.paginators: for paginator in self.paginators:
await paginator.stop() await paginator.stop()
@ -212,31 +209,25 @@ class Emotes(commands.Cog):
@commands.command(name='add-from-ec', aliases=['addfromec']) @commands.command(name='add-from-ec', aliases=['addfromec'])
async def add_from_ec(self, context, name, *names): async def add_from_ec(self, context, name, *names):
"""Copies one or more emotes from Emote Collector to your server. """Copies one or more emotes from Emote Collector to your server."""
The list of possible emotes you can copy is here:
https://ec.emote.bot/list
"""
if names: if names:
for name in (name,) + names: for name in (name,) + names:
await context.invoke(self.add_from_ec, name) await context.invoke(self.add_from_ec, name)
await context.message.add_reaction(utils.SUCCESS_EMOJIS[True])
return return
name = name.strip(':')
try: try:
emote = await self.aioec.emote(name) emote = self.ec_emotes[name.strip(':').lower()]
except aioec.NotFound: except KeyError:
return await context.send("Emote not found in Emote Collector's database.") return await context.send("Emote not found in Emote Collector's database.")
except aioec.HttpException as exception:
return await context.send(
f'Error: the Emote Collector API returned status code {exception.status}')
reason = ( reason = (
f'Added from Emote Collector by {utils.format_user(self.bot, context.author.id)}. ' f'Added from Emote Collector by {utils.format_user(self.bot, context.author.id)}. '
f'Original emote author: {utils.format_user(self.bot, emote.author)}') f'Original emote author: {utils.format_user(self.bot, emote["author"])}')
image_url = utils.emote.url(emote['id'], animated=emote['animated'])
async with context.typing(): async with context.typing():
message = await self.add_safe(context, name, emote.url, context.author.id, reason=reason) message = await self.add_safe(context, name, image_url, context.author.id, reason=reason)
await context.send(message) await context.send(message)

101488
data/ec-emotes-final.json Normal file

File diff suppressed because it is too large Load Diff