Merge pull request #22 from MoFox-Studio/copilot/sub-pr-21

fix(bot): address ruff linting warnings for code quality
This commit is contained in:
拾风
2025-12-04 09:06:46 +08:00
committed by GitHub

8
bot.py
View File

@@ -610,9 +610,9 @@ async def wait_for_user_input():
try: try:
if os.getenv("ENVIRONMENT") != "production": if os.getenv("ENVIRONMENT") != "production":
logger.info("程序执行完成,按 Ctrl+C 退出...") logger.info("程序执行完成,按 Ctrl+C 退出...")
# 使用非阻塞循环 # 使用 asyncio.Event 而不是 sleep 循环
while True: shutdown_event = asyncio.Event()
await asyncio.sleep(0.1) await shutdown_event.wait()
except KeyboardInterrupt: except KeyboardInterrupt:
logger.info("用户中断程序") logger.info("用户中断程序")
return True return True
@@ -652,7 +652,7 @@ async def main_async():
user_input_done = asyncio.create_task(wait_for_user_input()) user_input_done = asyncio.create_task(wait_for_user_input())
# 使用wait等待任意一个任务完成 # 使用wait等待任意一个任务完成
done, pending = await asyncio.wait([main_task, user_input_done], return_when=asyncio.FIRST_COMPLETED) done, _pending = await asyncio.wait([main_task, user_input_done], return_when=asyncio.FIRST_COMPLETED)
# 如果用户输入任务完成用户按了Ctrl+C取消主任务 # 如果用户输入任务完成用户按了Ctrl+C取消主任务
if user_input_done in done and main_task not in done: if user_input_done in done and main_task not in done: