import requests
import vk_api
import random as r
import wikipedia
from vk_api.longpoll import VkLongPoll, VkEventType
wikipedia.set_lang("RU")
vk_session = vk_api.VkApi(token="Мой токен")
longpoll = VkLongPoll(vk_session)
vk = vk_session.get_api()
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.text :
if event.text == 'Вики':
if event.from_user:
vk.messages.send(
user_id=event.user_id,
message='Введите запрос',
random_id=r.randint(1, 2147483647)
)
if event.from_chat:
vk.messages.send(
chat_id=event.chat_id,
message='Введите запрос',
random_id=r.randint(1, 2147483647)
)
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.text:
if event.from_user:
vk.messages.send(
user_id=event.user_id,
message='Вот что я нашёл: \n' + str(wikipedia.summary(event.text)),
random_id=r.randint(1, 2147483647)
)
break
elif event.from_chat:
vk.messages.send(
chat_id=event.chat_id,
message='Вот что я нашёл: \n' + str(wikipedia.summary(event.text)),
random_id=r.randint(1, 2147483647)
)
break
continue
import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
from vk_api.utils import get_random_id
vk_session = vk_api.VkApi(token=TOKEN)
longpoll = VkBotLongPoll(vk_session, VKGroupID)
vk = vk_session.get_api()
status = {'stat' : 0}
def main():
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.text :
if event.text == 'Вики' and not status['stat']:
if event.from_user:
vk.messages.send(
peer_id=event.obj.from_id,
message='Введите запрос',
random_id=get_random_id()
)
if event.from_chat:
vk.messages.send(
peer_id=event.obj.peer_id,
message='Введите запрос',
random_id=get_random_id()
)
status['stat'] = 1
elif status['stat']:
status['stat'] = 0# тут все действия с поиском