From 8861fbbb4b28b04fbf6428c689744060ce26edd7 Mon Sep 17 00:00:00 2001 From: huker667 Date: Sat, 23 May 2026 18:09:50 +0300 Subject: added global statistics --- .gitignore | 1 + commands.py | 43 +++++++++++++++++++++++++++++++++++++++++++ main.py | 9 +++++++++ statistics.py | 30 ++++++++++++++++++++++++++++++ supergenerator.py | 8 ++++++++ 5 files changed, 91 insertions(+) create mode 100644 statistics.py diff --git a/.gitignore b/.gitignore index 075eefc..280da93 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ __pycache__/ users users.* config.py +stats/ diff --git a/commands.py b/commands.py index ace141e..afec430 100644 --- a/commands.py +++ b/commands.py @@ -20,12 +20,53 @@ from aiogram.types import ( ) from aiogram.utils.deep_linking import create_start_link +from collections import Counter + from colors import * from config import * +from statistics import * from supergenerator import * router = Router() +@router.message(Command("stats")) +async def stats_handler(message: Message): + users = get_all_users() + + total_users = len(users) + + models = Counter() + streams = Counter() + calls = Counter() + + for data in users.values(): + if isinstance(data, dict): + models[data.get("model")] += 1 + streams[data.get("stream")] += 1 + calls[data.get("call")] += 1 + + top_models = models.most_common(3) + top_streams = streams.most_common(3) + + text = [ + "✅ *общая статистика*", + f"☝️пользователей: {total_users}", + f"📞всего генераций: {get_stats('stats/gens')}", + f"👻ген в гостевом: {get_stats('stats/guest')}", + f"🙏ген в инлайне: {get_stats('stats/inline')}", + f"🤝ben: {get_stats('stats/ben')}", + f"🤝reporn: {get_stats('stats/reporn')}", + "🥺топ моделей:", + *(f"- `{m}`: {c}" for m, c in top_models), + "✍️топ режимов стрима:", + *(f"- `{s}`: {c}" for s, c in top_streams), + "👀топ режимов вызова:", + *(f"- `{c}`: {n}" for c, n in calls.most_common()), + ] + + await message.reply("\n".join(text)) + + @router.message(Command("broadcast")) async def broadcast_handler(message: Message): @@ -63,6 +104,7 @@ async def start_handler(message: Message): await message.reply( "вы забанены за Botting, spamming, and coordinated inauthentic behavior.😡✅" ) + add_one_to("stats/ben") return @@ -74,6 +116,7 @@ async def start_handler(message: Message): await message.reply( f"отправлен репорт на {user_name}!" ) + add_one_to("stats/reporn") return diff --git a/main.py b/main.py index be7161a..fbfe211 100644 --- a/main.py +++ b/main.py @@ -27,6 +27,7 @@ from aiogram.types import ( Message, ) from callbacks import * +from statistics import * from colors import * from commands import * from dotenv import load_dotenv @@ -170,6 +171,7 @@ async def guest_middleware(handler, event, data): user_id=user_id, message_id=None, ) + add_one_to("stats/guest") try: await data["bot"]( AnswerGuestQuery( @@ -434,6 +436,8 @@ async def chosen_inline_result_handler(chosen_result: ChosenInlineResult): inline_message_id = chosen_result.inline_message_id user_id = chosen_result.from_user.id + add_one_to("stats/inline") + if chosen_result.query == "clear": user_contexts[user_id] = [] else: @@ -485,6 +489,11 @@ async def chosen_inline_result_handler(chosen_result: ChosenInlineResult): async def main(): + ensure_path("stats/gens") + ensure_path("stats/inline") + ensure_path("stats/guest") + ensure_path("stats/ben") + ensure_path("stats/reporn") await bot.delete_webhook(drop_pending_updates=True) await dp.start_polling( bot, diff --git a/statistics.py b/statistics.py new file mode 100644 index 0000000..6a98ff4 --- /dev/null +++ b/statistics.py @@ -0,0 +1,30 @@ +import os + + +def ensure_path(path, default="0"): + os.makedirs(os.path.dirname(path) or ".", exist_ok=True) + + if not os.path.exists(path): + with open(path, "w") as f: + f.write(default) + + +def add_one_to(path): + try: + with open(path, "r") as f: + total = int(f.read().strip()) + except: + total = 0 + + total += 1 + + with open(path, "w") as f: + f.write(str(total)) + + +def get_stats(path): + try: + with open(path) as f: + return int(f.read().strip()) + except: + return 0 diff --git a/supergenerator.py b/supergenerator.py index e3827f5..83c359b 100644 --- a/supergenerator.py +++ b/supergenerator.py @@ -6,6 +6,7 @@ from configparser import DEFAULTSECT from openai import AsyncOpenAI +from statistics import * from colors import * from config import * @@ -111,6 +112,11 @@ def remove_think_tags(text): return result +def get_all_users(): + with shelve.open("users") as db: + return {k: db[k] for k in db.keys()} + + def get_all_user_ids(): ids = [] with shelve.open("users") as db: @@ -195,6 +201,8 @@ async def generate( text = "" + add_one_to("stats/gens") + client = providers[model[0]] text = await openai_generate_text( oai=client, -- cgit v1.3.1