diff --git a/AZScrapper.py b/AZScrapper.py index 99d158f..b34384e 100644 --- a/AZScrapper.py +++ b/AZScrapper.py @@ -15,7 +15,7 @@ InlineKeyboardMarkup from Config import MAX_RESULTS, NO_RESULTS_ALERT, CANCEL_DATA_STRING, NO_RESULTS_TEXT, CANCEL_BUTTON_TEXT, \ - TITLE_ARTIST_SEPARATOR + TITLE_ARTIST_SEPARATOR, REFINE_BUTTON_TEXT __author__ = "Franco Cruces Ayala" @@ -29,6 +29,10 @@ def get_lyrics_as_inline_keyboard(query): """ buttons = get_inline_keyboard_buttons(query) if len(buttons) > 0: + buttons.append([InlineKeyboardButton( + text=REFINE_BUTTON_TEXT, + switch_inline_query_current_chat=query + )]) buttons.append([InlineKeyboardButton( text=CANCEL_BUTTON_TEXT, callback_data=CANCEL_DATA_STRING, @@ -42,7 +46,6 @@ def get_lyrics_as_inline_keyboard(query): parse_mode="Markdown"), reply_markup=InlineKeyboardMarkup(inline_keyboard=buttons) )] - # TODO: Add a cancel button. else: return [InlineQueryResultArticle( id=0, title=NO_RESULTS_TEXT, input_message_content=InputTextMessageContent( diff --git a/Config.py b/Config.py index 31f00e8..dd45cce 100644 --- a/Config.py +++ b/Config.py @@ -12,5 +12,6 @@ CANCEL_BUTTON_TEXT = "CANCEL SEARCH" CANCEL_DATA_STRING = "~~CANCEL~~" SEARCH_CANCELLED_ALERT = "_The search was cancelled_" +REFINE_BUTTON_TEXT = "REFINE SEARCH" -TITLE_ARTIST_SEPARATOR = " by " \ No newline at end of file +TITLE_ARTIST_SEPARATOR = " by " diff --git a/main.py b/main.py index 2370143..4ab8693 100644 --- a/main.py +++ b/main.py @@ -8,9 +8,9 @@ from telepot.aio.delegate import per_inline_from_id, create_open, pave_event_space, intercept_callback_query_origin from telepot.aio.helper import InlineUserHandler, AnswererMixin, InterceptCallbackQueryMixin from telepot.aio.loop import MessageLoop -from Config import MAX_MESSAGE_SIZE, MESSAGE_TOO_LONG_ALERT, CANCEL_DATA_STRING, SEARCH_CANCELLED_ALERT from AZScrapper import get_lyrics_as_inline_keyboard, get_lyric_body_from_id +from Config import MAX_MESSAGE_SIZE, MESSAGE_TOO_LONG_ALERT, CANCEL_DATA_STRING, SEARCH_CANCELLED_ALERT from __TOKEN__ import TOKEN # Replace with your own token. Provided by BotFather __author__ = "Franco Cruces Ayala" @@ -53,7 +53,9 @@ async def on_callback_query(self, msg): print(msg) in_id = msg['inline_message_id'] data = msg['data'] - if data != CANCEL_DATA_STRING: + if data == CANCEL_DATA_STRING: + await self.bot.editMessageText(str(in_id), SEARCH_CANCELLED_ALERT, parse_mode="Markdown") + else: lyrics = get_lyric_body_from_id(data) if len(lyrics) <= MAX_MESSAGE_SIZE: await self.bot.editMessageText(str(in_id), lyrics, parse_mode="Markdown") @@ -62,8 +64,6 @@ async def on_callback_query(self, msg): while lyrics != "": await self.bot.sendMessage(msg['from']['id'], lyrics[:MAX_MESSAGE_SIZE]) lyrics = lyrics[MAX_MESSAGE_SIZE:] - else: - await self.bot.editMessageText(str(in_id), SEARCH_CANCELLED_ALERT, parse_mode="Markdown") # ASYNC MAIN