Пример #1
0
def handler(bot, update):
    command = parse_command(update.message.text)
    txt_args = ' '.join(update.message.text.split(' ')[1:])

    try:
        command_handler(command)(bot, update, command, txt_args)
    except CommandNotFound:
        default_handler(bot, update, f'Command {command} not found')
    except CharacterNotFound:
        default_handler(bot, update, f'Character not found. Cannot execute {update.message.text}')
    except CampaignNotFound:
        default_handler(bot, update, f'Campaign not found. Theres must be an active campaign')
Пример #2
0
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith(bot_secrets.PREFIX):
        message_content = message.content[len(bot_secrets.PREFIX):].lower()
        response = commands.command_handler(message_content)
        if response is not None:
            await message.channel.send(response)
Пример #3
0
def webhook(event, context):
    """
    Runs the Telegram webhook.
    """

    bot = configure_telegram()
    logger.info(json.loads(event.get('body')))

    if event.get('httpMethod') == 'POST' and event.get('body'):
        update = telegram.Update.de_json(json.loads(event.get('body')), bot)

        if not is_command(update):
            return OK_RESPONSE

        db = Database()
        chat_id = update.message.chat.id
        username = update.message.from_user.username if update.message.from_user.username else update.message.from_user.first_name
        command = parse_command(update.message.text)
        txt_args = ' '.join(update.message.text.split(' ')[1:])

        try:
            command_handler(command)(bot, update, command, txt_args, username,
                                     chat_id, db)
        except (CommandNotFound, InvalidCommand):
            default_handler(bot, update,
                            'Invalid command or command not supported')
        except CharacterNotFound:
            default_handler(bot, update,
                            'Character not found. Cannot execute command')
        except CampaignNotFound:
            default_handler(
                bot, update,
                'Campaign not found. There must be an active campaign')
        except json.JSONDecodeError:
            default_handler(bot, update, 'Error parsing JSON')
        except NotADM:
            default_handler(
                bot, update,
                f'Only the Dungeon Master can execute {command} command')
        #except Exception:
        #    logger.error(sys.exc_info()[2])
        #    default_handler(bot, update, 'Unhandled error. Check server logs for more details')

    return OK_RESPONSE
Пример #4
0
def handler(bot, update):
    command = parse_command(update.message.text)
    txt_args = ' '.join(update.message.text.split(' ')[1:])

    try:
        command_handler(command)(bot, update, command, txt_args)
    except (CommandNotFound, InvalidCommand):
        default_handler(bot, update, 'Invalid command')
    except CharacterNotFound:
        default_handler(bot, update,
                        'Character not found. Cannot execute command')
    except CampaignNotFound:
        default_handler(
            bot, update,
            f'Campaign not found. Theres must be an active campaign')
    except NotADM:
        default_handler(
            bot, update,
            f'Only the Dungeon Master can execute {command} command')
Пример #5
0
def database_shell():
    ''' Provides a simplistic commandline interface '''
    print('Welcome to the simple SQLite 3 database interactive shell!\n\
            To exit type -1!')
    print('(For help utilize the number 0)\n')

    try:
        conn, curr = setup_database('my.db')
    except sqlite3.Error as e:
        print(e)

    line = 0
    while (line != -1):
        line = int(input("Input your commands here:"))
        line = commands.command_handler(curr, line)

    conn.commit()
    close_db(conn, curr)
Пример #6
0
def _callback(recognizer, audio):
    """
    音声認識をして、その結果からコマンドを実行する
    """
    message = _audio_recognition(recognizer, audio)
    command_handler(message)