Skip to content
This repository was archived by the owner on Nov 3, 2022. It is now read-only.

Commit 46a239d

Browse files
KenHVMr.Miss
authored andcommitted
afk: don't crash if an anonymous message mentions user
get_sender() returns None if telegram didn't send the sender. this leads to the bot crashing whenever an anonymous message mentions the user, as the afk event handler doesn't account for this case. let's add a check to handle this case. Signed-off-by: Mr.Miss <keselekpermen@mrmiss.wtf>
1 parent ea0e150 commit 46a239d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

userbot/modules/afk.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,7 @@ async def mention_afk(mention):
135135
back_alivee = datetime.now()
136136
afk_end = back_alivee.replace(microsecond=0)
137137
afk_since = "a while ago"
138-
if (
139-
mention.message.mentioned
140-
and not (await mention.get_sender()).bot
141-
and ISAFK
142-
):
138+
if ISAFK and mention.message.mentioned:
143139
now = datetime.now()
144140
datime_since_afk = now - afk_time # pylint:disable=E0602
145141
time = float(datime_since_afk.seconds)
@@ -167,14 +163,18 @@ async def mention_afk(mention):
167163
afk_since = f"`{int(minutes)}m{int(seconds)}s` ago"
168164
else:
169165
afk_since = f"`{int(seconds)}s` ago"
170-
if mention.sender_id not in USERS:
166+
167+
is_bot = False
168+
if (sender := await mention.get_sender()):
169+
is_bot = sender.bot
170+
if not is_bot and mention.sender_id not in USERS:
171171
if AFKREASON:
172172
await mention.reply(f"I'm AFK since {afk_since}.\
173173
\nReason: `{AFKREASON}`")
174174
else:
175175
await mention.reply(str(choice(AFKSTR)))
176176
USERS.update({mention.sender_id: 1})
177-
else:
177+
elif not is_bot and sender:
178178
if USERS[mention.sender_id] % randint(2, 4) == 0:
179179
if AFKREASON:
180180
await mention.reply(f"I'm still AFK since {afk_since}.\

0 commit comments

Comments
 (0)