This repository has been archived by the owner on Jul 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.py
94 lines (68 loc) · 2.49 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import asyncio
import client
from lib.exceptions import WrongPassword
from lib.socket_handler import SocketHandler
from lib.user_credentials import UserCredentialsProcessor
from sub_client import SubClient
async def run():
user_credentials = UserCredentialsProcessor().get_user_credentials()
client_object = client.ClientObject()
try:
await client_object.login(user_credentials.login, user_credentials.password)
except WrongPassword as exception:
print(exception)
print('Try to rerun the script')
UserCredentialsProcessor().delete_user_credentials()
exit()
coo = await client_object.get_my_communities()
print("Choose a community to work in (you can choose only one for now): ")
i = 1
for item in coo.items:
print(str(i) + ' - ' + str(item.name))
i += 1
coo_id = input('You chose: ')
if not coo_id or not coo_id.isnumeric():
print('Please provide a correct value')
exit()
coo_id = int(coo_id) - 1
print('You chose ' + str(coo.items[coo_id].name))
coo_id = coo.items[coo_id].communityId
client_object.allowed_communities.append(coo_id)
await client_object.process_self_status()
if client_object.is_leader:
print('The user has leader status.')
elif client_object.is_curator:
print('The user has curator status.')
else:
print('The user has default status.')
print()
print('Now choose chats to monitor')
print('You can choose more than one chat')
print('Please type it one by one')
print('Type nothing if you are done')
sub_client = SubClient(coo_id)
chats = await sub_client.get_my_chats()
i = 1
for item in chats.items:
print(str(i) + ' - ' + str(item.name))
i += 1
while True:
chat_id = input('Your chose: ')
if not chat_id:
break
if not chat_id.isnumeric():
print('Please enter a valid number')
continue
chat_id = int(chat_id) - 1
print('You added ' + str(chats.items[chat_id].name) + ' to the monitoring list')
chat_id = chats.items[chat_id].chatId
client_object.allowed_chats.append(chat_id)
if client_object.allowed_chats:
print('Done.')
else:
print('You chose no chats. Working in a webhook mode.')
websocket_url = await client_object.get_webhook_url()
s_h = SocketHandler(client_object, websocket_url)
s_h.start()
if __name__ == '__main__':
asyncio.run(run())