-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
55 lines (44 loc) · 1.42 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import asyncio
from contextlib import suppress
from pyrogram import idle
from banner import banner_text
from core.client_manager import ClientManager
client_manager = ClientManager()
async def main():
print(banner_text)
await client_manager.load_sessions_and_start()
user_input_task = asyncio.create_task(process_user_input())
try:
await idle()
finally:
user_input_task.cancel()
for app in client_manager.clients.values():
await app.stop()
async def get_user_input():
loop = asyncio.get_event_loop()
message = (
"\n选择操作:\n"
"1. 添加帐号\n"
"2. 查看登录客户端\n"
"3. {}\n"
"4. 退出\n"
"请输入选项: "
).format('禁用消息' if client_manager.switch.is_set() else '启用消息')
return await loop.run_in_executor(None, input, message)
async def process_user_input():
while True:
choice = await get_user_input()
if choice == '1':
await client_manager.add_account()
elif choice == '2':
await client_manager.show_clients()
elif choice == '3':
client_manager.change_msg()
elif choice == '4':
await client_manager.stop_clients()
exit()
else:
print("无效选项,请重新选择。")
if __name__ == '__main__':
with suppress(KeyboardInterrupt):
asyncio.run(main())