Как сделать подпись для каждой команды? - PullRequest
0 голосов
/ 08 мая 2019

Для моей справочной команды я ищу добавление текста для каждой проверки, имеющейся в команде, чтобы пользователь знал необходимые условия при использовании команды.

Это некоторый набросок кода, иллюстрирующий то, что яДумаю заняться

from discord.ext.commands import (
    is_owner, has_permissions, guild_only, is_nsfw, has_role,
    command, check,
)

def custom_check(x):

    def predicate(ctx):
        return x in ctx.message.content

    rt = check(predicate)
    rt.args = [x]
    return rt



@command(name = "abc")
@has_role(1234)
@custom_check("1234567890")
async def test1(ctx, a:int):
    print(f"test1 passed. {a}")



@command(name = "def")
@is_owner()
@has_permissions(manage_roles = True)
@has_role(5678)
async def test2(ctx, x:bool):
    print(f"test2 passed. {x}")



check_to_text_dict = {
    is_owner.id: "you must be owner to use this command",
    has_permissions.id: "you must have the following permissions to use this command: {args}",
    guild_only.id: "you must only use this command whilst in a server",
    is_nsfw.id: "you must only use this command in nsfw channels",
    has_role.id: "you must have the following role to use this command: {args[0]}",
    custom_check.id: "you must have the following content in your message for whatever reason: {args[0]}",
}



def get_check_signature(command):
    rt = list()
    for check in command.checks:
        rt.append(check_to_text_dict[check.id].format(args = check.args)) # nonsense

    return "\n".join(rt) if rt else "no rulez!"



print(get_check_signature(test1))
print()
print(get_check_signature(test2))

Конечно, все, что я там написал, - полная чушь.Не существует такого понятия, как идентификатор проверки или сохранение чека по заданным аргументам.

Так как мне это сделать?

...