Advertisement
Platitude

Untitled

Apr 28th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. from aiogram.contrib.fsm_storage.memory import MemoryStorage
  2. import telebot, logging, requests, json, time
  3. from telebot import types
  4. import urllib3
  5. import flask
  6. from flask_cors import CORS
  7. import requests
  8. import logging, asyncore, aiogram
  9. from aiogram import Bot, Dispatcher, executor, types
  10. from aiogram.dispatcher.filters import Text, Command
  11. from aiogram import Bot, Dispatcher, executor
  12.  
  13. from callback_data_factory import *
  14. from aiogram.utils.callback_data import CallbackData
  15.  
  16. API_TOKEN = 'token'
  17. logging.basicConfig(level=logging.INFO)
  18.  
  19. storage = MemoryStorage()
  20. bot = Bot(token=API_TOKEN)
  21. dp = Dispatcher(bot)
  22. app = flask.Flask(__name__)
  23. app.config['JSON_AS_ASCII'] = False
  24.  
  25.  
  26. @app.route('/token', methods=['POST'])
  27. def webhook():
  28. if flask.request.headers.get('content-type') == 'application/json':
  29. json_string = flask.request.get_data().decode('utf-8')
  30. update = telebot.types.Update.de_json(json_string)
  31. bot.process_new_updates([update]) #ТУТ ОН РУГАЕТСЯ (Unresolved attribute reference 'process_new_updates' for class 'Bot')
  32. return ''
  33. else:
  34. flask.abort(403)
  35.  
  36. def main_menu(message):
  37. user_id = message.chat.id
  38. r = requests.post(http_getusertoken, json={"password": "1488", "telegram_id": int(user_id)})
  39. print(r.json())
  40. print(r.status_code)
  41. if r.json()['msg'] == "ok":
  42. keyboard = types.InlineKeyboardMarkup(True)
  43. row = [types.InlineKeyboardButton(text="Пройти тест", callback_data="Test")]
  44. keyboard.row(*row)
  45. row = [types.InlineKeyboardButton(text="Личная информация", callback_data="personal_information")]
  46. keyboard.row(*row)
  47. row = [types.InlineKeyboardButton(text="Перейти на сайт", url="https://howtostudy.ru/home")]
  48. keyboard.row(*row)
  49. row = [types.InlineKeyboardButton(text="Выйти", callback_data="exit")]
  50. keyboard.row(*row)
  51. return keyboard
  52. else:
  53. keyboard = types.InlineKeyboardMarkup(True)
  54. row = [types.InlineKeyboardButton(text="Регистрация", callback_data="registration")]
  55. keyboard.row(*row)
  56. row = [types.InlineKeyboardButton(text="Авторизация", callback_data="auth")]
  57. keyboard.row(*row)
  58. row = [types.InlineKeyboardButton(text="Перейти на сайт", callback_data=" ", url="https://howtostudy.ru/home")]
  59. keyboard.row(*row)
  60. return keyboard
  61.  
  62.  
  63. @dp.message_handler(state='*', commands=["start"])
  64. @dp.message_handler(Text(equals='начать', ignore_case=True), state='*')
  65. async def send_welcome(message):
  66. img = open("./logo.jpg", "rb")
  67. await bot.send_photo(message.chat.id, img,
  68. caption="Добро пожаловать на платформу онлайн тестирования",
  69. reply_markup=main_menu(message))
  70.  
  71. @dp.callback_query_handler(func=lambda call: True)
  72. def callback_btn(call):
  73. data = call.data
  74.  
  75.  
  76.  
  77. async def back_main_menu(message):
  78. await bot.edit_message_caption("Добро пожаловать на платформу онлайн тестирования", message.chat.id, message.message_id,
  79. reply_markup=main_menu(message))
  80.  
  81.  
  82. WEBHOOK_SSL_CERT = './webhook_cert.pem'
  83. WEBHOOK_SSL_PRIV = './webhook_pkey.pem'
  84.  
  85. if __name__ == '__main__':
  86. cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
  87. bot.delete_webhook()
  88. bot.set_webhook("https://name.ru/token",
  89. certificate=open('./webhook_cert.pem', 'r'))
  90. app.run(host='0.0.0.0', port=5006, ssl_context=(WEBHOOK_SSL_CERT, WEBHOOK_SSL_PRIV), debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement