mirror of
https://github.com/uhIgnacio/EmoteManager.git
synced 2024-08-15 02:23:13 +00:00
Merge branch 'master' into metrics
This commit is contained in:
commit
5cb0f0adea
3 changed files with 101504 additions and 22 deletions
|
@ -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
101488
data/ec-emotes-final.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -14,9 +14,9 @@
|
||||||
# along with Emote Manager. If not, see <https://www.gnu.org/licenses/>.
|
# along with Emote Manager. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
|
from discord.ext.commands import BadArgument
|
||||||
|
|
||||||
_emote_type_predicates = {
|
_emote_type_predicates = {
|
||||||
'': lambda _: True, # allow usage as a "consume rest" converter
|
|
||||||
'all': lambda _: True,
|
'all': lambda _: True,
|
||||||
'static': lambda e: not e.animated,
|
'static': lambda e: not e.animated,
|
||||||
'animated': lambda e: e.animated}
|
'animated': lambda e: e.animated}
|
||||||
|
@ -28,7 +28,10 @@ def emote_type_filter_default(command):
|
||||||
@functools.wraps(old_callback)
|
@functools.wraps(old_callback)
|
||||||
async def callback(self, ctx, *args):
|
async def callback(self, ctx, *args):
|
||||||
image_type = args[-1]
|
image_type = args[-1]
|
||||||
image_type = _emote_type_predicates[image_type]
|
try:
|
||||||
|
image_type = _emote_type_predicates[image_type]
|
||||||
|
except KeyError:
|
||||||
|
raise BadArgument(f'Invalid emote type. Specify one of "all", "static", or "animated".')
|
||||||
return await old_callback(self, ctx, *args[:-1], image_type)
|
return await old_callback(self, ctx, *args[:-1], image_type)
|
||||||
|
|
||||||
command.callback = callback
|
command.callback = callback
|
||||||
|
|
Loading…
Reference in a new issue