-
Notifications
You must be signed in to change notification settings - Fork 10
/
lilly_runner.py
48 lines (31 loc) · 1.39 KB
/
lilly_runner.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
import vk_api
from lilly import Lilly
from vk_api.longpoll import VkLongPoll, VkEventType
import config
def write_msg(user_id, s):
vk.method('messages.send', {'peer_id': user_id, 'message': s})
# Авторизуемся как сообщество
vk = vk_api.VkApi(token=config.vk_api_token)
# Работа с сообщениями
longpoll = VkLongPoll(vk)
# Словарь, где будут хранится разные объекты бота для разных пользователей
users_bot_class_dict = {}
def run():
print("Server started")
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW:
if event.to_me:
print('New message:')
print('For me by: ', end='')
print(event.user_id)
user_id = event.user_id
if user_id not in users_bot_class_dict:
users_bot_class_dict[user_id] = Lilly()
# Checking to welcome message send
if users_bot_class_dict[user_id].WELCOME_MSG_SEND:
write_msg(event.user_id, users_bot_class_dict[user_id].update_screen(event.text))
else:
write_msg(event.user_id, users_bot_class_dict[user_id].get_welcome_msg(event.user_id))
print('Text: ', event.text)
print()
print("Lilly_Test is ready")