Skip to content
This repository was archived by the owner on Sep 29, 2021. It is now read-only.

Commit 0bbd8ef

Browse files
committed
Userbot: Finale I fix this error issue
1 parent a7246d5 commit 0bbd8ef

File tree

1 file changed

+79
-56
lines changed

1 file changed

+79
-56
lines changed

userbot/modules/admin.py

Lines changed: 79 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
EditBannedRequest,
1919
EditPhotoRequest)
2020
from telethon.tl.functions.messages import UpdatePinnedMessageRequest
21-
from telethon.tl.types import (PeerChannel, ChannelParticipantsAdmins,
22-
ChatAdminRights, ChatBannedRights,
23-
MessageEntityMentionName, MessageMediaPhoto,
24-
ChannelParticipantsBots)
21+
from telethon.tl.types import (PeerChannel, ChannelParticipantsAdmins,
22+
ChannelParticipantAdmin, ChatAdminRights,
23+
ChatBannedRights, MessageEntityMentionName,
24+
MessageMediaPhoto, ChannelParticipantsBots,
25+
ChannelParticipantCreator)
2526

2627
from userbot import BOTLOG, BOTLOG_CHATID, CMD_HELP, bot
2728
from userbot.events import register
@@ -615,24 +616,54 @@ async def tagaso(event):
615616
chat, mentions, reply_to=event.message.reply_to_msg_id)
616617

617618

618-
@register(outgoing=True, pattern="^.admins$")
619-
async def get_admin(show):
620-
""" For .admins command, list all of the admins of the chat. """
621-
info = await show.client.get_entity(show.chat_id)
619+
@register(outgoing=True, pattern="^.admins(?: |$)(.*)")
620+
async def _(event):
621+
if event.fwd_from:
622+
return
623+
info = await event.client.get_entity(event.chat_id)
622624
title = info.title if info.title else "this chat"
623-
mentions = f'<b>Admins in {title}:</b> \n'
625+
mentions = '**Admins On {} Group**: \n'.format(title)
626+
should_mention_admins = False
627+
reply_message = None
628+
pattern_match_str = event.pattern_match.group(1)
629+
if "m" in pattern_match_str:
630+
should_mention_admins = True
631+
if event.reply_to_msg_id:
632+
reply_message = await event.get_reply_message()
633+
input_str = event.pattern_match.group(1)
634+
to_write_chat = await event.get_input_chat()
635+
chat = None
636+
if not input_str:
637+
chat = to_write_chat
638+
else:
639+
try:
640+
chat = await bot.get_entity(input_str)
641+
except Exception as e:
642+
await event.edit(str(e))
643+
return None
624644
try:
625-
async for user in show.client.iter_participants(
626-
show.chat_id, filter=ChannelParticipantsAdmins):
627-
if not user.deleted:
628-
link = f"<a href=\"tg://user?id={user.id}\">{user.first_name}</a>"
629-
userid = f"<code>{user.id}</code>"
630-
mentions += f"\n{link} {userid}"
631-
else:
632-
mentions += f"\nDeleted Account <code>{user.id}</code>"
633-
except ChatAdminRequiredError as err:
634-
mentions += " " + str(err) + "\n"
635-
await show.edit(mentions, parse_mode="html")
645+
async for x in bot.iter_participants(chat, filter=ChannelParticipantsAdmins):
646+
if not x.deleted:
647+
if isinstance(x.participant, ChannelParticipantCreator):
648+
mentions += "\n 👑 [{}](tg://user?id={}) `{}`".format(x.first_name, x.id, x.id)
649+
mentions += "\n"
650+
async for x in bot.iter_participants(chat, filter=ChannelParticipantsAdmins):
651+
if not x.deleted:
652+
if isinstance(x.participant, ChannelParticipantAdmin):
653+
mentions += "\n 🔰 [{}](tg://user?id={}) `{}`".format(x.first_name, x.id, x.id)
654+
655+
# mentions += "\n 💘 [Deleted Account](tg://user?id=689811472) `689811472`"
656+
657+
except Exception as e:
658+
mentions += " " + str(e) + "\n"
659+
if should_mention_admins:
660+
if reply_message:
661+
await reply_message.reply(mentions)
662+
else:
663+
await event.reply(mentions)
664+
await event.delete()
665+
else:
666+
await event.edit(mentions)
636667

