async def inner(bot: Bot, chat_id: str, *args, **kwargs): try: await f(bot, chat_id, *args, **kwargs) except (BotBlocked, UserDeactivated, BotBlocked) as e: logger.warning(f"bot blocked by {chat_id},{str(e)}") with get_db_session() as db: crud.update_user_status(db, chat_id, False) else: logger.info(f"message send to {chat_id},args={args},kwargs={kwargs}")
async def update_subscription_callback_handler(query: types.CallbackQuery): is_enable = query.data == ENABLE_SUB with get_db_session() as db: crud.update_user_status(db, query.message.chat.id, is_enable) text = "已开启订阅" if is_enable else "已关闭订阅" user = crud.get_user(db, query.message.chat.id) await query.answer(text) await query.message.edit_reply_markup( KeyboardMarkUpFactory.build_cron_options(user))
async def handle_sub(message: types.Message) -> None: with get_db_session() as db: crud.update_user_status(db, message.chat.id, True) await TelegramMessageService.send_text(dp.bot, message.chat.id, "已开启定时订阅") user = crud.get_user(db, message.chat.id) reply_markup = KeyboardMarkUpFactory.build_cron_options(user) await TelegramMessageService.send_keyboard_markup( dp.bot, message.chat.id, WELCOME_TEXT, reply_markup)
async def sub_cron_update_callback_handler(query: types.CallbackQuery): hour = query.data chat_id = query.message.chat.id with get_db_session() as db: # 激活用户 crud.update_user_status(db, query.message.chat.id, True) user = crud.get_user(db, query.message.chat.id) # 新增/删除订阅 cron_job, created = crud.create_or_delete_cron_job(db, chat_id, hour) if created: await query.answer("订阅成功") else: await query.answer("已取消") db.refresh(user) cron_sub_menu = KeyboardMarkUpFactory.build_cron_options(user) await query.message.edit_reply_markup(cron_sub_menu)
async def inner(bot: Bot, chat_id: str, *args, **kwargs): try: await f(bot, chat_id, *args, **kwargs) except (BotBlocked, UserDeactivated, ChatNotFound, BotKicked, CantTalkWithBots) as e: logger.warning(f"bot blocked by {chat_id},{str(e)}") with get_db_session() as db: crud.update_user_status(db, chat_id, False) except Unauthorized as e: if "the group chat was deleted" in e.text: logger.warning(f"{bot} of group was deleted") except MigrateToChat as e: with get_db_session() as db: crud.update_user_status(db, chat_id, False) crud.migrate_user_by_chat_id(db, chat_id, str(e.migrate_to_chat_id)) except Exception as e: logger.error(e) sentry_sdk.capture_exception(e) else: logger.info( f"message send to {chat_id},args={args},kwargs={kwargs}")
async def handle_unsub(message: types.Message) -> None: with get_db_session() as db: crud.update_user_status(db, message.chat.id, False) await TelegramMessageService.send_text(dp.bot, message.chat.id, "已关闭定时订阅")