This repository has been archived by the owner on Sep 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 917
Use edit message in help and settings #47
Open
AyraHikari
wants to merge
4
commits into
PaulSonOfLars:master
Choose a base branch
from
AyraHikari:new
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dc46f1b
Use edit message in help and settings
AyraHikari 9e0c128
Error Flood control handling in help and settings button
AyraHikari f0389c2
Change Exception to BadRequest
AyraHikari c1a5211
use query edit message instead of bot edit message
AyraHikari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,33 +191,36 @@ def help_button(bot: Bot, update: Update): | |
module = mod_match.group(1) | ||
text = "Here is the help for the *{}* module:\n".format(HELPABLE[module].__mod_name__) \ | ||
+ HELPABLE[module].__help__ | ||
query.message.reply_text(text=text, | ||
parse_mode=ParseMode.MARKDOWN, | ||
reply_markup=InlineKeyboardMarkup( | ||
[[InlineKeyboardButton(text="Back", callback_data="help_back")]])) | ||
query.message.edit_text(text=text, | ||
parse_mode=ParseMode.MARKDOWN, | ||
reply_markup=InlineKeyboardMarkup( | ||
[[InlineKeyboardButton(text="Back", callback_data="help_back")]])) | ||
|
||
elif prev_match: | ||
curr_page = int(prev_match.group(1)) | ||
query.message.reply_text(HELP_STRINGS, | ||
parse_mode=ParseMode.MARKDOWN, | ||
reply_markup=InlineKeyboardMarkup( | ||
paginate_modules(curr_page - 1, HELPABLE, "help"))) | ||
query.message.edit_text(text=HELP_STRINGS, | ||
parse_mode=ParseMode.MARKDOWN, | ||
reply_markup=InlineKeyboardMarkup( | ||
paginate_modules(curr_page - 1, HELPABLE, "help"))) | ||
|
||
elif next_match: | ||
next_page = int(next_match.group(1)) | ||
query.message.reply_text(HELP_STRINGS, | ||
parse_mode=ParseMode.MARKDOWN, | ||
reply_markup=InlineKeyboardMarkup( | ||
paginate_modules(next_page + 1, HELPABLE, "help"))) | ||
bot.edit_message_text(chat_id=query.message.chat_id, | ||
message_id=query.message.message_id, | ||
text=HELP_STRINGS, | ||
parse_mode=ParseMode.MARKDOWN, | ||
reply_markup=InlineKeyboardMarkup( | ||
paginate_modules(next_page + 1, HELPABLE, "help"))) | ||
|
||
elif back_match: | ||
query.message.reply_text(text=HELP_STRINGS, | ||
parse_mode=ParseMode.MARKDOWN, | ||
reply_markup=InlineKeyboardMarkup(paginate_modules(0, HELPABLE, "help"))) | ||
bot.edit_message_text(chat_id=query.message.chat_id, | ||
message_id=query.message.message_id, | ||
text=HELP_STRINGS, | ||
parse_mode=ParseMode.MARKDOWN, | ||
reply_markup=InlineKeyboardMarkup(paginate_modules(0, HELPABLE, "help"))) | ||
|
||
# ensure no spinny white circle | ||
bot.answer_callback_query(query.id) | ||
query.message.delete() | ||
except BadRequest as excp: | ||
if excp.message == "Message is not modified": | ||
pass | ||
|
@@ -296,44 +299,51 @@ def settings_button(bot: Bot, update: Update): | |
text = "*{}* has the following settings for the *{}* module:\n\n".format(escape_markdown(chat.title), | ||
CHAT_SETTINGS[module].__mod_name__) + \ | ||
CHAT_SETTINGS[module].__chat_settings__(chat_id, user.id) | ||
query.message.reply_text(text=text, | ||
parse_mode=ParseMode.MARKDOWN, | ||
reply_markup=InlineKeyboardMarkup( | ||
[[InlineKeyboardButton(text="Back", | ||
callback_data="stngs_back({})".format(chat_id))]])) | ||
query.message.edit_text(chat_id=query.message.chat_id, | ||
message_id=query.message.message_id, | ||
text=text, | ||
parse_mode=ParseMode.MARKDOWN, | ||
reply_markup=InlineKeyboardMarkup( | ||
[[InlineKeyboardButton(text="Back", | ||
callback_data="stngs_back({})".format(chat_id))]])) | ||
|
||
elif prev_match: | ||
chat_id = prev_match.group(1) | ||
curr_page = int(prev_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 " | ||
"you're interested in.".format(chat.title), | ||
reply_markup=InlineKeyboardMarkup( | ||
paginate_modules(curr_page - 1, CHAT_SETTINGS, "stngs", | ||
chat=chat_id))) | ||
query.message.edit_text(chat_id=query.message.chat_id, | ||
message_id=query.message.message_id, | ||
text="Hi there! There are quite a few settings for {} - go ahead and pick what " | ||
"you're interested in.".format(chat.title), | ||
reply_markup=InlineKeyboardMarkup( | ||
paginate_modules(curr_page - 1, CHAT_SETTINGS, "stngs", | ||
chat=chat_id))) | ||
|
||
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 " | ||
"you're interested in.".format(chat.title), | ||
reply_markup=InlineKeyboardMarkup( | ||
paginate_modules(next_page + 1, CHAT_SETTINGS, "stngs", | ||
chat=chat_id))) | ||
query.message.edit_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 commentThe 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 |
||
text="Hi there! There are quite a few settings for {} - go ahead and pick what " | ||
"you're interested in.".format(chat.title), | ||
reply_markup=InlineKeyboardMarkup( | ||
paginate_modules(next_page + 1, CHAT_SETTINGS, "stngs", | ||
chat=chat_id))) | ||
|
||
elif back_match: | ||
chat_id = back_match.group(1) | ||
chat = bot.get_chat(chat_id) | ||
query.message.reply_text(text="Hi there! There are quite a few settings for {} - go ahead and pick what " | ||
"you're interested in.".format(escape_markdown(chat.title)), | ||
parse_mode=ParseMode.MARKDOWN, | ||
reply_markup=InlineKeyboardMarkup(paginate_modules(0, CHAT_SETTINGS, "stngs", | ||
chat=chat_id))) | ||
query.message.edit_text(chat_id=query.message.chat_id, | ||
message_id=query.message.message_id, | ||
text="Hi there! There are quite a few settings for {} - go ahead and pick what " | ||
"you're interested in.".format(escape_markdown(chat.title)), | ||
parse_mode=ParseMode.MARKDOWN, | ||
reply_markup=InlineKeyboardMarkup(paginate_modules(0, CHAT_SETTINGS, "stngs", | ||
chat=chat_id))) | ||
|
||
# ensure no spinny white circle | ||
bot.answer_callback_query(query.id) | ||
query.message.delete() | ||
except BadRequest as excp: | ||
if excp.message == "Message is not modified": | ||
pass | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.