async def remove_cache(callback: types.CallbackQuery): async with analytics.Analyze("remove_cache", callback): await bot.send_message(callback.from_user.id, strings.cache_removed) reply_to: types.Message = callback.message.reply_to_message file_type, book_id = reply_to.text.replace('/', '').split('_') await Sender.remove_cache(file_type, int(book_id)) await Sender.send_book(reply_to, int(book_id), file_type)
async def get_author_annotation_update(callback: types.CallbackQuery): async with analytics.Analyze("get_author_annotation", callable): msg: types.Message = callback.message if not msg.reply_to_message or not msg.reply_to_message.text: return await msg.reply("Ошибка :( Попробуйте еще раз!") author, page = callback.data.replace("a_ann_", "").split("_") await TelegramUserDB.create_or_update(msg.reply_to_message) await Sender.send_author_annotation_edit(msg, int(author), int(page))
async def get_day_update_log_range(callback: types.CallbackQuery): async with analytics.Analyze("get_update_log", callback): msg: types.Message = callback.message type_, raw_start_date, raw_end_date, page = callback.data[3:].split( "_") await TelegramUserDB.create_or_update(callback) await Sender.send_update_log(msg, date.fromisoformat(raw_start_date), date.fromisoformat(raw_end_date), int(page), type_)
async def get_books_by_series(callback: types.CallbackQuery): async with analytics.Analyze("get_books_by_series", callback): msg: types.Message = callback.message if not msg.reply_to_message or not msg.reply_to_message.text: return await msg.reply("Ошибка :( Попробуйте еще раз!") await TelegramUserDB.create_or_update(msg.reply_to_message) await Sender.search_books_by_series( msg, int(msg.reply_to_message.text.split("_")[1]), int(callback.data.split('_')[1]))
async def search(msg: types.Message): async with analytics.Analyze("new_search_query", msg): await TelegramUserDB.create_or_update(msg) keyboard = types.InlineKeyboardMarkup() keyboard.row( types.InlineKeyboardButton("По названию", callback_data="b_1")) keyboard.row( types.InlineKeyboardButton("По авторам", callback_data="a_1"), types.InlineKeyboardButton("По сериям", callback_data="s_1")) await msg.reply("Поиск: ", reply_markup=keyboard)
async def beta_test_functions(msg: types.Message): async with analytics.Analyze("beta_test_functions", msg): await TelegramUserDB.create_or_update(msg) await msg.reply(""" Функции на тестировании: 1. Загрузка всех книг серии Выбирается приоритетный формат для загрузки. Загружаются все книги в выбранном формате, если нет возможности загрузить в этом формате, то загружается в доступном. """)
async def beta_testing_choose(query: types.CallbackQuery): async with analytics.Analyze("beta_testing_choose", query): await TelegramUserDB.create_or_update(query) settings = await SettingsDB.get(query.from_user.id) new_status = query.data.replace("beta_test_", "") if new_status == "on": settings.beta_testing = True else: settings.beta_testing = False await SettingsDB.update(settings) await query.message.edit_reply_markup(await beta_testing_keyboard( query.from_user.id))
async def lang_setup_changer(query: types.CallbackQuery): async with analytics.Analyze("lang_settings_change", query): await TelegramUserDB.create_or_update(query) settings = await SettingsDB.get(query.from_user.id) lang, set_ = query.data.split('_') if lang == "uk": settings.allow_uk = (set_ == "on") if lang == "be": settings.allow_be = (set_ == "on") if lang == "ru": settings.allow_ru = (set_ == "on") await SettingsDB.update(settings) await query.message.edit_reply_markup( await make_settings_lang_keyboard(query.from_user.id))
async def share_book(query: types.InlineQuery): async with analytics.Analyze("share_book", query): book_id = int(query.query.split("_")[1]) book = await BookAPI.get_by_id(book_id) if book is None: return await bot.answer_inline_query(query.id, [ types.InlineQueryResultArticle( id=str(query.query), title=strings.share, description=book.short_info, input_message_content=types.InputTextMessageContent( book.share_text, parse_mode="markdown", disable_web_page_preview=True)) ])
async def get_update_log_message(msg: types.Message): async with analytics.Analyze("get_update_log_message", msg): await TelegramUserDB.create_or_update(msg) end_date = (date.today() - timedelta(days=1)).isoformat() start_date_3 = (date.today() - timedelta(days=4)).isoformat() start_date_7 = (date.today() - timedelta(days=8)).isoformat() start_date_30 = (date.today() - timedelta(days=31)).isoformat() keyboard = types.InlineKeyboardMarkup(row_width=1) keyboard.add( types.InlineKeyboardButton( "За 1 день", callback_data=f"ul_d_{end_date}_{end_date}_1"), types.InlineKeyboardButton( "За 3 дня", callback_data=f"ul_t_{start_date_3}_{end_date}_1"), types.InlineKeyboardButton( "За 7 дней", callback_data=f"ul_w_{start_date_7}_{end_date}_1"), types.InlineKeyboardButton( "За 30 дней", callback_data=f"ul_m_{start_date_30}_{end_date}_1")) await msg.reply("Обновления за: ", reply_markup=keyboard)
async def help_commands_handler(msg: types.Message): async with analytics.Analyze("commands", msg): await msg.reply(strings.commands_msg)
async def beta_testing_menu(query: types.CallbackQuery): async with analytics.Analyze("beta_testing_menu", query): await TelegramUserDB.create_or_update(query) await query.message.edit_text( "Бета тест \n(список функций на тестировании /beta_functions ):", reply_markup=await beta_testing_keyboard(query.from_user.id))
async def help_handler(msg: types.Message): async with analytics.Analyze("help", msg): await msg.reply(strings.help_msg)
async def send_download_by_serial_keyboard(query: types.CallbackQuery): async with analytics.Analyze("download_by_serial_keyboard", query): series_id = int(query.data.replace("download_c_", "")) await query.message.edit_text(strings.choose_priority_format, reply_markup=await download_by_series_keyboard(series_id))
async def lang_setup(query: types.CallbackQuery): async with analytics.Analyze("lang_settings", query): await TelegramUserDB.create_or_update(query) await query.message.edit_text( "Языки:", reply_markup=await make_settings_lang_keyboard(query.from_user.id))
async def beta_test_functions(msg: types.Message): async with analytics.Analyze("beta_test_functions", msg): await TelegramUserDB.create_or_update(msg) await msg.reply("Нет")
async def donation(msg: types.Message): async with analytics.Analyze("donation", msg): await msg.reply(strings.donate_msg, parse_mode='HTML')
async def search_series(callback: types.CallbackQuery): async with analytics.Analyze("search_series", callback): msg: types.Message = callback.message if not msg.reply_to_message or not msg.reply_to_message.text: return await msg.reply("Ошибка :( Попробуйте еще раз!") await Sender.search_series(msg, int(callback.data.split('_')[1]))
async def get_author_annotation(msg: types.Message): async with analytics.Analyze("author_annotation", msg): author_id = int(msg.text.split("/a_info_")[1]) await Sender.send_author_annotation(msg, author_id)
async def get_book_detail(msg: types.Message): async with analytics.Analyze("book_detail", msg): book_id = int(msg.text.split("/b_info_")[1]) await Sender.send_book_detail(msg, book_id)
async def download_books_by_series(query: types.CallbackQuery): async with analytics.Analyze("download_series", query): file_type, series_id = query.data.replace("download_c_", "").split("_") await Sender.send_books_by_series(query, int(series_id), file_type)
async def info_handler(msg: types.Message): async with analytics.Analyze("info", msg): await msg.reply(strings.info_msg, disable_web_page_preview=True)
async def get_book_detail_callback(callback: types.CallbackQuery): async with analytics.Analyze("book_detail", callback): book_id = int(callback.data.replace("book_detail_", "")) await Sender.send_book_detail_edit(callback.message, book_id)
async def settings(msg: types.Message): async with analytics.Analyze("settings", msg): await TelegramUserDB.create_or_update(msg) await msg.reply("Настройки: ", reply_markup=await make_settings_keyboard())
async def get_random_series(msg: types.Message): async with analytics.Analyze("get_random_series", msg): await TelegramUserDB.create_or_update(msg) await Sender.get_random_sequence(msg)
async def settings_main(query: types.CallbackQuery): async with analytics.Analyze("settings_main", query): await TelegramUserDB.create_or_update(query) await query.message.edit_text("Настройки:", reply_markup=await make_settings_keyboard())
async def search_book_by_series(msg: types.Message): async with analytics.Analyze("get_book_by_series", msg): await TelegramUserDB.create_or_update(msg) await Sender.search_books_by_series(msg, int(msg.text.split("_")[1]), 1)
async def send_download_by_serial_keyboard(query: types.CallbackQuery): async with analytics.Analyze("download_by_serial_keyboard", query): series_id = int(query.data.replace("download_c_", "")) await query.message.edit_text("Скачать серию: ", reply_markup=await download_by_series_keyboard(series_id))
async def download_book(msg: types.Message): async with analytics.Analyze("download", msg): file_type, book_id = msg.text.replace('/', '').split('_') await Sender.send_book(msg, int(book_id), file_type)