Skip to content

Commit

Permalink
perf: offer response for wrong message link
Browse files Browse the repository at this point in the history
- Offer response when receiving url which is not a message link.
  • Loading branch information
hlf20010508 committed Sep 15, 2023
1 parent f724a30 commit 6be400b
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,22 @@ async def callback(current, total):
else:
msg_link = get_link(event.text)
if msg_link:
chat = ""
if "?single" in msg_link:
msg_link = msg_link.split("?single")[0]
msg_id = int(msg_link.split("/")[-1])
if 't.me/c/' in msg_link:
if 't.me/b/' in msg_link:
chat = str(msg_link.split("/")[-2])
else:
chat = int('-100' + str(msg_link.split("/")[-2]))

message = await tg_client.get_messages(chat, ids=msg_id)
try:
chat = ""
if "?single" in msg_link:
msg_link = msg_link.split("?single")[0]
msg_id = int(msg_link.split("/")[-1])
if 't.me/c/' in msg_link:
if 't.me/b/' in msg_link:
chat = str(msg_link.split("/")[-2])
else:
chat = int('-100' + str(msg_link.split("/")[-2]))

message = await tg_client.get_messages(chat, ids=msg_id)
except:
logger('Not message link.')
await event.reply("Please offer a message link.\n\nUse /help for available command.")
raise events.StopPropagation

if message:
try:
Expand All @@ -474,6 +479,7 @@ async def callback(current, total):
await event.reply(logger("Message not found."))
else:
if event.text != '/auth':
logger('Unknown command.')
await event.reply("Use /help for available command.")
raise events.StopPropagation

Expand Down

0 comments on commit 6be400b

Please sign in to comment.