Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import vk_api as vk
- from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
- import wikipedia as wiki
- from random import randint
- # vktoken = input("Введите ваш токен:")
- vktoken = "37dae4366219f68f90186905ce81d7be0c997ecbccd54f76c00ecb9173ba7" \
- "26bbb66149ccd01eac17757a"
- # group = input("ваш id группы")
- group = 187423793
- wvars = ["wiki","wp","вики","вп"]
- wmodessearch = ["search", "поиск"]
- wmodesrandom = ["random", "рандом", "случайная_статья"]
- vksession = vk.VkApi(token=vktoken)
- vksession._auth_token()
- vapi = vksession.get_api()
- lpoll = VkBotLongPoll(vksession, group_id=group)
- print("ready")
- def send(msg, cid):
- vapi.messages.send(users_id=cid, message=str(msg),
- random_id=randint(0, 18446744073709551615))
- def send_chat(msg, cid):
- vapi.messages.send(chat_id=cid, message=str(msg),
- random_id=randint(0, 18446744073709551615))
- wiki.set_lang("ru")
- while True:
- for event in lpoll.listen():
- if event.type == VkBotEventType.MESSAGE_NEW:
- msg_text = event.object.text
- # command, mode, text = event.object.msg_text.split("!")
- if msg_text[0] == "!":
- msg_text = msg_text[1:]
- raw = msg_text.split(" ")
- if len(raw) >= 3:
- command = raw[0]
- mode = raw[1]
- raw = raw[2:]
- text = ""
- for item in raw:
- text += item + " "
- elif len(raw) == 2:
- command = raw[0]
- mode = raw[1]
- else:
- continue
- print(command, ":", mode)
- if command in wvars:
- print('command')
- if mode.lower() in wmodessearch:
- print("search")
- if event.from_user:
- try:
- send(wiki.summary(text), event.user_id)
- except wiki.exceptions.DisambiguationError as e:
- send(str(e), event.user_id)
- elif event.from_chat:
- try:
- send_chat(wiki.summary(text), event.chat_id)
- except wiki.exceptions.DisambiguationError as e:
- send_chat(str(e), event.chat_id)
- elif mode.lower() in wmodesrandom:
- print('random')
- if event.from_user:
- send(wiki.random(1), event.user_id)
- elif event.from_chat:
- send_chat(wiki.random(1), event.chat_id)
- elif event.type == VkBotEventType.AUDIO_NEW:
- if event.from_user:
- send("Кто шлет голосовые - тот виндузятник", event.user_id)
- elif event.from_chat:
- send_chat("Кто шлет голосовые - тот виндузятник", event.chat_id)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement