From c3e0da702979c64d01ebb478c08d1b55de46945a Mon Sep 17 00:00:00 2001 From: Olly Hearn Date: Wed, 28 Jan 2026 12:47:48 +0300 Subject: [PATCH] chore: misc --- docker-compose.yml | 4 ++-- handlers/command_handlers.py | 15 ++++++++++++--- handlers/group_handlers.py | 13 +++++++++++-- main.py | 2 +- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 55501af..ccb2161 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.8' +version: "3.8" services: postgres: @@ -9,7 +9,7 @@ services: POSTGRES_PASSWORD: postgres POSTGRES_DB: bdbot ports: - - "5432:5432" + - "5432" # Persist data in a local folder ./postgres_data volumes: - ./postgres_data:/var/lib/postgresql/data diff --git a/handlers/command_handlers.py b/handlers/command_handlers.py index 27fed90..ce01ceb 100644 --- a/handlers/command_handlers.py +++ b/handlers/command_handlers.py @@ -23,9 +23,18 @@ def register_command_handlers(bot: telebot.TeleBot) -> None: bot.reply_to(message, "Мне нужны права администратора для выполнения этой команды.") return - # Get total members count + # Get total members count (exclude bots) try: - total_members = bot.get_chat_member_count(chat_id) + total_members_raw = bot.get_chat_member_count(chat_id) + # Try to subtract all bots (including this bot) using admin list + human_members = total_members_raw + try: + admins = bot.get_chat_administrators(chat_id) + bots_in_admins = sum(1 for m in admins if getattr(m.user, "is_bot", False)) + human_members = max(total_members_raw - bots_in_admins, 0) + except Exception: + human_members = total_members_raw + total_members = human_members except Exception: total_members = 0 @@ -34,7 +43,7 @@ def register_command_handlers(bot: telebot.TeleBot) -> None: UserChat.chat_id == chat_id ).distinct().count() - users_without_birthday = total_members - users_with_birthday + users_without_birthday = max(total_members - users_with_birthday, 0) # Format message if total_members > 0: diff --git a/handlers/group_handlers.py b/handlers/group_handlers.py index 93f0f30..0f49f97 100644 --- a/handlers/group_handlers.py +++ b/handlers/group_handlers.py @@ -145,9 +145,18 @@ def show_statistics(bot: telebot.TeleBot, chat: telebot.types.Chat) -> None: try: chat_id = chat.id - # Get all chat members + # Get all chat members (exclude bots where possible) try: - members_count = bot.get_chat_member_count(chat_id) + members_count_raw = bot.get_chat_member_count(chat_id) + # Try to subtract all bots (including this bot) using admin list + human_members = members_count_raw + try: + admins = bot.get_chat_administrators(chat_id) + bots_in_admins = sum(1 for m in admins if getattr(m.user, "is_bot", False)) + human_members = max(members_count_raw - bots_in_admins, 0) + except Exception: + human_members = members_count_raw + members_count = human_members except Exception: members_count = 0 diff --git a/main.py b/main.py index caba575..aed3895 100644 --- a/main.py +++ b/main.py @@ -17,7 +17,7 @@ def main() -> None: scheduler_thread.start() # Start bot polling - print("Bot is starting...") + print("Bot is starting...", flush=True) bot.infinity_polling(none_stop=True)