platform integration
This commit is contained in:
@@ -1,40 +1,15 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
import telebot
|
||||
from cachetools import TTLCache
|
||||
from requests import get
|
||||
from telebot.types import Message
|
||||
|
||||
import settings
|
||||
from helpers.mongo import mongo
|
||||
from helpers.platform import platform
|
||||
|
||||
bot = telebot.TeleBot(os.getenv("TELEGRAM_TOKEN"))
|
||||
|
||||
|
||||
STAFF_CACHE = TTLCache(100, 60)
|
||||
|
||||
|
||||
def is_staff(telegram_id):
|
||||
logging.info("is staff check")
|
||||
staff_data = STAFF_CACHE.get(telegram_id)
|
||||
if staff_data is None:
|
||||
staff_data = get(
|
||||
'https://platform.sprinthub.ru/is_staff',
|
||||
headers={'X-Security-Token': settings.PLATFORM_SECURITY_TOKEN},
|
||||
params={
|
||||
'telegram_id': telegram_id
|
||||
}
|
||||
)
|
||||
if staff_data.status_code != 200:
|
||||
logging.info('return status ' + str(staff_data.status_code))
|
||||
return False
|
||||
staff_data = staff_data.json()['is_staff']
|
||||
logging.info('got info ' + str(staff_data))
|
||||
STAFF_CACHE[telegram_id] = staff_data
|
||||
return staff_data
|
||||
|
||||
|
||||
@bot.message_handler(commands=['start'])
|
||||
def on_start(message: Message):
|
||||
mongo.users_collection.delete_many({"chat_id": message.chat.id})
|
||||
@@ -43,7 +18,7 @@ def on_start(message: Message):
|
||||
|
||||
@bot.message_handler()
|
||||
def do_action(message: Message):
|
||||
if settings.STAGE == 'development' and not is_staff(message.chat.id):
|
||||
if settings.STAGE == 'development' and not platform.get_staff(message.chat.id):
|
||||
return
|
||||
from helpers.answer import Answer
|
||||
Answer(message).process()
|
||||
|
||||
Reference in New Issue
Block a user