637668

638669
@register(outgoing=True, pattern="^.pin(?: |$)(.*)")
@@ -731,12 +762,12 @@ async def get_users(show):
731762
""" For .users command, list all of the users in a chat. """
732763
info = await show.client.get_entity(show.chat_id)
733764
title = info.title if info.title else "this chat"
734-
mentions = 'Users in {}: \n'.format(title)
765+
mentions = '**Users in {} Group**: \n'.format(title)
735766
try:
736767
if not show.pattern_match.group(1):
737768
async for user in show.client.iter_participants(show.chat_id):
738769
if not user.deleted:
739-
mentions += f"\n[{user.first_name}](tg://user?id={user.id}) `{user.id}`"
770+
mentions += f"\n ⚜️ [{user.first_name}](tg://user?id={user.id}) `{user.id}`"
740771
else:
741772
mentions += f"\nDeleted Account `{user.id}`"
742773
else:
@@ -905,42 +936,34 @@ async def get_userdel_from_id(user, event):
905936

906937
return user_obj
907938

908-
@register(outgoing=True, pattern="^.bots$", groups_only=True)
909-
async def get_bots(show):
910-
""" For .bots command, list all of the bots of the chat. """
911-
info = await show.client.get_entity(show.chat_id)
939+
@register(outgoing=True, pattern="^.bots(?: |$)(.*)")
940+
async def _(event):
941+
""" For .listbot command, list all of the bots of the chat. """
942+
if event.fwd_from:
943+
return
944+
info = await event.client.get_entity(event.chat_id)
912945
title = info.title if info.title else "this chat"
913-
mentions = f'<b>Bots in {title}:</b>\n'
914-
try:
915-
if isinstance(message.to_id, PeerChat):
916-
await show.edit("`I heard that only Supergroups can have bots.`")
917-
return
918-
else:
919-
async for user in show.client.iter_participants(
920-
show.chat_id, filter=ChannelParticipantsBots):
921-
if not user.deleted:
922-
link = f"<a href=\"tg://user?id={user.id}\">{user.first_name}</a>"
923-
userid = f"<code>{user.id}</code>"
924-
mentions += f"\n{link} {userid}"
925-
else:
926-
mentions += f"\nDeleted Bot <code>{user.id}</code>"
927-
except ChatAdminRequiredError as err:
928-
mentions += " " + str(err) + "\n"
946+
mentions = '**Bots in {} Group**: \n'.format(title)
947+
input_str = event.pattern_match.group(1)
948+
to_write_chat = await event.get_input_chat()
949+
chat = None
950+
if not input_str:
951+
chat = to_write_chat
952+
else:
953+
try:
954+
chat = await bot.get_entity(input_str)
955+
except Exception as e:
956+
await event.edit(str(e))
957+
return None
929958
try:
930-
await show.edit(mentions, parse_mode="html")
931-
except MessageTooLongError:
932-
await show.edit(
933-
"Damn, too many bots here. Uploading bots list as file.")
934-
file = open("botlist.txt", "w+")
935-
file.write(mentions)
936-
file.close()
937-
await show.client.send_file(
938-
show.chat_id,
939-
"botlist.txt",
940-
caption='Bots in {}'.format(title),
941-
reply_to=show.id,
942-
)
943-
remove("botlist.txt")
959+
async for x in bot.iter_participants(chat, filter=ChannelParticipantsBots):
960+
if isinstance(x.participant, ChannelParticipantAdmin):
961+
mentions += "\n 👑 [{}](tg://user?id={}) `{}`".format(x.first_name, x.id, x.id)
962+
else:
963+
mentions += "\n [{}](tg://user?id={}) `{}`".format(x.first_name, x.id, x.id)
964+
except Exception as e:
965+
mentions += " " + str(e) + "\n"
966+
await event.edit(mentions)
944967

945968

946969

0 commit comments

Comments
 (0)