mirror of
https://github.com/woodchen-ink/Q58Bot.git
synced 2025-07-18 13:52:07 +08:00
优化启动过程,使用asyncio运行bot设置
将bot的初始化过程改为使用asyncio.run(setup_bot()),以简化事件循环的创建和管理。该更改旨在优化代码结构,提高可读性和可维护性。
This commit is contained in:
parent
cec72f173c
commit
86d2966d43
@ -3,6 +3,7 @@ import multiprocessing
|
||||
import guard
|
||||
import binance
|
||||
import logging
|
||||
import asyncio
|
||||
from bot_commands import register_commands
|
||||
from telethon import TelegramClient
|
||||
|
||||
@ -15,6 +16,9 @@ async def setup_bot():
|
||||
await register_commands(client, ADMIN_ID)
|
||||
await client.disconnect()
|
||||
|
||||
def run_setup_bot():
|
||||
asyncio.run(setup_bot())
|
||||
|
||||
def run_guard():
|
||||
while True:
|
||||
try:
|
||||
@ -35,8 +39,7 @@ if __name__ == '__main__':
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
|
||||
# 注册机器人命令
|
||||
import asyncio
|
||||
asyncio.get_event_loop().run_until_complete(setup_bot())
|
||||
run_setup_bot()
|
||||
|
||||
# 创建两个进程分别运行 guard 和 binance 服务
|
||||
guard_process = multiprocessing.Process(target=run_guard)
|
||||
|
Loading…
x
Reference in New Issue
Block a user