From 084ab6d9b40fc4eba7b4c6992bbde4e651b51b28 Mon Sep 17 00:00:00 2001 From: dnslin Date: Fri, 12 Dec 2025 09:25:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(telegram):=20=E4=BC=98=E5=8C=96=20bot=20?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=96=B9=E5=BC=8F=E5=8F=8A=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E9=80=BB=E8=BE=91=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E5=AE=89=E8=A3=85=E5=92=8C=E5=8D=B8=E8=BD=BD?= =?UTF-8?q?=20aria2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/telegram/app.py | 11 ++++++++++- src/telegram/handlers.py | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/telegram/app.py b/src/telegram/app.py index 784bf98..cb76a6b 100644 --- a/src/telegram/app.py +++ b/src/telegram/app.py @@ -48,6 +48,8 @@ def create_app(config: BotConfig) -> Application: def run() -> None: """加载配置并启动 bot""" + import asyncio + logger = setup_logger() config = BotConfig.from_env() @@ -57,4 +59,11 @@ def run() -> None: app = create_app(config) logger.info("Bot starting...") - app.run_polling() + + async def main(): + async with app: + await app.start() + await app.updater.start_polling() + await asyncio.Event().wait() + + asyncio.run(main()) diff --git a/src/telegram/handlers.py b/src/telegram/handlers.py index f5a0003..501a8e6 100644 --- a/src/telegram/handlers.py +++ b/src/telegram/handlers.py @@ -75,6 +75,9 @@ class Aria2BotAPI: async def install(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: logger.info(f"收到 /install 命令 - {_get_user_info(update)}") + if is_aria2_installed(): + await self._reply(update, context, "aria2 已安装,无需重复安装。如需重新安装,请先运行 /uninstall") + return await self._reply(update, context, "正在安装 aria2,处理中,请稍候...") try: result = await self.installer.install() @@ -106,6 +109,9 @@ class Aria2BotAPI: async def uninstall(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: logger.info(f"收到 /uninstall 命令 - {_get_user_info(update)}") + if not is_aria2_installed(): + await self._reply(update, context, "aria2 未安装,无需卸载") + return await self._reply(update, context, "正在卸载 aria2,处理中,请稍候...") try: try: