2021-01-19 14:30:25 +01:00
|
|
|
from discord.ext import commands
|
|
|
|
from jishaku.models import copy_context_with
|
|
|
|
|
|
|
|
|
2021-01-19 15:03:05 +01:00
|
|
|
_ = lambda x: x
|
|
|
|
|
|
|
|
|
2021-01-19 14:30:25 +01:00
|
|
|
class AliasConvertor(commands.Converter):
|
|
|
|
async def convert(self, ctx, argument):
|
|
|
|
args = argument.split(" | ")
|
|
|
|
|
|
|
|
if len(args) <= 1:
|
|
|
|
raise commands.BadArgument(
|
2021-01-19 15:03:05 +01:00
|
|
|
_("Alias must be like `[command] | [alias]`")
|
2021-01-19 14:30:25 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
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:
|
2021-01-19 15:03:05 +01:00
|
|
|
raise commands.BadArgument(_(f"Unknown command `{args[0]}`"))
|
2021-01-19 14:30:25 +01:00
|
|
|
|
|
|
|
if alias_ctx.command is not None:
|
2021-01-19 15:03:05 +01:00
|
|
|
raise commands.BadArgument(_(f"Command `{args[1]}` already exists"))
|
2021-01-19 14:30:25 +01:00
|
|
|
|
|
|
|
return argument
|