Repository: python-discord/bot

Issue:
Remove alias cog
Since the merging of #1124, only 3 alias commands remain, listed below. All usage statistics are since stats have been tracked, which is around April of 2020.

1. `!get docs` - alias for `!docs get`
    * Usage: 4 times
    * Usage of `!docs get`: 793 times
    * Usage of `!docs`: 9240 times (includes all the above and empty arg invocations)
2. `!get tags` - alias for `!tags get`
    * Usage: 0 times
    * Usage of `!tags get`: 4 times
    * Usage of `!tags`: 720 times (includes all the above and empty arg invocations)
3. `!extension` - alias for `!tags get traceback`
    * Usage: 12 times
    * Usage of the `traceback` tag: 194 times

The usages compared to other ways to invoke the commands are ~0.04%, 0%, and 6.19% respectively. Quite low numbers. Regarding the `traceback` alias, the tag search functionality will likely pick up the `exception` keyword and show the traceback tag anyway.

Removing this cog would reduce maintenance costs (granted, not by much). It would also just clean things up a bit. I find the existence of this code to be an anomaly, for lack of a better word, considering #1124. Lastly, it means #844 and #847 would be closed.

Is anyone on board with this proposal?


Discussion:
Let's do this. Always good to trim unused features.

`!exception` isn't a suitable alias for `traceback` anyway, and we have tags for both.

Resolving patch:
diff --git a/bot/exts/backend/alias.py b/bot/exts/backend/alias.py
deleted file mode 100644
--- a/bot/exts/backend/alias.py
+++ /dev/null
@@ -1,87 +0,0 @@
-import inspect
-import logging
-
-from discord import Colour, Embed
-from discord.ext.commands import (
-    Cog, Command, Context,
-    clean_content, command, group,
-)
-
-from bot.bot import Bot
-from bot.converters import TagNameConverter
-from bot.pagination import LinePaginator
-
-log = logging.getLogger(__name__)
-
-
-class Alias (Cog):
-    """Aliases for commonly used commands."""
-
-    def __init__(self, bot: Bot):
-        self.bot = bot
-
-    async def invoke(self, ctx: Context, cmd_name: str, *args, **kwargs) -> None:
-        """Invokes a command with args and kwargs."""
-        log.debug(f"{cmd_name} was invoked through an alias")
-        cmd = self.bot.get_command(cmd_name)
-        if not cmd:
-            return log.info(f'Did not find command "{cmd_name}" to invoke.')
-        elif not await cmd.can_run(ctx):
-            return log.info(
-                f'{str(ctx.author)} tried to run the command "{cmd_name}" but lacks permission.'
-            )
-
-        await ctx.invoke(cmd, *args, **kwargs)
-
-    @command(name='aliases')
-    async def aliases_command(self, ctx: Context) -> None:
-        """Show configured aliases on the bot."""
-        embed = Embed(
-            title='Configured aliases',
-            colour=Colour.blue()
-        )
-        await LinePaginator.paginate(
-            (
-                f"• `{ctx.prefix}{value.name}` "
-                f"=> `{ctx.prefix}{name[:-len('_alias')].replace('_', ' ')}`"
-                for name, value in inspect.getmembers(self)
-                if isinstance(value, Command) and name.endswith('_alias')
-            ),
-            ctx, embed, empty=False, max_lines=20
-        )
-
-    @command(name="exception", hidden=True)
-    async def tags_get_traceback_alias(self, ctx: Context) -> None:
-        """Alias for invoking <prefix>tags get traceback."""
-        await self.invoke(ctx, "tags get", tag_name="traceback")
-
-    @group(name="get",
-           aliases=("show", "g"),
-           hidden=True,
-           invoke_without_command=True)
-    async def get_group_alias(self, ctx: Context) -> None:
-        """Group for reverse aliases for commands like `tags get`, allowing for `get tags` or `get docs`."""
-        pass
-
-    @get_group_alias.command(name="tags", aliases=("tag", "t"), hidden=True)
-    async def tags_get_alias(
-            self, ctx: Context, *, tag_name: TagNameConverter = None
-    ) -> None:
-        """
-        Alias for invoking <prefix>tags get [tag_name].
-
-        tag_name: str - tag to be viewed.
-        """
-        await self.invoke(ctx, "tags get", tag_name=tag_name)
-
-    @get_group_alias.command(name="docs", aliases=("doc", "d"), hidden=True)
-    async def docs_get_alias(
-            self, ctx: Context, symbol: clean_content = None
-    ) -> None:
-        """Alias for invoking <prefix>docs get [symbol]."""
-        await self.invoke(ctx, "docs get", symbol)
-
-
-def setup(bot: Bot) -> None:
-    """Load the Alias cog."""
-    bot.add_cog(Alias(bot))
diff --git a/bot/exts/info/source.py b/bot/exts/info/source.py
--- a/bot/exts/info/source.py
+++ b/bot/exts/info/source.py
@@ -66,14 +66,8 @@ def get_source_link(self, source_item: SourceType) -> Tuple[str, str, Optional[i
         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
         elif isinstance(source_item, str):
             tags_cog = self.bot.get_cog("Tags")
             filename = tags_cog._cache[source_item]["location"]
@@ -113,13 +107,7 @@ async def build_embed(self, source_object: SourceType) -> Optional[Embed]:
             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
-
+            description = source_object.short_doc
             title = f"Command: {source_object.qualified_name}"
         elif isinstance(source_object, str):
             title = f"Tag: {source_object}"


Test patch: