This commit is contained in:
Administrator 2023-09-30 09:30:49 +03:00
parent 36a3585280
commit 2cbcecf35c

53
main.py
View File

@ -1,5 +1,5 @@
import os
from random import randrange
from random import randrange, choice
import telebot
from cachetools import TTLCache
@ -49,6 +49,12 @@ DEFAULT_ANSWERS = {
"здрасьте": "Пизду покрасьте!"
}
DEFAULT_REPLIES = [
"Пошел нахуй!",
"Я твою маму ебал!",
"Ты пидор!",
]
bot = telebot.TeleBot(os.getenv("TELEGRAM_TOKEN"))
security_token = os.getenv("PLATFORM_SECURITY_TOKEN")
stage = os.getenv("STAGE")
@ -58,6 +64,27 @@ all_letters = "йцукенгшщзхъёфывапролджэячсмитьб
CACHE_CONFIG = TTLCache(1, 60)
SELF_NAME = None
def get_self_name():
global SELF_NAME
if SELF_NAME:
return SELF_NAME
answers_response = get(
'https://platform.sprinthub.ru/configs/get',
headers={'X-Security-Token': security_token},
params={
'project': "Pizda Bot",
'stage': stage,
'name': "constants"
}
)
if answers_response.status_code != 200:
print("ERROR")
return 'answer_da_bot'
SELF_NAME = answers_response.json()['self_name']
return SELF_NAME
def get_answers():
@ -80,6 +107,26 @@ def get_answers():
return answers
def get_replies():
answers = CACHE_CONFIG.get('replies')
if answers is None:
answers_response = get(
'https://platform.sprinthub.ru/configs/get',
headers={'X-Security-Token': security_token},
params={
'project': "Pizda Bot",
'stage': stage,
'name': "replies"
}
)
if answers_response.status_code != 200:
print("ERROR")
return DEFAULT_REPLIES
answers = answers_response.json()
CACHE_CONFIG['answers'] = answers
return answers
@bot.message_handler(commands=['setprobability'])
def set_probability(message: Message):
bot.send_message(message.chat.id, "Отправь одно число - вероятность парирования")
@ -104,6 +151,10 @@ def show_rating(message: Message):
@bot.message_handler()
def do_action(message: Message):
if message.reply_to_message:
if message.reply_to_message.from_user.username == 'localdevelopmentsprintbot':
bot.reply_to(message, choice(get_replies()))
return
info = get_chat_info(message.chat.id)
if info['state'] == "set_probability":
try: