Skip to content

Commit

Permalink
V2.2: Fix more duplications
Browse files Browse the repository at this point in the history
Signed-off-by: starry69 <starry369126@outlook.com>
  • Loading branch information
starry-shivam committed May 25, 2020
1 parent 84b4375 commit 7e0fa8f
Showing 1 changed file with 19 additions and 28 deletions.
47 changes: 19 additions & 28 deletions starrybot.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ def error(update, context):
BASE_URL = 'https://pixabay.com/api/'
AUTH_URL = 'https://pixabay.com/users'

# Don't async
def keyboard(imgurl, author, authid):
""" sends inline keyboard buttons
with reply photo """
keyb = [[
InlineKeyboardButton(text="PageLink 🌐", url=imgurl),
InlineKeyboardButton(text="Author 👸",
url=f'{AUTH_URL}/{author}-{authid}')]]
return keyb


@run_async
@send_action(ChatAction.UPLOAD_PHOTO)
def wall(update, context):
Expand Down Expand Up @@ -119,17 +130,12 @@ def wall(update, context):
imgurl = hits.get('pageURL')
document = hits.get('imageURL')

keyboard = [[
InlineKeyboardButton(text="PageLink 🌐", url=imgurl),
InlineKeyboardButton(text="Author 👸",
url=f'{AUTH_URL}/{author}-{authid}')
]]

try:
context.bot.send_photo(chat.id, photo=preview,
caption=(s.WALL_STR.format(
likes, author, views, downloads, tags)),
reply_markup=InlineKeyboardMarkup(keyboard),
reply_markup=InlineKeyboardMarkup(
keyboard(imgurl, author, authid)),
timeout=60)

context.bot.send_document(chat.id,
Expand Down Expand Up @@ -184,17 +190,12 @@ def wallcolor(update, context):
imgurl = hits.get('pageURL')
document = hits.get('imageURL')

keyboard = [[
InlineKeyboardButton(text="PageLink 🌐", url=imgurl),
InlineKeyboardButton(text="Author 👸",
url=f'{AUTH_URL}/{author}-{authid}')
]]

try:
context.bot.send_photo(chat.id, photo=preview,
caption=(s.WALL_STR.format(
likes, author, views, downloads, tags)),
reply_markup=InlineKeyboardMarkup(keyboard),
reply_markup=InlineKeyboardMarkup(
keyboard(imgurl, author, authid)),
timeout=60)

context.bot.send_document(chat.id,
Expand Down Expand Up @@ -227,17 +228,12 @@ def editorschoice(update, context):
imgurl = hits.get('pageURL')
document = hits.get('imageURL')

keyboard = [[
InlineKeyboardButton(text="PageLink 🌐", url=imgurl),
InlineKeyboardButton(text="Author 👸",
url=f'{AUTH_URL}/users/{author}-{authid}')
]]

try:
context.bot.send_photo(chat.id, photo=preview,
caption=(s.WALL_STR.format(
likes, author, views, downloads, tags)),
reply_markup=InlineKeyboardMarkup(keyboard),
reply_markup=InlineKeyboardMarkup(
keyboard(imgurl, author, authid)),
timeout=60)

context.bot.send_document(chat.id,
Expand Down Expand Up @@ -271,17 +267,12 @@ def randomwalls(update, context):
imgurl = hits.get('pageURL')
document = hits.get('imageURL')

keyboard = [[
InlineKeyboardButton(text="PageLink 🌐", url=imgurl),
InlineKeyboardButton(text="Author 👸",
url=f'{AUTH_URL}/{author}-{authid}')
]]

try:
context.bot.send_photo(chat.id, photo=preview,
caption=(s.WALL_STR.format(
likes, author, views, downloads, tags)),
reply_markup=InlineKeyboardMarkup(keyboard),
reply_markup=InlineKeyboardMarkup(
keyboard(imgurl, author, authid)),
timeout=60)

context.bot.send_document(chat.id,
Expand Down

0 comments on commit 7e0fa8f

Please sign in to comment.