コード例 #1
0
def send_numbered_stuff_from_storage(message, storage_name, stuff_number):
    """Send a numbered piece of media from a storage"""
    contents = get_list_from_storage(storage_name)['contents']
    if len(contents) > 0:
        try:
            result = contents[stuff_number]
        except IndexError:
            reply(message, "Не вижу такого номера в этом хранилище :-(")
            return  # ничего не возвращает, но досрочно завершает работу функции
        args_to_send = [message.chat.id, result[0]]
        kwargs_to_send = {
            'reply_to_message_id': message.message_id,
            'caption': result[2],
            'parse_mode': 'HTML'
        }
        if result[1] == 'photo':
            send_photo(*args_to_send, **kwargs_to_send)
        elif result[1] == 'video':
            send_video(*args_to_send, **kwargs_to_send)
        elif result[1] == 'gif':
            send_document(*args_to_send, **kwargs_to_send)
        else:
            reply(message, "Произошла ошибка!")
    else:
        reply(message, "На данный момент хранилище пусто :-(")
コード例 #2
0
def send_random_stuff_from_storage(message, storage_name):
    """Send a random piece of media from a storage"""
    contents = get_list_from_storage(storage_name)['contents']
    if len(contents) > 0:
        result = choice(contents)
        args_to_send = [message.chat.id, result[0]]
        kwargs_to_send = {'reply_to_message_id': message.message_id,
                          'caption': result[2], 'parse_mode': 'HTML'}
        if result[1] == 'photo':
            send_photo(*args_to_send, **kwargs_to_send)
        elif result[1] == 'video':
            send_video(*args_to_send, **kwargs_to_send)
        elif result[1] == 'gif':
            send_document(*args_to_send, **kwargs_to_send)
        else:
            reply(message, "Произошла ошибка!")
    else:
        reply(message, "На данный момент хранилище пусто :-(")