diff options
Diffstat (limited to 'bot')
| -rw-r--r-- | bot/exts/evergreen/emoji_count.py | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji_count.py index e9bd8c35..3ad0d61b 100644 --- a/bot/exts/evergreen/emoji_count.py +++ b/bot/exts/evergreen/emoji_count.py @@ -6,7 +6,7 @@ from typing import Dict, Optional import discord from discord.ext import commands -from bot.constants import Colours +from bot.constants import Colours, ERROR_REPLIES log = logging.getLogger(__name__) @@ -25,17 +25,16 @@ class EmojiCount(commands.Cog): embed.timestamp = datetime.datetime.utcnow() if len(emoji) == 1: for key, value in emoji.items(): - print(key) embed.description = f"There are **{len(value)}** emojis in the **{key}** category" embed.set_thumbnail(url=random.choice(value).url) else: msg = '' for key, value in emoji.items(): emoji_choice = random.choice(value) - error_msg = f'There are **{len(value)}** emojis in the **{key}** category\n' - msg += f'<:{emoji_choice.name}:{emoji_choice.id}> {error_msg}' + emoji_info = f'There are **{len(value)}** emojis in the **{key}** category\n' + msg += f'<:{emoji_choice.name}:{emoji_choice.id}> {emoji_info}' embed.description = msg - log.trace('Emoji embed sent') + log.trace('Emoji embed built') return embed @staticmethod @@ -43,27 +42,29 @@ class EmojiCount(commands.Cog): """Genrates error embed.""" embed = discord.Embed() embed.color = Colours.soft_red - embed.title = "Invalid Input" + embed.title = random.choice(ERROR_REPLIES) emoji_dict = {} for emoji in ctx.guild.emojis: emoji_dict[emoji.name.split("_")[0]] = [] error_comp = ', '.join(key for key in emoji_dict.keys()) embed.description = f"These are the valid categories\n```{error_comp}```" - log.trace("Error embed sent") + log.trace("Error embed built") return embed - def emoji_list(self, ctx: commands.Context, emojis: dict) -> Dict: - """Genrates dictionary of emojis given by the user.""" + def emoji_list(self, ctx: commands.Context, categories: dict) -> Dict: + """Generates an embed with the emoji names and count.""" + out = {category: [] for category in categories} + for emoji in ctx.guild.emojis: - for key, value in emojis.items(): - if emoji.name.split("_")[0] == key: - value.append(emoji) - log.trace("Emoji dict sent") - return emojis + category = emoji.name.split('_')[0] + if category in out: + out[category].append(emoji) + log.trace("Emoji dict built") + return out - @commands.command(name="ec") + @commands.command(name="emoji_count", aliases=["ec"]) async def ec(self, ctx: commands.Context, *, emoji: str = None) -> Optional[str]: - """Returns embed with emoji category and info given by user.""" + """Returns embed with emoji category and info given by the user.""" emoji_dict = {} for a in ctx.guild.emojis: if emoji is None: |