-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathMain.py
43 lines (28 loc) · 1.05 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
import random
import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
# --
from commander.commander import Commander
from vk_bot import VkBot
# --
def write_msg(user_id, message):
vk.method('messages.send', {'user_id': user_id, 'message': message, 'random_id': random.randint(0, 2048)})
# API-ключ созданный ранее
token = "Your API token here..."
# Авторизуемся как сообщество
vk = vk_api.VkApi(token=token)
# Работа с сообщениями
longpoll = VkLongPoll(vk)
commander = Commander()
print("Server started")
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW:
if event.to_me:
print(f'New message from {event.user_id}', end='')
bot = VkBot(event.user_id)
if event.text[0] == "/":
write_msg(event.user_id, commander.do(event.text[1::]))
else:
write_msg(event.user_id, bot.new_message(event.text))
print('Text: ', event.text)
print("-------------------")