Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon Jun 17 16:13:18 2019
  4.  
  5. @author: Юрий
  6. """
  7. import vk_api
  8. #import time
  9. import random
  10. import datetime
  11. import requests
  12. import user_dialog
  13. import re
  14. tk='f0aa071af27e1ecdd70661a1bc12adf1833f333f3550a29b75a42bf3d93295d5ad27dfa15a27ca0c2251b'
  15. session = requests.Session()
  16. vk_session = vk_api.VkApi(token=tk)
  17. try:
  18. vk_session.auth(token_only=True)
  19. except vk_api.AuthError as error_msg:
  20. print(error_msg)
  21. from vk_api.longpoll import VkLongPoll, VkEventType
  22. longpoll = VkLongPoll(vk_session)
  23. vk = vk_session.get_api()
  24. for event in longpoll.listen():
  25. if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text:
  26.  
  27. # 'vk.kom/testmybot'
  28. # event.text
  29. # "Привет!"!="Привет"!="привет"
  30. txt=event.text.lower()
  31. txt=re.sub(r'[^а-яА-Я0-9 ]','', txt)
  32. rand=random.randint(0,50000000)
  33.  
  34. if txt=='привет' or txt=='хи':
  35. msg_text='привет'
  36. vk.messages.send( #Отправляем сообщение
  37. user_id=event.user_id,random_id=rand,message=msg_text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement