deny for development

This commit is contained in:
Administrator 2023-10-11 19:08:09 +03:00
parent df4b61b09a
commit 86738de9ac
4 changed files with 32 additions and 0 deletions

View File

@ -7,8 +7,10 @@ services:
image: mathwave/sprint-repo:ruz-bot image: mathwave/sprint-repo:ruz-bot
environment: environment:
MONGO_HOST: "mongo.develop.sprinthub.ru" MONGO_HOST: "mongo.develop.sprinthub.ru"
STAGE: "development"
MONGO_PASSWORD: $MONGO_PASSWORD_DEV MONGO_PASSWORD: $MONGO_PASSWORD_DEV
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
command: bot command: bot
deploy: deploy:
mode: replicated mode: replicated

View File

@ -7,8 +7,10 @@ services:
image: mathwave/sprint-repo:ruz-bot image: mathwave/sprint-repo:ruz-bot
environment: environment:
MONGO_HOST: "mongo.sprinthub.ru" MONGO_HOST: "mongo.sprinthub.ru"
STAGE: "production"
MONGO_PASSWORD: $MONGO_PASSWORD_PROD MONGO_PASSWORD: $MONGO_PASSWORD_PROD
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_PROD TELEGRAM_TOKEN: $TELEGRAM_TOKEN_PROD
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
DEBUG: "false" DEBUG: "false"
command: bot command: bot
deploy: deploy:

View File

@ -1,13 +1,37 @@
import os import os
import telebot import telebot
from cachetools import TTLCache
from requests import get
from telebot.types import Message from telebot.types import Message
import settings
from helpers.mongo import mongo from helpers.mongo import mongo
bot = telebot.TeleBot(os.getenv("TELEGRAM_TOKEN")) bot = telebot.TeleBot(os.getenv("TELEGRAM_TOKEN"))
STAFF_CACHE = TTLCache(100, 60)
def is_staff(telegram_id):
print('there')
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:
return False
staff_data = staff_data.json()['is_staff']
STAFF_CACHE[telegram_id] = staff_data
return staff_data
@bot.message_handler(commands=['start']) @bot.message_handler(commands=['start'])
def on_start(message: Message): def on_start(message: Message):
mongo.users_collection.delete_many({"chat_id": message.chat.id}) mongo.users_collection.delete_many({"chat_id": message.chat.id})
@ -16,5 +40,7 @@ def on_start(message: Message):
@bot.message_handler() @bot.message_handler()
def do_action(message: Message): def do_action(message: Message):
if settings.STAGE == 'development' and not is_staff(message.chat.id):
return
from helpers.answer import Answer from helpers.answer import Answer
Answer(message).process() Answer(message).process()

View File

@ -6,6 +6,8 @@ MONGO_USER = os.getenv("MONGO_USER", "mongo")
MONGO_PASSWORD = os.getenv("MONGO_PASSWORD", "password") MONGO_PASSWORD = os.getenv("MONGO_PASSWORD", "password")
MONGO_HOST = os.getenv("MONGO_HOST", "localhost") MONGO_HOST = os.getenv("MONGO_HOST", "localhost")
DEBUG = os.getenv("DEBUG", "true") == "true" DEBUG = os.getenv("DEBUG", "true") == "true"
STAGE = os.getenv("STAGE", None)
PLATFORM_SECURITY_TOKEN = os.getenv('PLATFORM_SECURITY_TOKEN', None)
RUZ_API = "https://api.hseapp.ru/" RUZ_API = "https://api.hseapp.ru/"
MOSCOW_TIMEZONE = zoneinfo.ZoneInfo("Europe/Moscow") MOSCOW_TIMEZONE = zoneinfo.ZoneInfo("Europe/Moscow")