2020-04-04 16:07:39 +00:00
|
|
|
|
import vk_api
|
|
|
|
|
import time
|
|
|
|
|
import requests
|
|
|
|
|
from config import vk
|
|
|
|
|
from bs4 import BeautifulSoup
|
2020-04-03 21:18:34 +00:00
|
|
|
|
from dan63047bot import VkBot
|
2020-04-04 16:07:39 +00:00
|
|
|
|
from vk_api.longpoll import VkLongPoll, VkEventType
|
2020-04-03 21:18:34 +00:00
|
|
|
|
|
|
|
|
|
|
2020-04-04 16:07:39 +00:00
|
|
|
|
def write_msg(peer_id, message, attachment=None):
|
|
|
|
|
vk.method('messages.send', {'peer_id': peer_id,
|
|
|
|
|
'message': message,
|
|
|
|
|
'random_id': time.time(),
|
|
|
|
|
'attachment': attachment})
|
|
|
|
|
|
|
|
|
|
longpoll = VkLongPoll(vk) # Работа с сообщениями
|
2020-04-03 21:18:34 +00:00
|
|
|
|
print("Server started")
|
|
|
|
|
for event in longpoll.listen():
|
|
|
|
|
if event.type == VkEventType.MESSAGE_NEW:
|
|
|
|
|
if event.to_me:
|
2020-04-04 16:07:39 +00:00
|
|
|
|
|
2020-04-03 21:18:34 +00:00
|
|
|
|
print('New message:')
|
|
|
|
|
print(f'For me by: {event.peer_id}', end='')
|
2020-04-04 16:07:39 +00:00
|
|
|
|
|
2020-04-03 21:18:34 +00:00
|
|
|
|
bot = VkBot(event.peer_id)
|
2020-04-04 16:07:39 +00:00
|
|
|
|
if bot.new_message(event.text)['text']:
|
|
|
|
|
write_msg(event.peer_id, bot.new_message(event.text)['text'], bot.new_message(event.text)['attachment'])
|
|
|
|
|
|
|
|
|
|
print('Text: ', event.text)
|