mirror of
https://github.com/dnslin/aria2bot.git
synced 2026-01-11 12:12:19 +08:00
fix(telegram): 优化 bot 启动方式及安装命令逻辑,避免重复安装和卸载 aria2
This commit is contained in:
@@ -48,6 +48,8 @@ def create_app(config: BotConfig) -> Application:
|
|||||||
|
|
||||||
def run() -> None:
|
def run() -> None:
|
||||||
"""加载配置并启动 bot"""
|
"""加载配置并启动 bot"""
|
||||||
|
import asyncio
|
||||||
|
|
||||||
logger = setup_logger()
|
logger = setup_logger()
|
||||||
config = BotConfig.from_env()
|
config = BotConfig.from_env()
|
||||||
|
|
||||||
@@ -57,4 +59,11 @@ def run() -> None:
|
|||||||
|
|
||||||
app = create_app(config)
|
app = create_app(config)
|
||||||
logger.info("Bot starting...")
|
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())
|
||||||
|
|||||||
@@ -75,6 +75,9 @@ class Aria2BotAPI:
|
|||||||
|
|
||||||
async def install(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
async def install(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
logger.info(f"收到 /install 命令 - {_get_user_info(update)}")
|
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,处理中,请稍候...")
|
await self._reply(update, context, "正在安装 aria2,处理中,请稍候...")
|
||||||
try:
|
try:
|
||||||
result = await self.installer.install()
|
result = await self.installer.install()
|
||||||
@@ -106,6 +109,9 @@ class Aria2BotAPI:
|
|||||||
|
|
||||||
async def uninstall(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
async def uninstall(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
logger.info(f"收到 /uninstall 命令 - {_get_user_info(update)}")
|
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,处理中,请稍候...")
|
await self._reply(update, context, "正在卸载 aria2,处理中,请稍候...")
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user