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

Commit 251c941

Browse files
Mr.MissMoveAngel
authored andcommitted
whois: handle anonymous admin
anonymous admin have no id attributes that make the bot crash when fetching. This just handle if the user_id return a NoneType. Co-authored-by: Mr.Miss <[email protected]> Signed-off-by: MoveAngel <[email protected]>
1 parent 0807fb2 commit 251c941

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

userbot/modules/whois.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ async def who(event):
2929
os.makedirs(TEMP_DOWNLOAD_DIRECTORY)
3030

3131
replied_user = await get_user(event)
32+
if replied_user is None:
33+
await event.edit("`This is anonymous admin in this group.\nCan't fetch the info`")
34+
return
3235

3336
try:
3437
photo, caption = await fetch_info(replied_user, event)
3538
except AttributeError:
36-
event.edit("`Could not fetch info of that user.`")
39+
await event.edit("`Could not fetch info of that user.`")
3740
return
3841

3942
message_id_to_reply = event.message.reply_to_msg_id
@@ -64,7 +67,10 @@ async def get_user(event):
6467
""" Get the user from argument or replied message. """
6568
if event.reply_to_msg_id and not event.pattern_match.group(1):
6669
previous_message = await event.get_reply_message()
67-
replied_user = await event.client(GetFullUserRequest(previous_message.from_id))
70+
if previous_message.from_id is None: # Anonymous admin seems don't have id attr
71+
return None
72+
replied_user = await event.client(
73+
GetFullUserRequest(previous_message.from_id))
6874
else:
6975
user = event.pattern_match.group(1)
7076

@@ -155,6 +161,6 @@ async def fetch_info(replied_user, event):
155161
CMD_HELP.update(
156162
{
157163
"whois": ".whois <username> or reply to someones text with .whois\
158-
\nUsage: Gets info of an user."
164+
\nUsage: Gets info of an user."
159165
}
160166
)

0 commit comments

Comments
 (0)