diff --git a/olgram/commands/info.py b/olgram/commands/info.py new file mode 100644 index 0000000..c7eb568 --- /dev/null +++ b/olgram/commands/info.py @@ -0,0 +1,26 @@ +""" +Здесь метрики +""" + +from aiogram import types +from aiogram.dispatcher import FSMContext +from olgram.models import models + +from olgram.router import dp +from olgram.settings import OlgramSettings + + +@dp.message_handler(commands=["info"], state="*") +async def info(message: types.Message, state: FSMContext): + """ + Команда /info + """ + + if message.from_user.id != OlgramSettings.supervisor_id(): + return + + bots_count = len(await models.Bot.all()) + user_count = len(await models.User.all()) + + await message.answer(f"Количество ботов: {bots_count}" + f"Количество пользователей: {user_count}") diff --git a/olgram/settings.py b/olgram/settings.py index b107075..515acf8 100644 --- a/olgram/settings.py +++ b/olgram/settings.py @@ -38,6 +38,12 @@ class OlgramSettings(AbstractSettings): _id = cls._get_env("ADMIN_ID", True) return int(_id) if _id else None + @classmethod + @lru_cache + def supervisor_id(cls): + _id = cls._get_env("SUPERVISOR_ID", True) + return int(_id) if _id else None + class ServerSettings(AbstractSettings): @classmethod