Statistic module now separated

This commit is contained in:
Your Name 2024-12-29 17:22:09 +03:00
parent 33178a041a
commit 85b6cc5c79
4 changed files with 27 additions and 15 deletions

3
s.py
View file

@ -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()

View file

@ -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)

21
src/stat.py Normal file
View file

@ -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)

13
ubot.py
View file

@ -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):