async def cmd_commands(msg: Message, *args):
    include_aliases = '-a' in args or '-alias' in args
    custom_commands = ', '.join(map(attrgetter('name'), get_all_custom_commands(msg.channel_name)))
    usable_commands = []
    seen = set()
    for command in commands.values():
        if (
                command.fullname in seen
                or command.hidden
                or not is_command_whitelisted(command.name)
                or is_command_disabled(msg.channel_name, command.name)
                or not perms.has_permission(msg.channel_name, msg.author, command.permission)
        ):
            continue

        seen.add(command.fullname)
        usable_commands.append(command.fullname)
        if include_aliases:
            for alias in command.aliases:
                usable_commands.append(command.prefix + alias)
    global_commands = ', '.join(usable_commands)

    if usable_commands:
        await msg.reply(whisper=True, msg=f'COMMANDS YOU CAN USE: {global_commands}')
    else:
        await msg.reply(whisper=True, msg=f'{msg.mention}, you do not have permission to use any commands')

    if custom_commands:
        await msg.reply(whisper=True, msg=f'CUSTOM: {custom_commands}')
async def cmd_commands(msg: Message, *args):
    custom_commands = ', '.join(
        map(attrgetter('name'), get_all_custom_commands(msg.channel_name)))
    global_commands = ', '.join(map(attrgetter('fullname'), commands.values()))

    await msg.reply(whisper=True, msg=f'GLOBAL: {global_commands}')
    if custom_commands:
        await msg.reply(whisper=True, msg=f'CUSTOM: {custom_commands}')
async def cmd_commands(msg: Message, *args):
    custom_commands_str = ', '.join(
        cmd.name for cmd in get_all_custom_commands(msg.channel_name))
    global_commands_str = ', '.join(cmd.fullname for cmd in commands.values())

    await msg.reply(whisper=True, msg=f'GLOBAL: {global_commands_str}')

    if custom_commands_str:
        await msg.reply(whisper=True, msg=f'CUSTOM: {custom_commands_str}')
async def cmd_commands(msg: Message, *args):
    custom_commands = ', '.join(
        map(attrgetter('name'), get_all_custom_commands(msg.channel_name)))
    usable_commands = [
        c for c in commands.values() if is_command_whitelisted(c.name)
        and not is_command_disabled(msg.channel_name, c.name)
        and perms.has_permission(msg.channel_name, msg.author, c.permission)
    ]
    global_commands = ', '.join(map(attrgetter('fullname'), usable_commands))

    if usable_commands:
        await msg.reply(whisper=True,
                        msg=f'COMMANDS YOU CAN USE: {global_commands}')
    else:
        await msg.reply(
            whisper=True,
            msg=f'{msg.mention}, you do not have permission to use any commands'
        )

    if custom_commands:
        await msg.reply(whisper=True, msg=f'CUSTOM: {custom_commands}')
Exemplo n.º 5
0
from twitchbot import commands
from shutil import rmtree
from pathlib import Path
from os import remove

with open('commands.md', 'w') as out:
    out.write('# Builtin Commands: \n')
    out.write('## index\n')

    for command in commands.values():
        out.write(f'\n* [{command.name}](#{command.name})')

    for command in commands.values():
        out.write(f"""

## {command.name}
NAME: {command.name}

SYNTAX: {command.syntax or 'NO SYNTAX'}

PERMISSION: {command.permission or 'NO PERMISSION'}

HELP: {command.help or 'NO HELP'}

[[back to index](#index)]
""")

# the bot creates these folders, and since we do not need them, just delete them
CWD = Path.cwd()
# noinspection PyTypeChecker
remove(CWD / 'database.sqlite')