From 4d2f61b1c2ce5cbf926b1f8623aeb9d8212bc42d Mon Sep 17 00:00:00 2001 From: ilyazheprog Date: Sun, 25 Feb 2024 03:59:26 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20/c?= =?UTF-8?q?hatID=20=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=20=D0=BF=D1=80=D0=B0=D0=B2=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D1=8F=20=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D0=B5=D0=B3=D1=80=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__init__.py | 3 ++- src/core/main.py | 2 +- src/modules/standard/admin/handlers.py | 7 +++++-- src/modules/standard/admin/routers.py | 7 +++++-- src/modules/standard/filters/admin.py | 6 ++++-- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/__init__.py b/src/__init__.py index fa7075c..2c9e6c4 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1 +1,2 @@ -import src.service \ No newline at end of file +import src.service +import src.core \ No newline at end of file diff --git a/src/core/main.py b/src/core/main.py index a7e7422..ea4a2bd 100644 --- a/src/core/main.py +++ b/src/core/main.py @@ -1,4 +1,4 @@ -from src.core.routers import include_routers +from routers import include_routers from src.modules.standard.config.config import get_telegram_token from src.modules.standard.database.api import connect_database, create_tables diff --git a/src/modules/standard/admin/handlers.py b/src/modules/standard/admin/handlers.py index 863f091..ef6afa2 100644 --- a/src/modules/standard/admin/handlers.py +++ b/src/modules/standard/admin/handlers.py @@ -6,5 +6,8 @@ async def delete_message(message: Message, bot: Bot): reply_message_id = message.reply_to_message.message_id await bot.delete_message(message.chat.id, reply_message_id) -async def delete_message_error_access(message: Message, bot: Bot): - await message.reply("Вы не админ/модератор") \ No newline at end of file +async def error_access(message: Message, bot: Bot): + await message.reply("Вы не админ/модератор") + +async def get_chat_id(message: Message, bot: Bot): + await message.reply(f"ID данного чата: `{message.chat.id}`", parse_mode="MarkdownV2") \ No newline at end of file diff --git a/src/modules/standard/admin/routers.py b/src/modules/standard/admin/routers.py index 45cb557..63df570 100644 --- a/src/modules/standard/admin/routers.py +++ b/src/modules/standard/admin/routers.py @@ -1,8 +1,11 @@ from aiogram import Router, F -from src.modules.standard.admin.handlers import delete_message, delete_message_error_access +from src.modules.standard.admin.handlers import delete_message, error_access, get_chat_id from src.modules.standard.filters.admin import ChatModerOrAdminFilter router = Router() +router.message.register(get_chat_id, ChatModerOrAdminFilter(), F.text == '/chatID') + router.message.register(delete_message, ChatModerOrAdminFilter(), F.text == '/rm') -router.message.register(delete_message_error_access, F.text == '/rm') \ No newline at end of file +router.message.register(error_access, F.text == '/rm') +router.message.register(error_access, F.text == '/chatID') \ No newline at end of file diff --git a/src/modules/standard/filters/admin.py b/src/modules/standard/filters/admin.py index f0c1c14..2b5547a 100644 --- a/src/modules/standard/filters/admin.py +++ b/src/modules/standard/filters/admin.py @@ -1,11 +1,13 @@ from aiogram.filters import BaseFilter from aiogram.types import Message +from aiogram import Bot from src.modules.standard.roles.api import Roles class ChatModerOrAdminFilter(BaseFilter): - async def __call__(self, message: Message) -> bool: + async def __call__(self, message: Message, bot: Bot) -> bool: user_id = message.from_user.id roles = Roles() + admins = await bot.get_chat_administrators(message.chat.id) return await roles.check_admin_permission(user_id) or \ - await roles.check_moderator_permission(user_id) + await roles.check_moderator_permission(user_id) or any(user_id == admin.user.id for admin in admins)