Advertisement
Guest User

Untitled

a guest
Dec 5th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. import vk_api
  2. from vk_api.longpoll import VkLongPoll, VkEventType
  3. import time
  4. import random
  5.  
  6.  
  7. def main():
  8.  
  9.     login, password = '*', '*'
  10.     vk_session = vk_api.VkApi(login, password)
  11.  
  12.     try:
  13.         vk_session.auth(token_only=True)
  14.     except vk_api.AuthError as error_msg:
  15.         print(error_msg)
  16.         return
  17.  
  18.     vk = vk_session.get_api()
  19.     longpoll = VkLongPoll(vk_session)
  20.  
  21.     for event in longpoll.listen():
  22.         if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text:
  23.             print('Новое сообщение')
  24.             if event.from_user:
  25.                 while True:
  26.                     vk.messages.send(
  27.                         user_id=event.user_id,
  28.                         message='',
  29.                         random_id=random.randint(0, 111111111)
  30.                     )
  31.                     time.sleep(2)
  32.             if event.from_chat:
  33.                 while True:
  34.                     vk.messages.send(
  35.                         chat_id=event.chat_id,
  36.                         message='',
  37.                         random_id=random.randint(0, 111111111)
  38.                     )
  39.                     time.sleep(2)
  40.  
  41.  
  42. if __name__ == '__main__':
  43.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement