SHARE
TWEET

Untitled

Sasha07 Mar 9th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Скрипт был создан автором канала IT THINGS: https://www.youtube.com/c/ITTHINGS
  2.  
  3. from flask import Flask, request, json
  4.  
  5. import vk_api
  6. import random
  7.  
  8. vk = vk_api.VkApi(token="токен бота")
  9.  
  10. app = Flask(__name__)
  11.  
  12. @app.route('/', methods = ["POST"])
  13. def main():
  14.     data = json.loads(request.data)
  15.     if data["type"] == "confirmation":
  16.         return "код подтверждения"
  17.     elif data["type"] == "message_new":
  18.         object = data["object"]
  19.         id = object["peer_id"]
  20.         body = object["text"]
  21.         if body.lower() == "привет":
  22.                 vk.method("messages.send", {"peer_id": id, "message": "Привет!", "random_id": random.randint(1, 2147483647)})
  23.         elif body.lower() == "я не подписан на канал it things":
  24.                 vk.method("messages.send", {"peer_id": id, "message": "Казнить грешника!", "random_id": random.randint(1, 2147483647)})
  25.         else:
  26.             vk.method("messages.send", {"peer_id": id, "message": "Не понял тебя!", "random_id": random.randint(1, 2147483647)})
  27.     return "ok"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top