Advertisement
800gen

Квестбот [финал]

Sep 15th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
  2. import vk_api
  3. import os
  4.  
  5. def printinchat(msg): vk.method("messages.send", {"peer_id": event.object.peer_id, "message": msg, "random_id": 0})
  6.  
  7. whitelist = []
  8. questions = []
  9. answers = []
  10.  
  11. if not os.path.exists("whitelist.txt"):
  12. with open("whitelist.txt", "w") as f:
  13. f.write("")
  14.  
  15. if not os.path.exists("info.txt"):
  16. with open("info.txt", "w") as f:
  17. f.write("")
  18.  
  19. if not os.path.exists("leaderboard.txt"):
  20. with open("leaderboard.txt", "w") as f:
  21. f.write("Лидерборд:")
  22.  
  23. if not os.path.exists("q&a.txt"):
  24. with open("q&a.txt", "w") as f:
  25. f.write("Вопрос1 (введите /ответ ответ1)\nответ1\nВопрос2 (введите /ответ ответ2)\nответ2")
  26.  
  27. with open ("q&a.txt", "r") as f:
  28. qa = f.read().split("\n")
  29. for i in range(0, len(qa), 2):
  30. questions.append(qa[i])
  31. for i in range(1, len(qa), 2):
  32. answers.append(qa[i])
  33.  
  34. with open ("leaderboard.txt", "r") as f:
  35. leaderboard = f.read()
  36. stage = len(leaderboard.split("\n"))-1
  37.  
  38. with open ("info.txt", "r") as f: info = f.read()
  39.  
  40. with open ("whitelist.txt", "r") as f: whitelist = f.read().split("\n")
  41.  
  42. vk = vk_api.VkApi(token="Тут тупа пажилой токен")
  43. vk._auth_token()
  44. vk.get_api()
  45. longpoll = VkBotLongPoll(vk, 186281584)
  46.  
  47. for event in longpoll.listen():
  48. if event.type == VkBotEventType.MESSAGE_NEW:
  49. if str(event.object.peer_id - 2000000000) in whitelist:
  50. if "/меню" == event.object.text.lower(): printinchat("Команды:\n\n/вопрос\n/ответ [ответ]\n/меню (вы здесь)\n/лидерборд\n/инфо")
  51.  
  52. if "/инфо" == event.object.text.lower(): printinchat("Информация:\n\n" + info + "\n\nЧтобы попасть в меню, напишите /меню")
  53.  
  54. if "/вопрос" == event.object.text.lower() and stage != len(questions): printinchat("Вопрос " + str(stage + 1) + ":\n\n" + questions[stage] + "\n\nЧтобы попасть в меню, напишите /меню")
  55. elif stage == len(questions) and "/вопрос" == event.object.text.lower(): printinchat("Квест уже пройден!\n\nЧтобы попасть в меню, напишите /меню")
  56.  
  57. if stage != len(questions) and event.object.text.lower() == "/ответ " + answers[stage].lower():
  58. stage += 1
  59. if event.object.from_id > 0:
  60. leaderboard = (leaderboard + "\n" + str(stage) + ". Вопрос: " + questions[stage - 1] + ". Ответ: " + answers[stage - 1] + ". Прошел(ла) @id" + str(event.object.from_id) + "!")
  61. printinchat("@id" + str(event.object.from_id) + " прошел(ла) " + str(stage) + " стадию квеста!")
  62. else:
  63. leaderboard = (leaderboard + "\n" + str(stage) + ". Вопрос: " + questions[stage - 1] + ". Ответ: " + answers[stage - 1] + ". Прошел(ла) @club" + str(event.object.from_id)[1:] + "!")
  64. printinchat("@club" + str(event.object.from_id)[1:] + " прошел(ла) " + str(stage) + " стадию квеста!")
  65. with open ("leaderboard.txt", "w") as f:
  66. f.write(leaderboard)
  67. leaderboard = leaderboard.replace(".. ", ". ")
  68. leaderboard = leaderboard.replace("?.", "?")
  69. leaderboard = leaderboard.replace("!.", "!")
  70. if stage == len(questions): printinchat("Квест пройден! Поздравляю всех участников!\n\nЧтобы попасть в меню, напишите /меню")
  71. else: printinchat("Следующий вопрос:\n\n" + questions[stage] + "\n\nЧтобы попасть в меню, напишите /меню")
  72. elif stage == len(questions) and event.object.text.lower()[:6] == "/ответ": printinchat("Квест уже пройден!\n\nЧтобы попасть в меню, напишите /меню")
  73. elif event.object.text.lower()[:6] == "/ответ": printinchat("Ответ неверный!\n\nЧтобы попасть в меню, напишите /меню")
  74.  
  75. if event.object.text.lower() == "/лидерборд": printinchat(leaderboard + "\n\nЧтобы попасть в меню, напишите /меню")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement