tuxbot-bot/tuxbot/cogs/Custom/functions/converters.py
2021-01-21 16:13:46 +01:00

29 lines
816 B
Python

from discord.ext import commands
from jishaku.models import copy_context_with
def _(x):
return x
class AliasConvertor(commands.Converter):
async def convert(self, ctx, argument):
args = argument.split(" | ")
if len(args) <= 1:
raise commands.BadArgument(
_("Alias must be like `[command] | [alias]`")
)
command_ctx = await copy_context_with(
ctx, content=ctx.prefix + args[0]
)
alias_ctx = await copy_context_with(ctx, content=ctx.prefix + args[1])
if command_ctx.command is None:
raise commands.BadArgument(_("Unknown command"))
if args[0] != args[1] and alias_ctx.command is not None:
raise commands.BadArgument(_("Command already exists"))
return argument