diff options
| author | 2021-05-16 15:27:58 +0100 | |
|---|---|---|
| committer | 2021-05-16 15:27:58 +0100 | |
| commit | 0585e210949ef808417d181579081416fa73fd18 (patch) | |
| tree | d5f3a9102f420506f823ee9593857b4098d1af38 /bot/exts/evergreen/source.py | |
| parent | Change authors value in pyproject.toml (diff) | |
| parent | Spring cleanup (#718) (diff) | |
Merge branch 'main' into pipenv-to-poetry
Diffstat (limited to '')
| -rw-r--r-- | bot/exts/evergreen/source.py | 35 | 
1 files changed, 7 insertions, 28 deletions
| diff --git a/bot/exts/evergreen/source.py b/bot/exts/evergreen/source.py index cdfe54ec..8fb72143 100644 --- a/bot/exts/evergreen/source.py +++ b/bot/exts/evergreen/source.py @@ -1,39 +1,18 @@  import inspect  from pathlib import Path -from typing import Optional, Tuple, Union +from typing import Optional, Tuple  from discord import Embed  from discord.ext import commands +from bot.bot import Bot  from bot.constants import Source - -SourceType = Union[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." -        ) +from bot.utils.converters import SourceConverter, SourceType  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.""" @@ -76,7 +55,7 @@ class BotSource(commands.Cog):          file_location = Path(filename).relative_to(Path.cwd()).as_posix() -        url = f"{Source.github}/blob/master/{file_location}{lines_extension}" +        url = f"{Source.github}/blob/main/{file_location}{lines_extension}"          return url, file_location, first_line_no or None @@ -85,7 +64,7 @@ class BotSource(commands.Cog):          url, location, first_line = self.get_source_link(source_object)          if isinstance(source_object, commands.Command): -            if source_object.cog_name == 'Help': +            if source_object.cog_name == "Help":                  title = "Help Command"                  description = source_object.__doc__.splitlines()[1]              else: @@ -104,6 +83,6 @@ class BotSource(commands.Cog):          return embed -def setup(bot: commands.Bot) -> None: +def setup(bot: Bot) -> None:      """Load the BotSource cog.""" -    bot.add_cog(BotSource(bot)) +    bot.add_cog(BotSource()) | 
