Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
- from vk_api.keyboard import VkKeyboard, VkKeyboardColor
- import vk_api
- import time
- import datetime
- from datetime import datetime
- import random
- from enum import Enum
- import requests
- bot_session = vk_api.VkApi(token="ceb0c2f08e15e62bf695d1e12b29959997b4f5487f577d3fd126800693dd39bb7062ed9658c51c39045de")
- bot_api = bot_session.get_api()
- longpoll = VkBotLongPoll(bot_session, "181509348")
- replies = [ "ответ1", "ответ2", "ответ3" ]
- def send_message(vk_session, id_type, id, message=None, attachment=None, keyboard=None):
- vk_session.method('messages.send',{id_type: id, 'message': message, 'random_id': random.randint(-2147483648, +2147483648), "attachment": attachment, 'keyboard': keyboard})
- def create_keyboard(response):
- keyboard = VkKeyboard(one_time=True)
- if response == 'Меню':
- keyboard.add_button('Текущая игра', color=VkKeyboardColor.POSITIVE)
- keyboard.add_button('Депозит', color=VkKeyboardColor.POSITIVE)
- keyboard = keyboard.get_keyboard()
- return keyboard
- while True:
- try:
- for event in longpoll.listen():
- if event.type == VkBotEventType.MESSAGE_NEW:
- if event.from_user and not event.from_me:
- print("New message")
- bot_api.messages.send(
- random_id=random.getrandbits(32),
- peer_id=event.obj.peer_id,
- message=random.choice(replies)
- )
- if vk_api.bot_longpoll.VkBotEvent:
- print("New message")
- bot_api.messages.send(
- random_id=random.getrandbits(32),
- peer_id=event.obj.peer_id,
- message=random.choice(replies)
- )
- except requests.exceptions.ReadTimeout as timeout:
- continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement