try
All checks were successful
Deploy Dev / Build (pull_request) Successful in 5s
Deploy Dev / Push (pull_request) Successful in 8s
Deploy Dev / Deploy dev (pull_request) Successful in 13s

This commit is contained in:
2024-11-17 12:58:09 +03:00
parent 9e472f03a4
commit 7b77ca2f56
12 changed files with 315 additions and 153 deletions

138
main.py
View File

@@ -1,137 +1,15 @@
import datetime
import os
import sys
from random import randrange, choice
import telebot
from telebot.types import Message
from mongo import mongo
from sprint_platform import PlatformClient
from storage import set_values, get_chat_info
bot = telebot.TeleBot(os.getenv("TELEGRAM_TOKEN"))
security_token = os.getenv("PLATFORM_SECURITY_TOKEN")
stage = os.getenv("STAGE", 'local')
client = PlatformClient(
security_token,
'Pizda Bot',
stage,
['constants', 'answers', 'replies'],
[],
need_poll=True,
)
all_letters = "йцукенгшщзхъёфывапролджэячсмитьбюЙЦУКЕНГШЩЗХЪЁФЫВАПРОЛДЖЭЯЧСМИТЬБЮQWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890 "
def get_self_name():
return client.get_config('constants')['self_name']
def get_answers():
return client.get_config('answers')
def get_replies():
return client.get_config('replies')
@bot.message_handler(commands=['setprobability'])
def set_probability(message: Message):
bot.send_message(message.chat.id, "Отправь одно число - вероятность парирования")
set_values(message.chat.id, state="set_probability")
@bot.message_handler(commands=['rating'])
def show_rating(message: Message):
rating = list(mongo.counter_collection.find({"chat_id": message.chat.id}).sort("count", -1))
if not rating:
bot.send_message(message.chat.id, "В этом чате я пока никому не парировал")
return
text = "Вот кому я парировал:\n"
rating_arr = list(enumerate(rating))
total = 0
for _, value in rating_arr:
total += value['count']
for index, value in rating_arr:
text += f"{index + 1}. @{value['username']} - {value['count']} ({int(value['count'] / total * 100)}%)\n"
bot.send_message(message.chat.id, text)
@bot.message_handler(commands=['point'])
def point(message: Message):
if not message.reply_to_message:
bot.reply_to(message, 'Чтобы начислить Ебаллы, нужно прописать команду ответом на чье-то сообщение')
return
username = message.reply_to_message.from_user.username
if username == get_self_name():
bot.reply_to(message, 'Ты конченый? Как я себе Ебаллы то начислю, мудила? Мамке своей Ебаллы начисляй, пидор!')
return
mongo.inc_points(username, message.chat.id)
bot.reply_to(message.reply_to_message, 'Тебе начислили Ебалл!')
@bot.message_handler(commands=['pointers'])
def pointers(message: Message):
rating = list(mongo.counter_collection.find({"chat_id": message.chat.id, "points": {"$exists": True}}).sort("points", -1))
if not rating:
bot.send_message(message.chat.id, "Ебаллы пока никому не начислялись")
return
text = "Рейтинг Ебальников:\n"
rating_arr = list(enumerate(rating))
total = 0
for _, value in rating_arr:
total += value['points']
for index, value in rating_arr:
text += f"{index + 1}. @{value['username']} - {value['points']}\n"
bot.send_message(message.chat.id, text)
@bot.message_handler()
def do_action(message: Message):
if message.reply_to_message:
if message.reply_to_message.from_user.username == get_self_name():
bot.reply_to(message, choice(get_replies()))
return
info = get_chat_info(message.chat.id)
if client.get_config('updater')['enabled']:
set_values(message.chat.id, last_time_updated=datetime.datetime.now())
if message.text == '#debug' and client.is_staff(telegram_id=message.from_user.id):
bot.send_message(message.chat.id, f'chat id: {message.chat.id}\n'
f'probability: {info["probability"]}')
return
if info['state'] == "set_probability":
try:
value = int(message.text)
if value < 0 or value > 100:
bot.reply_to(message, "Число не попадает в диапозон от 0 до 100!")
else:
set_values(message.chat.id, probability=value, state="default")
bot.reply_to(message, "Ок! Установил")
except ValueError:
bot.reply_to(message, "Это не число!")
return
convert_text = ''.join([letter for letter in message.text if letter in all_letters]).lower().split()
if len(convert_text) > 0:
convert_text = convert_text[-1]
else:
return
ans = get_answers().get(convert_text)
if ans is not None and randrange(1, 101) <= info["probability"]:
bot.reply_to(message, ans)
mongo.inc(message.from_user.username, message.chat.id)
arg = sys.argv[-1]
if arg == 'bot':
bot.polling()
elif arg == 'updater':
from updater import update
update()
if arg == 'poll':
from daemons import poll
daemon = poll.Daemon()
elif arg == 'worker':
from daemons import worker
daemon = worker.Daemon()
else:
from api import app
app.run(host="0.0.0.0", port=1238)
daemon.execute()