From 27e86de7bae9f69c0176a1eb262ac341075a1baa Mon Sep 17 00:00:00 2001 From: Harold Karibiye Date: Thu, 24 Sep 2020 03:33:42 +0100 Subject: add modified files modify code to work on all platforms, fix grammatical errors --- bot/exts/evergreen/minesweeper.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/minesweeper.py b/bot/exts/evergreen/minesweeper.py index 3e40f493..286ac7a5 100644 --- a/bot/exts/evergreen/minesweeper.py +++ b/bot/exts/evergreen/minesweeper.py @@ -120,14 +120,14 @@ class Minesweeper(commands.Cog): def format_for_discord(board: GameBoard) -> str: """Format the board as a string for Discord.""" discord_msg = ( - ":stop_button: :regional_indicator_a::regional_indicator_b::regional_indicator_c:" - ":regional_indicator_d::regional_indicator_e::regional_indicator_f::regional_indicator_g:" - ":regional_indicator_h::regional_indicator_i::regional_indicator_j:\n\n" + ":stop_button: :regional_indicator_a: :regional_indicator_b: :regional_indicator_c: " + ":regional_indicator_d: :regional_indicator_e: :regional_indicator_f: :regional_indicator_g: " + ":regional_indicator_h: :regional_indicator_i: :regional_indicator_j:\n\n" ) rows = [] for row_number, row in enumerate(board): new_row = f"{MESSAGE_MAPPING[row_number + 1]} " - new_row += "".join(MESSAGE_MAPPING[cell] for cell in row) + new_row += " ".join(MESSAGE_MAPPING[cell] for cell in row) rows.append(new_row) discord_msg += "\n".join(rows) @@ -158,7 +158,7 @@ class Minesweeper(commands.Cog): if ctx.guild: await ctx.send(f"{ctx.author.mention} is playing Minesweeper") - chat_msg = await ctx.send(f"Here's there board!\n{self.format_for_discord(revealed_board)}") + chat_msg = await ctx.send(f"Here's their board!\n{self.format_for_discord(revealed_board)}") else: chat_msg = None @@ -176,7 +176,7 @@ class Minesweeper(commands.Cog): await game.dm_msg.delete() game.dm_msg = await ctx.author.send(f"Here's your board!\n{self.format_for_discord(game.revealed)}") if game.activated_on_server: - await game.chat_msg.edit(content=f"Here's there board!\n{self.format_for_discord(game.revealed)}") + await game.chat_msg.edit(content=f"Here's their board!\n{self.format_for_discord(game.revealed)}") @commands.dm_only() @minesweeper_group.command(name="flag") -- cgit v1.2.3 From 3534937b2563b96d5f5aebe5389ef5e4b3f3c4c8 Mon Sep 17 00:00:00 2001 From: Anubhav1603 Date: Tue, 29 Sep 2020 13:32:57 +0530 Subject: added github url of seasonal bot --- bot/constants.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'bot') diff --git a/bot/constants.py b/bot/constants.py index 7c8f72cb..417f384c 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -265,3 +265,6 @@ POSITIVE_REPLIES = [ class Wikipedia: total_chance = 3 + +class Source: + github = "https://github.com/python-discord/seasonalbot" -- cgit v1.2.3 From bd3dd9fa32a4f871b7033f0d322e5b675d51b8b1 Mon Sep 17 00:00:00 2001 From: Anubhav1603 Date: Tue, 29 Sep 2020 13:41:59 +0530 Subject: added source command --- bot/exts/evergreen/source.py | 126 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 bot/exts/evergreen/source.py (limited to 'bot') diff --git a/bot/exts/evergreen/source.py b/bot/exts/evergreen/source.py new file mode 100644 index 00000000..164430e2 --- /dev/null +++ b/bot/exts/evergreen/source.py @@ -0,0 +1,126 @@ +import inspect +from pathlib import Path +from typing import Optional, Tuple, Union + +from discord import Embed +from discord.ext import commands + +from bot.constants import Source + +SourceType = Union[commands.HelpCommand, commands.Command, commands.Cog, str, commands.ExtensionNotLoaded] + + +class SourceConverter(commands.Converter): + """Convert an argument into a help command, tag, command, or cog.""" + + async def convert(self, ctx: commands.Context, argument: str) -> SourceType: + """Convert argument into source object.""" + cog = ctx.bot.get_cog(argument) + if cog: + return cog + + cmd = ctx.bot.get_command(argument) + if cmd: + return cmd + + raise commands.BadArgument( + f"Unable to convert `{argument}` to valid command or Cog." + ) + + +class BotSource(commands.Cog): + """Displays information about the bot's source code.""" + + def __init__(self, bot: commands.Bot): + self.bot = bot + + @commands.command(name="source", aliases=("src",)) + async def source_command(self, ctx: commands.Context, *, source_item: SourceConverter = None) -> None: + """Display information and a GitHub link to the source code of a command, tag, or cog.""" + if not source_item: + embed = Embed(title="Bot's GitHub Repository") + embed.add_field(name="Repository", value=f"[Go to GitHub]({Source.github})") + embed.set_thumbnail(url="https://avatars1.githubusercontent.com/u/9919") + await ctx.send(embed=embed) + return + + embed = await self.build_embed(source_item) + await ctx.send(embed=embed) + + def get_source_link(self, source_item: SourceType) -> Tuple[str, str, Optional[int]]: + """ + Build GitHub link of source item, return this link, file location and first line number. + + Raise BadArgument if `source_item` is a dynamically-created object (e.g. via internal eval). + """ + if isinstance(source_item, commands.Command): + if source_item.cog_name == "Alias": + cmd_name = source_item.callback.__name__.replace("_alias", "") + cmd = self.bot.get_command(cmd_name.replace("_", " ")) + src = cmd.callback.__code__ + filename = src.co_filename + else: + src = source_item.callback.__code__ + filename = src.co_filename + else: + src = type(source_item) + try: + filename = inspect.getsourcefile(src) + except TypeError: + raise commands.BadArgument("Cannot get source for a dynamically-created object.") + + if not isinstance(source_item, str): + try: + lines, first_line_no = inspect.getsourcelines(src) + except OSError: + raise commands.BadArgument("Cannot get source for a dynamically-created object.") + + lines_extension = f"#L{first_line_no}-L{first_line_no+len(lines)-1}" + else: + first_line_no = None + lines_extension = "" + + # Handle tag file location differently than others to avoid errors in some cases + if not first_line_no: + file_location = Path(filename).relative_to("/bot/") + else: + file_location = Path(filename).relative_to(Path.cwd()).as_posix() + + url = f"{Source.github}/blob/master/{file_location}{lines_extension}" + + return url, file_location, first_line_no or None + + async def build_embed(self, source_object: SourceType) -> Optional[Embed]: + """Build embed based on source object.""" + url, location, first_line = self.get_source_link(source_object) + + if isinstance(source_object, commands.HelpCommand): + title = "Help Command" + description = source_object.__doc__.splitlines()[1] + elif isinstance(source_object, commands.Command): + if source_object.cog_name == "Alias": + cmd_name = source_object.callback.__name__.replace("_alias", "") + cmd = self.bot.get_command(cmd_name.replace("_", " ")) + description = cmd.short_doc + else: + description = source_object.short_doc + + title = f"Command: {source_object.qualified_name}" + elif isinstance(source_object, str): + title = f"Tag: {source_object}" + description = "" + else: + title = f"Cog: {source_object.qualified_name}" + description = source_object.description.splitlines()[0] + + embed = Embed(title=title, description=description) + embed.add_field(name="Source Code", value=f"[Go to GitHub]({url})") + line_text = f":{first_line}" if first_line else "" + embed.set_footer(text=f"{location}{line_text}") + + return embed + + +def setup(bot: commands.Bot) -> None: + """Load the BotSource cog.""" + bot.add_cog(BotSource(bot)) -- cgit v1.2.3 From e1e0e158e0b42b2bdb488646e8e86cb4a704c683 Mon Sep 17 00:00:00 2001 From: Anubhav1603 Date: Thu, 1 Oct 2020 10:52:45 +0530 Subject: added source command --- bot/exts/evergreen/source.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/source.py b/bot/exts/evergreen/source.py index 164430e2..62b5f6bb 100644 --- a/bot/exts/evergreen/source.py +++ b/bot/exts/evergreen/source.py @@ -15,6 +15,9 @@ class SourceConverter(commands.Converter): async def convert(self, ctx: commands.Context, argument: str) -> SourceType: """Convert argument into source object.""" + if argument.lower().startswith("help"): + return ctx.bot.help_command + cog = ctx.bot.get_cog(argument) if cog: return cog @@ -38,9 +41,9 @@ class BotSource(commands.Cog): async def source_command(self, ctx: commands.Context, *, source_item: SourceConverter = None) -> None: """Display information and a GitHub link to the source code of a command, tag, or cog.""" if not source_item: - embed = Embed(title="Bot's GitHub Repository") + embed = Embed(title="Seasonal Bot's GitHub Repository") embed.add_field(name="Repository", value=f"[Go to GitHub]({Source.github})") - embed.set_thumbnail(url="https://avatars1.githubusercontent.com/u/9919") + embed.set_thumbnail(url="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png") await ctx.send(embed=embed) return @@ -114,6 +117,7 @@ class BotSource(commands.Cog): description = source_object.description.splitlines()[0] embed = Embed(title=title, description=description) + embed.set_thumbnail(url="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png") embed.add_field(name="Source Code", value=f"[Go to GitHub]({url})") line_text = f":{first_line}" if first_line else "" embed.set_footer(text=f"{location}{line_text}") -- cgit v1.2.3 From 8f5494727d81be7190537f130ef9b384c9e72285 Mon Sep 17 00:00:00 2001 From: Anubhav1603 Date: Thu, 1 Oct 2020 13:44:09 +0530 Subject: inital commit --- bot/exts/evergreen/emoji_count.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 bot/exts/evergreen/emoji_count.py (limited to 'bot') diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji_count.py new file mode 100644 index 00000000..b619f349 --- /dev/null +++ b/bot/exts/evergreen/emoji_count.py @@ -0,0 +1,29 @@ +import logging + +from discord.ext import commands + +log = logging.getLogger(__name__) + + +class EmojiCount(commands.Cog): + """Command that give random emoji based on category.""" + + def __init__(self, bot: commands.Bot): + self.bot = bot + + @commands.command(name="ec") + async def ec(self, ctx, emoj: str): + """Returns embed with emoji category and info given by user.""" + emoji = [] + for a in ctx.guild.emojis: + for n in a.name.split('_'): + if len(n) == 1: + pass + elif n.name[0] == emoji.lower(): + emoji.append(a) + await ctx.send(emoji) + + +def setup(bot: commands.Bot) -> None: + """Emoji Count Cog load.""" + bot.add_cog(EmojiCount(bot)) -- cgit v1.2.3 From 2e8a0396586dfdb9eaff8a308ef39736ccdaffb3 Mon Sep 17 00:00:00 2001 From: Anubhav1603 Date: Thu, 1 Oct 2020 19:00:56 +0530 Subject: removed --- bot/exts/evergreen/emoji_count.py | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 bot/exts/evergreen/emoji_count.py (limited to 'bot') diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji_count.py deleted file mode 100644 index b619f349..00000000 --- a/bot/exts/evergreen/emoji_count.py +++ /dev/null @@ -1,29 +0,0 @@ -import logging - -from discord.ext import commands - -log = logging.getLogger(__name__) - - -class EmojiCount(commands.Cog): - """Command that give random emoji based on category.""" - - def __init__(self, bot: commands.Bot): - self.bot = bot - - @commands.command(name="ec") - async def ec(self, ctx, emoj: str): - """Returns embed with emoji category and info given by user.""" - emoji = [] - for a in ctx.guild.emojis: - for n in a.name.split('_'): - if len(n) == 1: - pass - elif n.name[0] == emoji.lower(): - emoji.append(a) - await ctx.send(emoji) - - -def setup(bot: commands.Bot) -> None: - """Emoji Count Cog load.""" - bot.add_cog(EmojiCount(bot)) -- cgit v1.2.3 From 1f2d9a09b4aabbae0f5859ea0d909e80aaef194a Mon Sep 17 00:00:00 2001 From: Anubhav1603 Date: Fri, 2 Oct 2020 16:53:59 +0530 Subject: added embed_builder_method,error_embed_method --- bot/exts/evergreen/emoji_count.py | 80 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 bot/exts/evergreen/emoji_count.py (limited to 'bot') diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji_count.py new file mode 100644 index 00000000..2f20dbed --- /dev/null +++ b/bot/exts/evergreen/emoji_count.py @@ -0,0 +1,80 @@ +import datetime +import logging +import random +from typing import Dict, Optional + +import discord +from discord.ext import commands + +from bot.constants import Colours + +log = logging.getLogger(__name__) + + +class EmojiCount(commands.Cog): + """Command that give random emoji based on category.""" + + def __init__(self, bot: commands.Bot): + self.bot = bot + + def embed_builder(self, emoji: dict) -> discord.Embed: + """Genrates embed with emoji name and count.""" + embed = discord.Embed() + embed.color = Colours.orange + embed.title = "Emoji Count" + 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}' + embed.description = msg + return embed + + @staticmethod + def generate_invalid_embed(ctx) -> discord.Embed: + """Genrates error embed.""" + embed = discord.Embed() + embed.color = Colours.soft_red + embed.title = "Invalid Input" + emoji_dict = {} + for emoji in ctx.guild.emojis: + emoji_dict.update({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}```" + return embed + + def emoji_list(self, ctx, emojis: dict) -> Dict: + """Genrates dictionary of emojis given by the user.""" + for emoji in ctx.guild.emojis: + for key, value in emojis.items(): + if emoji.name.split("_")[0] == key: + value.append(emoji) + return emojis + + @commands.command(name="ec") + async def ec(self, ctx, *, emoji: str = None) -> Optional[str]: + """Returns embed with emoji category and info given by user.""" + emoji_dict = {} + for a in ctx.guild.emojis: + if emoji is None: + emoji_dict.update({a.name.split("_")[0]: []}) + elif a.name.split("_")[0] in emoji: + emoji_dict.update({a.name.split("_")[0]: []}) + emoji_dict = self.emoji_list(ctx, emoji_dict) + if len(emoji_dict) == 0: + embed = self.generate_invalid_embed(ctx) + else: + embed = self.embed_builder(emoji_dict) + await ctx.send(embed=embed) + + +def setup(bot: commands.Bot) -> None: + """Emoji Count Cog load.""" + bot.add_cog(EmojiCount(bot)) -- cgit v1.2.3 From c9cdb2b5005bd20f881b5b7d2ed5fcef0d66b0c9 Mon Sep 17 00:00:00 2001 From: Anubhav1603 Date: Fri, 2 Oct 2020 17:03:07 +0530 Subject: added logging --- bot/exts/evergreen/emoji_count.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'bot') diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji_count.py index 2f20dbed..a90c1b7d 100644 --- a/bot/exts/evergreen/emoji_count.py +++ b/bot/exts/evergreen/emoji_count.py @@ -35,6 +35,7 @@ class EmojiCount(commands.Cog): error_msg = f'There are **{len(value)}** emojis in the **{key}** category\n' msg += f'<:{emoji_choice.name}:{emoji_choice.id}> {error_msg}' embed.description = msg + log.trace('Emoji embed sent') return embed @staticmethod @@ -48,6 +49,7 @@ class EmojiCount(commands.Cog): emoji_dict.update({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") return embed def emoji_list(self, ctx, emojis: dict) -> Dict: @@ -56,6 +58,7 @@ class EmojiCount(commands.Cog): for key, value in emojis.items(): if emoji.name.split("_")[0] == key: value.append(emoji) + log.trace("Emoji dict sent") return emojis @commands.command(name="ec") @@ -64,15 +67,20 @@ class EmojiCount(commands.Cog): emoji_dict = {} for a in ctx.guild.emojis: if emoji is None: + log.trace("Emoji Category doesn't provided by the user") emoji_dict.update({a.name.split("_")[0]: []}) elif a.name.split("_")[0] in emoji: + log.trace("Emoji Category provided by the user") emoji_dict.update({a.name.split("_")[0]: []}) emoji_dict = self.emoji_list(ctx, emoji_dict) if len(emoji_dict) == 0: embed = self.generate_invalid_embed(ctx) + log.trace("Error embed received") else: embed = self.embed_builder(emoji_dict) + log.trace("Emoji embed received") await ctx.send(embed=embed) + log.trace("Embed sent") def setup(bot: commands.Bot) -> None: -- cgit v1.2.3 From e9de05b77f886dffacca9cdee53dd1a424913fb9 Mon Sep 17 00:00:00 2001 From: Anubhav1603 Date: Fri, 2 Oct 2020 17:25:49 +0530 Subject: added ctx annotation --- bot/exts/evergreen/emoji_count.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji_count.py index a90c1b7d..fa0879ae 100644 --- a/bot/exts/evergreen/emoji_count.py +++ b/bot/exts/evergreen/emoji_count.py @@ -39,7 +39,7 @@ class EmojiCount(commands.Cog): return embed @staticmethod - def generate_invalid_embed(ctx) -> discord.Embed: + def generate_invalid_embed(ctx: commands.Context) -> discord.Embed: """Genrates error embed.""" embed = discord.Embed() embed.color = Colours.soft_red @@ -52,7 +52,7 @@ class EmojiCount(commands.Cog): log.trace("Error embed sent") return embed - def emoji_list(self, ctx, emojis: dict) -> Dict: + def emoji_list(self, ctx: commands.Context, emojis: dict) -> Dict: """Genrates dictionary of emojis given by the user.""" for emoji in ctx.guild.emojis: for key, value in emojis.items(): @@ -62,7 +62,7 @@ class EmojiCount(commands.Cog): return emojis @commands.command(name="ec") - async def ec(self, ctx, *, emoji: str = None) -> Optional[str]: + async def ec(self, ctx: commands.Context, *, emoji: str = None) -> Optional[str]: """Returns embed with emoji category and info given by user.""" emoji_dict = {} for a in ctx.guild.emojis: -- cgit v1.2.3 From 8cc34b61f59f685344654d35791d0a722dd3d735 Mon Sep 17 00:00:00 2001 From: Anubhav <57266248+Anubhav1603@users.noreply.github.com> Date: Fri, 2 Oct 2020 18:06:06 +0530 Subject: Update bot/exts/evergreen/emoji_count.py Co-authored-by: Matteo Bertucci --- bot/exts/evergreen/emoji_count.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji_count.py index fa0879ae..2e6c5638 100644 --- a/bot/exts/evergreen/emoji_count.py +++ b/bot/exts/evergreen/emoji_count.py @@ -18,7 +18,7 @@ class EmojiCount(commands.Cog): self.bot = bot def embed_builder(self, emoji: dict) -> discord.Embed: - """Genrates embed with emoji name and count.""" + """Generates an embed with the emoji names and count.""" embed = discord.Embed() embed.color = Colours.orange embed.title = "Emoji Count" -- cgit v1.2.3 From 7cf5afb3ac29b9752e4b89da7b0c8dacd4e6313a Mon Sep 17 00:00:00 2001 From: Anubhav <57266248+Anubhav1603@users.noreply.github.com> Date: Fri, 2 Oct 2020 18:07:43 +0530 Subject: Update bot/exts/evergreen/emoji_count.py Co-authored-by: Matteo Bertucci --- bot/exts/evergreen/emoji_count.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji_count.py index 2e6c5638..4b35c619 100644 --- a/bot/exts/evergreen/emoji_count.py +++ b/bot/exts/evergreen/emoji_count.py @@ -67,7 +67,7 @@ class EmojiCount(commands.Cog): emoji_dict = {} for a in ctx.guild.emojis: if emoji is None: - log.trace("Emoji Category doesn't provided by the user") + log.trace("Emoji Category not provided by the user") emoji_dict.update({a.name.split("_")[0]: []}) elif a.name.split("_")[0] in emoji: log.trace("Emoji Category provided by the user") -- cgit v1.2.3 From 40f0c0e5b5c361ca3acf5e39b55470d2b9ea0bc4 Mon Sep 17 00:00:00 2001 From: Anubhav <57266248+Anubhav1603@users.noreply.github.com> Date: Fri, 2 Oct 2020 18:10:04 +0530 Subject: removed update and added data to dict directly Co-authored-by: Matteo Bertucci --- bot/exts/evergreen/emoji_count.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji_count.py index 4b35c619..e9bd8c35 100644 --- a/bot/exts/evergreen/emoji_count.py +++ b/bot/exts/evergreen/emoji_count.py @@ -46,7 +46,7 @@ class EmojiCount(commands.Cog): embed.title = "Invalid Input" emoji_dict = {} for emoji in ctx.guild.emojis: - emoji_dict.update({emoji.name.split("_")[0]: []}) + 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") -- cgit v1.2.3 From 1c5f5837714b71ef93ee9eeac32e74df09a585d9 Mon Sep 17 00:00:00 2001 From: Anubhav1603 Date: Fri, 2 Oct 2020 18:15:41 +0530 Subject: changed error_msg to emoji_info --- bot/exts/evergreen/emoji_count.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji_count.py index fa0879ae..95e4c927 100644 --- a/bot/exts/evergreen/emoji_count.py +++ b/bot/exts/evergreen/emoji_count.py @@ -32,8 +32,8 @@ class EmojiCount(commands.Cog): 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') return embed @@ -61,7 +61,7 @@ class EmojiCount(commands.Cog): log.trace("Emoji dict sent") return emojis - @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.""" emoji_dict = {} -- cgit v1.2.3 From 480cc1b56077c76b42c9102ae6320c4801b1719b Mon Sep 17 00:00:00 2001 From: Anubhav1603 Date: Fri, 2 Oct 2020 18:31:40 +0530 Subject: removed print statement,changed logging msg and changed emoji list --- bot/exts/evergreen/emoji_count.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji_count.py index 95e4c927..ecdb12fa 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,7 +25,6 @@ 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: @@ -35,7 +34,7 @@ class EmojiCount(commands.Cog): 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,23 +42,25 @@ 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.update({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, categories) -> 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="emoji_count", aliases=["ec"]) async def ec(self, ctx: commands.Context, *, emoji: str = None) -> Optional[str]: -- cgit v1.2.3 From d4b4885751a0830f684ac8cd95636abe2439b432 Mon Sep 17 00:00:00 2001 From: Anubhav1603 Date: Fri, 2 Oct 2020 18:34:41 +0530 Subject: added annotation --- bot/exts/evergreen/emoji_count.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji_count.py index ecdb12fa..c303cb7e 100644 --- a/bot/exts/evergreen/emoji_count.py +++ b/bot/exts/evergreen/emoji_count.py @@ -51,7 +51,7 @@ class EmojiCount(commands.Cog): log.trace("Error embed built") return embed - def emoji_list(self, ctx, categories) -> Dict: + 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} @@ -64,7 +64,7 @@ class EmojiCount(commands.Cog): @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: -- cgit v1.2.3 From 276d3631ac260ac21f0825dba8aff9dfa0c107c0 Mon Sep 17 00:00:00 2001 From: Anubhav1603 Date: Fri, 2 Oct 2020 19:13:48 +0530 Subject: added github_avatar_url --- bot/constants.py | 1 + 1 file changed, 1 insertion(+) (limited to 'bot') diff --git a/bot/constants.py b/bot/constants.py index 417f384c..a0c9f31e 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -268,3 +268,4 @@ class Wikipedia: class Source: github = "https://github.com/python-discord/seasonalbot" + github_avatar_url = "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" -- cgit v1.2.3 From 696dce383d4fddb9fe1767ce014a1ca264a8758b Mon Sep 17 00:00:00 2001 From: Anubhav1603 Date: Fri, 2 Oct 2020 19:15:08 +0530 Subject: removed aliases and default help command --- bot/exts/evergreen/source.py | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/source.py b/bot/exts/evergreen/source.py index 62b5f6bb..206cf258 100644 --- a/bot/exts/evergreen/source.py +++ b/bot/exts/evergreen/source.py @@ -7,7 +7,7 @@ from discord.ext import commands from bot.constants import Source -SourceType = Union[commands.HelpCommand, commands.Command, commands.Cog, str, commands.ExtensionNotLoaded] +SourceType = Union[commands.Command, commands.Cog, str, commands.ExtensionNotLoaded] class SourceConverter(commands.Converter): @@ -15,9 +15,6 @@ class SourceConverter(commands.Converter): async def convert(self, ctx: commands.Context, argument: str) -> SourceType: """Convert argument into source object.""" - if argument.lower().startswith("help"): - return ctx.bot.help_command - cog = ctx.bot.get_cog(argument) if cog: return cog @@ -43,7 +40,7 @@ class BotSource(commands.Cog): if not source_item: embed = Embed(title="Seasonal Bot's GitHub Repository") embed.add_field(name="Repository", value=f"[Go to GitHub]({Source.github})") - embed.set_thumbnail(url="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png") + embed.set_thumbnail(url=Source.github_avatar_url) await ctx.send(embed=embed) return @@ -57,14 +54,8 @@ class BotSource(commands.Cog): Raise BadArgument if `source_item` is a dynamically-created object (e.g. via internal eval). """ if isinstance(source_item, commands.Command): - if source_item.cog_name == "Alias": - cmd_name = source_item.callback.__name__.replace("_alias", "") - cmd = self.bot.get_command(cmd_name.replace("_", " ")) - src = cmd.callback.__code__ - filename = src.co_filename - else: - src = source_item.callback.__code__ - filename = src.co_filename + src = source_item.callback.__code__ + filename = src.co_filename else: src = type(source_item) try: @@ -97,27 +88,19 @@ class BotSource(commands.Cog): """Build embed based on source object.""" url, location, first_line = self.get_source_link(source_object) - if isinstance(source_object, commands.HelpCommand): - title = "Help Command" - description = source_object.__doc__.splitlines()[1] - elif isinstance(source_object, commands.Command): - if source_object.cog_name == "Alias": - cmd_name = source_object.callback.__name__.replace("_alias", "") - cmd = self.bot.get_command(cmd_name.replace("_", " ")) - description = cmd.short_doc + if isinstance(source_object, commands.Command): + if source_object.cog_name == 'Help': + title = "Help Command" + description = source_object.__doc__.splitlines()[1] else: description = source_object.short_doc - - title = f"Command: {source_object.qualified_name}" - elif isinstance(source_object, str): - title = f"Tag: {source_object}" - description = "" + title = f"Command: {source_object.qualified_name}" else: title = f"Cog: {source_object.qualified_name}" description = source_object.description.splitlines()[0] embed = Embed(title=title, description=description) - embed.set_thumbnail(url="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png") + embed.set_thumbnail(url=Source.github_avatar_url) embed.add_field(name="Source Code", value=f"[Go to GitHub]({url})") line_text = f":{first_line}" if first_line else "" embed.set_footer(text=f"{location}{line_text}") -- cgit v1.2.3 From 38968a545f3f237542448e4853d18e274c63e86d Mon Sep 17 00:00:00 2001 From: Anubhav <57266248+Anubhav1603@users.noreply.github.com> Date: Sat, 3 Oct 2020 12:44:19 +0530 Subject: Update bot/exts/evergreen/emoji_count.py Co-authored-by: ks129 <45097959+ks129@users.noreply.github.com> --- bot/exts/evergreen/emoji_count.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji_count.py index 3ad0d61b..b32fd0ed 100644 --- a/bot/exts/evergreen/emoji_count.py +++ b/bot/exts/evergreen/emoji_count.py @@ -40,9 +40,10 @@ class EmojiCount(commands.Cog): @staticmethod def generate_invalid_embed(ctx: commands.Context) -> discord.Embed: """Genrates error embed.""" - embed = discord.Embed() - embed.color = Colours.soft_red - embed.title = random.choice(ERROR_REPLIES) + embed = discord.Embed( + color=Colours.soft_red, + title=random.choice(ERROR_REPLIES) + ) emoji_dict = {} for emoji in ctx.guild.emojis: emoji_dict[emoji.name.split("_")[0]] = [] -- cgit v1.2.3 From 33b2c6bb8de14d277709af3a24072d2b2e6e61f9 Mon Sep 17 00:00:00 2001 From: Anubhav <57266248+Anubhav1603@users.noreply.github.com> Date: Sat, 3 Oct 2020 12:44:32 +0530 Subject: Update bot/exts/evergreen/emoji_count.py Co-authored-by: ks129 <45097959+ks129@users.noreply.github.com> --- bot/exts/evergreen/emoji_count.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji_count.py index b32fd0ed..c8076922 100644 --- a/bot/exts/evergreen/emoji_count.py +++ b/bot/exts/evergreen/emoji_count.py @@ -19,10 +19,11 @@ class EmojiCount(commands.Cog): def embed_builder(self, emoji: dict) -> discord.Embed: """Generates an embed with the emoji names and count.""" - embed = discord.Embed() - embed.color = Colours.orange - embed.title = "Emoji Count" - embed.timestamp = datetime.datetime.utcnow() + embed = discord.Embed( + color=Colours.orange, + title="Emoji Count", + timestamp=datetime.datetime.utcnow() + ) if len(emoji) == 1: for key, value in emoji.items(): embed.description = f"There are **{len(value)}** emojis in the **{key}** category" -- cgit v1.2.3 From 3c418746112d020549fcbeac386aca0f18abebba Mon Sep 17 00:00:00 2001 From: Anubhav1603 Date: Sat, 3 Oct 2020 12:51:25 +0530 Subject: changed github_avatar_url --- bot/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/constants.py b/bot/constants.py index a0c9f31e..a9c9e23e 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -268,4 +268,4 @@ class Wikipedia: class Source: github = "https://github.com/python-discord/seasonalbot" - github_avatar_url = "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" + github_avatar_url = "https://avatars1.githubusercontent.com/u/9919" -- cgit v1.2.3 From 7c76f01c8dacdcd954758bcb5078672a86286f2c Mon Sep 17 00:00:00 2001 From: Anubhav1603 Date: Sat, 3 Oct 2020 13:23:58 +0530 Subject: removed unnecessary logging and added one space --- bot/exts/evergreen/emoji_count.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji_count.py index c8076922..70c5ff53 100644 --- a/bot/exts/evergreen/emoji_count.py +++ b/bot/exts/evergreen/emoji_count.py @@ -35,7 +35,6 @@ class EmojiCount(commands.Cog): 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 built') return embed @staticmethod @@ -45,12 +44,13 @@ class EmojiCount(commands.Cog): color=Colours.soft_red, 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 built") return embed def emoji_list(self, ctx: commands.Context, categories: dict) -> Dict: @@ -61,7 +61,6 @@ class EmojiCount(commands.Cog): category = emoji.name.split('_')[0] if category in out: out[category].append(emoji) - log.trace("Emoji dict built") return out @commands.command(name="emoji_count", aliases=["ec"]) @@ -78,12 +77,9 @@ class EmojiCount(commands.Cog): emoji_dict = self.emoji_list(ctx, emoji_dict) if len(emoji_dict) == 0: embed = self.generate_invalid_embed(ctx) - log.trace("Error embed received") else: embed = self.embed_builder(emoji_dict) - log.trace("Emoji embed received") await ctx.send(embed=embed) - log.trace("Embed sent") def setup(bot: commands.Bot) -> None: -- cgit v1.2.3 From fcc345ae802cfe7815e10bc13f972c6925f3c60f Mon Sep 17 00:00:00 2001 From: Anubhav1603 Date: Sun, 4 Oct 2020 12:24:31 +0530 Subject: cleaned the code --- bot/exts/evergreen/emoji_count.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'bot') diff --git a/bot/exts/evergreen/emoji_count.py b/bot/exts/evergreen/emoji_count.py index 70c5ff53..ef900199 100644 --- a/bot/exts/evergreen/emoji_count.py +++ b/bot/exts/evergreen/emoji_count.py @@ -24,6 +24,7 @@ class EmojiCount(commands.Cog): title="Emoji Count", timestamp=datetime.datetime.utcnow() ) + if len(emoji) == 1: for key, value in emoji.items(): embed.description = f"There are **{len(value)}** emojis in the **{key}** category" @@ -67,6 +68,7 @@ class EmojiCount(commands.Cog): async def ec(self, ctx: commands.Context, *, emoji: str = None) -> Optional[str]: """Returns embed with emoji category and info given by the user.""" emoji_dict = {} + for a in ctx.guild.emojis: if emoji is None: log.trace("Emoji Category not provided by the user") @@ -74,7 +76,9 @@ class EmojiCount(commands.Cog): elif a.name.split("_")[0] in emoji: log.trace("Emoji Category provided by the user") emoji_dict.update({a.name.split("_")[0]: []}) + emoji_dict = self.emoji_list(ctx, emoji_dict) + if len(emoji_dict) == 0: embed = self.generate_invalid_embed(ctx) else: -- cgit v1.2.3 From 2a415d883fa79d9c421cec07becf7c1f846788da Mon Sep 17 00:00:00 2001 From: Anubhav1603 Date: Sun, 4 Oct 2020 12:35:37 +0530 Subject: removed tag handling --- bot/exts/evergreen/source.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/source.py b/bot/exts/evergreen/source.py index 206cf258..0725714f 100644 --- a/bot/exts/evergreen/source.py +++ b/bot/exts/evergreen/source.py @@ -74,11 +74,7 @@ class BotSource(commands.Cog): first_line_no = None lines_extension = "" - # Handle tag file location differently than others to avoid errors in some cases - if not first_line_no: - file_location = Path(filename).relative_to("/bot/") - else: - file_location = Path(filename).relative_to(Path.cwd()).as_posix() + file_location = Path(filename).relative_to(Path.cwd()).as_posix() url = f"{Source.github}/blob/master/{file_location}{lines_extension}" -- cgit v1.2.3