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, "На данный момент хранилище пусто :-(")
def database_send_handler(message): """ Send all databases to config_var.CREATOR_ID """ if message.chat.id == config_var.CREATOR_ID: for file in ( files_paths.DATABASE_FILE, files_paths.VOTES_FILE, files_paths.ADAPT_VOTES_FILE, files_paths.MULTI_VOTES_FILE, files_paths.SYSTEMS_FILE, files_paths.STORAGE_FILE): file_send = open(file, 'rb') output.send_document(message.chat.id, file_send) file_send.close()
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, "На данный момент хранилище пусто :-(")