added global statistics
This commit is contained in:
1 parent
f9207e1f99
commit
8861fbbb4b
5 files changed
+91
No files matched your search
@@ -7,3 +7,4 @@ __pycache__/
|
||||
users
|
||||
users.*
|
||||
config.py
|
||||
stats/
|
||||
+43
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user