-
Notifications
You must be signed in to change notification settings - Fork 917
Use edit message in help and settings #47
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Ayra Hikari <[email protected]>
Signed-off-by: Ayra Hikari <[email protected]>
I've added error flood control handling in help and settings button, if got error Flood control exceeded, it will edit message to |
... So your way of handling flood control is to edit to flood control exceeded? How does that make sense? You've hit flooding, you can't change it anymore? Or am I misunderstanding. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you catching exception? This is bad practice. And please make sure you adhere to PEP8.
|
||
# ensure no spinny white circle | ||
bot.answer_callback_query(query.id) | ||
query.message.delete() | ||
except BadRequest as excp: | ||
except Exception as excp: | ||
if excp.message == "Message is not modified": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never, ever, EVER catch exception. You can have no idea what you're catching.
|
||
elif next_match: | ||
chat_id = next_match.group(1) | ||
next_page = int(next_match.group(2)) | ||
chat = bot.get_chat(chat_id) | ||
query.message.reply_text("Hi there! There are quite a few settings for {} - go ahead and pick what " | ||
bot.edit_message_text(chat_id=query.message.chat_id, | ||
message_id=query.message.message_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are you doing with your indent? This isn't indented to pep8
Signed-off-by: Ayra Hikari <[email protected]>
Oh yeah sorry about that, fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the overall aim of this PR? And how does it react when you press an old button? Bots cannot edit older messages (I think it's 2 days), this code currently just dies quietly and doesn't update the message.
You're just changing from send_message to edit_message (which I think has a lower flood limit). What are the advantages? You save a single delete api call, but that delete ensures that the help still works with older messages.
tg_bot/__main__.py
Outdated
@@ -342,6 +359,9 @@ def settings_button(bot: Bot, update: Update): | |||
elif excp.message == "Message can't be deleted": | |||
pass | |||
else: | |||
bot.edit_message_text(chat_id=query.message.chat_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in conclusion, this line is useless and never succeeds then?
tg_bot/__main__.py
Outdated
reply_markup=InlineKeyboardMarkup( | ||
[[InlineKeyboardButton(text="Back", | ||
callback_data="stngs_back({})".format(chat_id))]])) | ||
bot.edit_message_text(chat_id=query.message.chat_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use query.message.edit_text
?
Signed-off-by: Ayra Hikari <[email protected]>
It still work and updated when i press button on old message (2 month ago, may 17) based on my bot. |
Why would it be better performance? I'd like to have some sort of proof that edit has better or equal flood limit, and what your performance claim is based on, other than removing one delete api call. |
I think it equal enough, because i clicked button in my bot and marie 19 times, and it not responding because flood limit. so it stuck at 19 times. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
Signed-off-by: Ayra Hikari [email protected]