aboutsummaryrefslogtreecommitdiffstats
path: root/bot
diff options
context:
space:
mode:
authorGravatar Anubhav1603 <[email protected]>2020-10-05 13:36:16 +0530
committerGravatar Anubhav1603 <[email protected]>2020-10-05 13:36:16 +0530
commitadb5d2db1a01cc32bab10286a617e27853349ff8 (patch)
treedd03e8964f566926b59fba056b705ba1e022e48e /bot
parentremoved emoji list and added default dict (diff)
corrected annotation
Diffstat (limited to 'bot')
-rw-r--r--bot/exts/evergreen/emoji_count.py28
1 files changed, 13 insertions, 15 deletions
diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji_count.py
index 544a0019..c030fa75 100644
--- a/bot/exts/evergreen/emoji_count.py
+++ b/bot/exts/evergreen/emoji_count.py
@@ -1,7 +1,6 @@
import datetime
import logging
import random
-from typing import Optional
from collections import defaultdict
import discord
@@ -19,49 +18,49 @@ class EmojiCount(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
- def embed_builder(self, emoji: dict) -> discord.Embed:
+ def embed_builder(self, emoji: dict) -> [discord.Embed, str]:
"""Generates an embed with the emoji names and count."""
embed = discord.Embed(
color=Colours.orange,
title="Emoji Count",
timestamp=datetime.datetime.utcnow()
)
+ msg = []
if len(emoji) == 1:
for key, value in emoji.items():
- msg = f"There are **{len(value)}** emojis in the **{key}** category"
+ msg.append(f"There are **{len(value)}** emojis in the **{key}** category")
embed.set_thumbnail(url=random.choice(value).url)
- embed.description = msg
+
else:
- msg = ''
for key, value in emoji.items():
emoji_choice = random.choice(value)
emoji_info = f'There are **{len(value)}** emojis in the **{key}** category\n'
if emoji_choice.animated:
- msg += f'<a:{emoji_choice.name}:{emoji_choice.id}> {emoji_info}'
+ msg.append(f'<a:{emoji_choice.name}:{emoji_choice.id}> {emoji_info}')
else:
- msg += f'<:{emoji_choice.name}:{emoji_choice.id}> {emoji_info}'
- embed.description = msg
+ msg.append(f'<:{emoji_choice.name}:{emoji_choice.id}> {emoji_info}')
return embed, msg
@staticmethod
- def generate_invalid_embed(ctx: commands.Context) -> discord.Embed:
+ def generate_invalid_embed(ctx: commands.Context) -> [discord.Embed, str]:
"""Genrates error embed."""
embed = discord.Embed(
color=Colours.soft_red,
title=random.choice(ERROR_REPLIES)
)
+ msg = []
- emoji_dict = {}
+ emoji_dict = defaultdict(list)
for emoji in ctx.guild.emojis:
- emoji_dict[emoji.name.split("_")[0]] = []
+ emoji_dict[emoji.name.split("_")[0]].append(emoji)
error_comp = ', '.join(key for key in emoji_dict.keys())
- msg = f"These are the valid categories\n```{error_comp}```"
+ msg.append(f"These are the valid categories\n```{error_comp}```")
return embed, msg
@commands.command(name="emoji_count", aliases=["ec"])
- async def ec(self, ctx: commands.Context, *, emoji_category: str = None) -> Optional[str]:
+ async def emoji_count(self, ctx: commands.Context, *, emoji_category: str = None) -> None:
"""Returns embed with emoji category and info given by the user."""
emoji_dict = defaultdict(list)
@@ -77,8 +76,7 @@ class EmojiCount(commands.Cog):
embed, msg = self.generate_invalid_embed(ctx)
else:
embed, msg = self.embed_builder(emoji_dict)
- msg = msg.split("\n")
- await LinePaginator.paginate([line for line in msg], ctx=ctx, embed=embed)
+ await LinePaginator.paginate(lines=msg, ctx=ctx, embed=embed)
def setup(bot: commands.Bot) -> None: