Advertisement
Guest User

dfsdf

a guest
Apr 23rd, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.99 KB | None | 0 0
  1. from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
  2. from vk_api.keyboard import VkKeyboard, VkKeyboardColor
  3.  
  4. import vk_api
  5. import time
  6. import datetime
  7. from datetime import datetime
  8. import random
  9. from enum import Enum
  10.  
  11.  
  12. import requests
  13.  
  14. bot_session = vk_api.VkApi(token="ceb0c2f08e15e62bf695d1e12b29959997b4f5487f577d3fd126800693dd39bb7062ed9658c51c39045de")
  15. bot_api = bot_session.get_api()
  16. longpoll = VkBotLongPoll(bot_session, "181509348")
  17.  
  18. replies = [ "ответ1", "ответ2", "ответ3" ]
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. def send_message(vk_session, id_type, id, message=None, attachment=None, keyboard=None):
  26.     vk_session.method('messages.send',{id_type: id, 'message': message, 'random_id': random.randint(-2147483648, +2147483648), "attachment": attachment, 'keyboard': keyboard})
  27.  
  28.  
  29.  
  30.  
  31.  
  32. def create_keyboard(response):
  33.     keyboard = VkKeyboard(one_time=True)
  34.  
  35.     if response == 'Меню':
  36.  
  37.         keyboard.add_button('Текущая игра', color=VkKeyboardColor.POSITIVE)
  38.         keyboard.add_button('Депозит', color=VkKeyboardColor.POSITIVE)
  39.  
  40.     keyboard = keyboard.get_keyboard()
  41.     return keyboard
  42.  
  43.  
  44. while True:
  45.     try:
  46.         for event in longpoll.listen():
  47.             if event.type == VkBotEventType.MESSAGE_NEW:
  48.  
  49.                 if event.from_user and not event.from_me:
  50.  
  51.    
  52.                     print("New message")
  53.                     bot_api.messages.send(
  54.                         random_id=random.getrandbits(32),
  55.                         peer_id=event.obj.peer_id,
  56.                         message=random.choice(replies)
  57.                     )
  58.    
  59.                 if vk_api.bot_longpoll.VkBotEvent:
  60.                     print("New message")
  61.                     bot_api.messages.send(
  62.                         random_id=random.getrandbits(32),
  63.                         peer_id=event.obj.peer_id,
  64.                         message=random.choice(replies)
  65.                     )
  66.  
  67.     except requests.exceptions.ReadTimeout as timeout:
  68.         continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement