Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possible ignore hidden admins in report cmd #112

Merged
merged 2 commits into from
May 25, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions app/handlers/moderator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,36 @@ async def report_private(message: types.Message):
await message.reply("Вы можете жаловаться на сообщения пользователей только в группах.")


async def get_mentions_admins(chat: types.Chat, bot: Bot):
async def get_mentions_admins(
chat: types.Chat,
bot: Bot,
ignore_anonymous: bool = True,
ignore_bot: bool = True,
):
admins = await bot.get_chat_administrators(chat.id)
admins_mention = ""
for admin in admins:
if admin.user.is_bot:
continue
if need_notify_admin(admin):
if need_notify_admin(admin, ignore_anonymous, ignore_bot):
admins_mention += hd.link("⁠", admin.user.url)
return admins_mention


def need_notify_admin(admin: types.ChatMemberAdministrator | types.ChatMemberOwner):
def need_notify_admin(
admin: types.ChatMemberAdministrator | types.ChatMemberOwner,
ignore_anonymous: bool = True,
ignore_bot: bool = True,
):
"""
Проверяет, нужно ли уведомлять администратора о жалобе.

:param admin: Администратор, которого нужно проверить.
:param ignore_anonymous: Игнорировать ли анонимных администраторов.
:param ignore_bot: Игнорировать ли ботов.
"""
if ignore_bot and admin.user.is_bot:
return False
Desiders marked this conversation as resolved.
Show resolved Hide resolved
if ignore_anonymous and admin.is_anonymous:
return False
return admin.can_delete_messages or admin.can_restrict_members or admin.status == "creator"


Expand Down