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

Commit

Permalink
Improved .admins (#54)
Browse files Browse the repository at this point in the history
* Update admins.py

* pylint: auto fixes

* Update admins.py
  • Loading branch information
code-rgb authored Oct 24, 2020
1 parent b2ba00a commit 4f17309
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 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,53 @@
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)

1 comment on commit 4f17309

@vercel
Copy link

@vercel vercel bot commented on 4f17309 Oct 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.