From 85b6cc5c79da9776e017f80473febe18aee0e3c1 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 29 Dec 2024 17:22:09 +0300 Subject: [PATCH] Statistic module now separated --- s.py | 3 --- src/autobioebbing.py | 5 +++-- src/stat.py | 21 +++++++++++++++++++++ ubot.py | 13 +++---------- 4 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 src/stat.py diff --git a/s.py b/s.py index b2e9a60..8062674 100644 --- a/s.py +++ b/s.py @@ -2,7 +2,6 @@ This module stores config and states ''' from loguru import logger -from collections import Counter import os import sys import json @@ -104,5 +103,3 @@ class states: automine_enabled = config.automine latest_successfull_mine = None wait_before_next_mine = None - stats_medkit = 0 - stats_most_infect_spam_chats = Counter() diff --git a/src/autobioebbing.py b/src/autobioebbing.py index 2715a7e..06c601e 100644 --- a/src/autobioebbing.py +++ b/src/autobioebbing.py @@ -1,5 +1,6 @@ '''This is most huge module for autobioeb, autohealing and etc...''' from s import states, config, avocado_id +from src import stat from telethon import events, utils, functions from loguru import logger @@ -116,7 +117,7 @@ async def eb(client, c, conn, con, d, get_id, my_id, message_q): cinfo = await m.get_chat() chat_name = cinfo.title logger.debug(f"in chat '{chat_name}'") - states.stats_most_infect_spam_chats[chat_name] += 1 + stat.bio.most_infect_spam_chats[chat_name] += 1 t = m.raw_text if len(m.entities) > 1: h = utils.sanitize_parse_mode( @@ -455,7 +456,7 @@ async def eb(client, c, conn, con, d, get_id, my_id, message_q): mark_read=True, delete=False, ) - states.stats_medkit += 1 + stat.bio.medkit_usage += 1 states.last_reply_bioeb_avocado = int( datetime.timestamp(event.date)) logger.debug(ah.text) diff --git a/src/stat.py b/src/stat.py new file mode 100644 index 0000000..ef149dc --- /dev/null +++ b/src/stat.py @@ -0,0 +1,21 @@ + +from collections import Counter +from telethon import events + + +class bio: + medkit_usage = 0 + most_infect_spam_chats = Counter() + + +async def biomod(client): + @client.on(events.NewMessage(outgoing=True, pattern=r'\.bstat$')) + async def bio_stat(event): + stats_most_chats = bio.most_infect_spam_chats.most_common() + msg = "Session stats:\n" \ + f"Medkit usage: {bio.medkit_usage}\n" \ + f"Most common chats:\n" \ + f"{stats_most_chats}".replace(',', '\n') + await event.edit(msg) + + diff --git a/ubot.py b/ubot.py index 1c2910e..7049cc0 100644 --- a/ubot.py +++ b/ubot.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from s import is_termux, sessdb, default_directory, config, states -from src import autobioebbing, avocmine, victimsbackup, updatenotif +from s import is_termux, sessdb, default_directory, config +from src import autobioebbing, avocmine, victimsbackup, updatenotif, stat # from telethon.sync import TelegramClient # https://docs-python.ru/packages/telegram-klient-telethon-python/ <-info @@ -185,14 +185,7 @@ async def main(): asyncio.ensure_future(avocmine.automine_avocado_task(client)) - @client.on(events.NewMessage(outgoing=True, pattern=r'\.bstat$')) - async def bio_stat(event): - stats_most_chats = states.stats_most_infect_spam_chats.most_common() - msg = "Session stats:\n" \ - f"Medkit usage: {states.stats_medkit}\n" \ - f"Most common chats:\n" \ - f"{stats_most_chats}".replace(',', '\n') - await event.edit(msg) + await stat.biomod(client) @client.on(events.NewMessage(outgoing=True, pattern='.ping')) async def cmd_ping(event):