Skip to content
This repository has been archived by the owner on May 15, 2021. It is now read-only.

Improved .admins #54

Merged
merged 5 commits into from
Oct 24, 2020
Merged
Changes from all commits
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
53 changes: 29 additions & 24 deletions userge/plugins/utils/admins.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >.
#
# This file is part of < https://github.com/UsergeTeam/Userge > project,
# and is released under the "GNU v3.0 License Agreement".
# Please see < https://github.com/uaudith/Userge/blob/master/LICENSE >
#
# All rights reserved.

from userge import Message, userge
from userge.utils import mention_html


@userge.on_cmd(
Expand All @@ -23,43 +16,55 @@
allow_channels=False,
)
async def mentionadmins(message: Message):
mentions = "🛡 **Admin List** 🛡\n"
owner_ = ""
admins_ = ""
bots_ = ""
chat_id = message.filtered_input_str
flags = message.flags
men_admins = "-m" in flags
men_creator = "-mc" in flags
show_id = "-id" in flags
if not chat_id:
chat_id = message.chat.id
mentions = "<b>Admins in {}</b>\n\n".format(
(await message.client.get_chat(chat_id)).title
)
try:
async for x in message.client.iter_chat_members(
chat_id=chat_id, filter="administrators"
):
status = x.status
u_id = x.user.id
username = x.user.username or None
is_bot = x.user.is_bot
full_name = (await message.client.get_user_dict(u_id))["flname"]
if status == "creator":
if men_admins or men_creator:
mentions += f"\n 👑 [{full_name}](tg://user?id={u_id})"
owner_ += f"\n 👑 {mention_html(u_id, full_name)}"
elif username:
mentions += f"\n 👑 [{full_name}](https://t.me/{username})"
owner_ += f"\n 👑 [{full_name}](https://t.me/{username})"
else:
mentions += f"\n 👑 {full_name}"
owner_ += f"\n 👑 [{full_name}](tg://openmessage?user_id={u_id})"
if show_id:
mentions += f" `{u_id}`"
owner_ += f" `{u_id}`"
elif status == "administrator":
if men_admins:
mentions += f"\n >> [{full_name}](tg://user?id={u_id})"
elif username:
mentions += f"\n >> [{full_name}](https://t.me/{username})"
if is_bot:
bots_ += f"\n 🤖 {mention_html(u_id, full_name)}"
if show_id:
bots_ += f" `{u_id}`"
else:
mentions += f"\n >> {full_name}"
if show_id:
mentions += f" `{u_id}`"
if men_admins:
admins_ += f"\n • {mention_html(u_id, full_name)}"
elif username:
admins_ += f"\n • [{full_name}](https://t.me/{username})"
else:
admins_ += (
f"\n • [{full_name}](tg://openmessage?user_id={u_id})"
)
if show_id:
admins_ += f" `{u_id}`"

mentions += f"{owner_}\n{admins_}{bots_}"
except Exception as e:
mentions += " " + str(e) + "\n"
await message.delete()
await message.client.send_message(
chat_id=message.chat.id, text=mentions, disable_web_page_preview=True
)
await message.edit(mentions, disable_web_page_preview=True)