mirror of
https://gitflic.ru/project/maks1ms/ocab.git
synced 2024-12-23 16:23:01 +03:00
Добавил /chatID
Проверка админ прав используя телеграм
This commit is contained in:
parent
4d6ee64731
commit
4d2f61b1c2
@ -1 +1,2 @@
|
||||
import src.service
|
||||
import src.service
|
||||
import src.core
|
@ -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
|
||||
|
||||
|
@ -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("Вы не админ/модератор")
|
||||
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")
|
@ -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')
|
||||
router.message.register(error_access, F.text == '/rm')
|
||||
router.message.register(error_access, F.text == '/chatID')
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user