Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
- import vk_api
- import os
- def printinchat(msg): vk.method("messages.send", {"peer_id": event.object.peer_id, "message": msg, "random_id": 0})
- whitelist = []
- questions = []
- answers = []
- if not os.path.exists("whitelist.txt"):
- with open("whitelist.txt", "w") as f:
- f.write("")
- if not os.path.exists("info.txt"):
- with open("info.txt", "w") as f:
- f.write("")
- if not os.path.exists("leaderboard.txt"):
- with open("leaderboard.txt", "w") as f:
- f.write("Лидерборд:")
- if not os.path.exists("q&a.txt"):
- with open("q&a.txt", "w") as f:
- f.write("Вопрос1 (введите /ответ ответ1)\nответ1\nВопрос2 (введите /ответ ответ2)\nответ2")
- with open ("q&a.txt", "r") as f:
- qa = f.read().split("\n")
- for i in range(0, len(qa), 2):
- questions.append(qa[i])
- for i in range(1, len(qa), 2):
- answers.append(qa[i])
- with open ("leaderboard.txt", "r") as f:
- leaderboard = f.read()
- stage = len(leaderboard.split("\n"))-1
- with open ("info.txt", "r") as f: info = f.read()
- with open ("whitelist.txt", "r") as f: whitelist = f.read().split("\n")
- vk = vk_api.VkApi(token="Тут тупа пажилой токен")
- vk._auth_token()
- vk.get_api()
- longpoll = VkBotLongPoll(vk, 186281584)
- for event in longpoll.listen():
- if event.type == VkBotEventType.MESSAGE_NEW:
- if str(event.object.peer_id - 2000000000) in whitelist:
- if "/меню" == event.object.text.lower(): printinchat("Команды:\n\n/вопрос\n/ответ [ответ]\n/меню (вы здесь)\n/лидерборд\n/инфо")
- if "/инфо" == event.object.text.lower(): printinchat("Информация:\n\n" + info + "\n\nЧтобы попасть в меню, напишите /меню")
- if "/вопрос" == event.object.text.lower() and stage != len(questions): printinchat("Вопрос " + str(stage + 1) + ":\n\n" + questions[stage] + "\n\nЧтобы попасть в меню, напишите /меню")
- elif stage == len(questions) and "/вопрос" == event.object.text.lower(): printinchat("Квест уже пройден!\n\nЧтобы попасть в меню, напишите /меню")
- if stage != len(questions) and event.object.text.lower() == "/ответ " + answers[stage].lower():
- stage += 1
- if event.object.from_id > 0:
- leaderboard = (leaderboard + "\n" + str(stage) + ". Вопрос: " + questions[stage - 1] + ". Ответ: " + answers[stage - 1] + ". Прошел(ла) @id" + str(event.object.from_id) + "!")
- printinchat("@id" + str(event.object.from_id) + " прошел(ла) " + str(stage) + " стадию квеста!")
- else:
- leaderboard = (leaderboard + "\n" + str(stage) + ". Вопрос: " + questions[stage - 1] + ". Ответ: " + answers[stage - 1] + ". Прошел(ла) @club" + str(event.object.from_id)[1:] + "!")
- printinchat("@club" + str(event.object.from_id)[1:] + " прошел(ла) " + str(stage) + " стадию квеста!")
- with open ("leaderboard.txt", "w") as f:
- f.write(leaderboard)
- leaderboard = leaderboard.replace(".. ", ". ")
- leaderboard = leaderboard.replace("?.", "?")
- leaderboard = leaderboard.replace("!.", "!")
- if stage == len(questions): printinchat("Квест пройден! Поздравляю всех участников!\n\nЧтобы попасть в меню, напишите /меню")
- else: printinchat("Следующий вопрос:\n\n" + questions[stage] + "\n\nЧтобы попасть в меню, напишите /меню")
- elif stage == len(questions) and event.object.text.lower()[:6] == "/ответ": printinchat("Квест уже пройден!\n\nЧтобы попасть в меню, напишите /меню")
- elif event.object.text.lower()[:6] == "/ответ": printinchat("Ответ неверный!\n\nЧтобы попасть в меню, напишите /меню")
- if event.object.text.lower() == "/лидерборд": printinchat(leaderboard + "\n\nЧтобы попасть в меню, напишите /меню")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement