Skip to content

Commit

Permalink
Added a REFINE SEARCH button
Browse files Browse the repository at this point in the history
  • Loading branch information
francocruces committed Oct 28, 2017
1 parent fdfc37d commit 7e8b393
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
7 changes: 5 additions & 2 deletions AZScrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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,
Expand All @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
TITLE_ARTIST_SEPARATOR = " by "
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit 7e8b393

Please sign in to comment.