def button(msg): chatId, query_data = glance(msg, flavor="callback_query")[1:3] user = User.get(chatId=chatId) query_split = query_data.split("#") query = query_split[0] message_id = int(query_split[1]) if query.startswith("delclip"): clipid = int(query.split("_")[1]) clip = Clip.get(user=user, id=clipid) cliptext = " ".join(clip.text.split()[:10]) cliptext = cliptext if len( clip.text.split()) < 11 else cliptext + "..." bot.editMessageText( (chatId, message_id), "⚠️ Are you <b>totally sure</b> you want to delete this clip?\n\n" "<b>Title:</b> {}\n" "<b>Text:</b> {}".format(clip.title, cliptext), parse_mode="HTML", reply_markup=keyboards.delete_confirm(clipid, message_id)) elif query.startswith("deleteyes"): clipid = int(query.split("_")[1]) clip = Clip.get(user=user, id=clipid) clip.delete() bot.editMessageText((chatId, message_id), "🗑 Clip successfully deleted!", reply_markup=None) elif query == "deleteno": bot.editMessageText((chatId, message_id), "👍 Clip restored!", parse_mode="HTML", reply_markup=None)
def query(msg): queryId, chatId, queryString = glance(msg, flavor='inline_query') user = User.get(chatId=chatId) results = inline.inlineResults(user, queryString) bot.answerInlineQuery(queryId, results, cache_time=10, is_personal=True, switch_pm_text="Create a new Clip", switch_pm_parameter="newclip_inline")
def button_press(msg): query_id, chatId, query_data = glance(msg, flavor="callback_query") query_split = query_data.split("#") message_id = int(query_split[1]) button = query_split[0] if button == "error": bot.answerCallbackQuery( query_id, "Non sono riuscito a creare il link per Scontino.") elif button == "prenotato": linkid = query_split[2] prevText = msg['message']['text'] bot.answerCallbackQuery(query_id, "Offerta prenotata!") bot.editMessageText((forwardChannel, message_id), prevText.replace( "Nuovo messaggio!\n", "<b>[Offerta prenotata da {}]</b>\n".format( msg['from']['first_name'])), parse_mode="HTML") if linkid != -1: bot.editMessageReplyMarkup( (forwardChannel, message_id), keyboards.open_scontino(linkid, message_id)) else: bot.editMessageReplyMarkup((forwardChannel, message_id), keyboards.error(message_id)) elif button == "richiesta": try: prevText = msg['message']['text'] bot.answerCallbackQuery(query_id, "Richiesta prenotata!") sent = bot.sendMessage(chatId, prevText.replace( "Nuovo messaggio!\n", "<b>[Richiesta prenotata]</b>\n"), parse_mode="HTML") bot.sendMessage( chatId, "Рё╣№ИЈ <b>Risposte Rapide</b>\n" "<code>Ciao, purtroppo non ho coupon per questo prodotto</code>", parse_mode="HTML", disable_notification=True) bot.deleteMessage((forwardChannel, message_id)) dbQuery = select( m for m in Message if m.sentIds[str(forwardChannel)] == message_id)[:] if len(dbQuery) > 0: origMsg = dbQuery[0] origMsg.sentIds = {str(chatId): int(sent['message_id'])} except Exception as e: print(e)
def query(msg): queryId, chatId, queryString = glance(msg, flavor='inline_query') if isAmazonUrl(queryString): amzSha256 = sha256(("amz" + queryString).encode()).hexdigest() bitSha256 = sha256(("bit" + queryString).encode()).hexdigest() strippedUrl = stripUrl(queryString) shortedUrl = shortUrl(strippedUrl) results = [ InlineQueryResultArticle( id=bitSha256, title="Shorted URL", input_message_content=InputTextMessageContent( message_text=shortedUrl, disable_web_page_preview=True), description="Short link with bit.ly", thumb_url="https://i.imgur.com/UXDqKay.jpg"), InlineQueryResultArticle( id=amzSha256, title="Stripped URL", input_message_content=InputTextMessageContent( message_text=strippedUrl, disable_web_page_preview=True), description="Original amazon link without extra tags", thumb_url="https://i.imgur.com/7eAooJr.jpg") ] bot.answerInlineQuery(queryId, results, cache_time=3600, is_personal=False) # Invalid link elif queryString.strip() != "": linkSha256 = sha256(queryString.encode()).hexdigest() results = [ InlineQueryResultArticle( id=linkSha256, title="Invalid link", input_message_content=InputTextMessageContent( message_text=queryString, disable_web_page_preview=True), description= "Invalid link. Type an Amazon link to short it (or tap to send anyway)", thumb_url="https://i.imgur.com/7eAooJr.jpg") ] bot.answerInlineQuery(queryId, results, cache_time=3600, is_personal=False)
def query(msg): queryId, chatId, queryString = glance(msg, flavor="inline_query") desc = f" for {queryString}" if queryString else " to pay respect." results = [ InlineQueryResultArticle(id=f"pressf_{queryString}", title="Press F", input_message_content=InputTextMessageContent( message_text=f"<b>Press F</b>{desc}", parse_mode="HTML"), reply_markup=keyboards.pressF(), description=desc, thumb_url="https://i.imgur.com/Nc7b9Yx.png") ] bot.answerInlineQuery(queryId, results, cache_time=10800, is_personal=False)
def query(msg): queryId, chatId, queryString = glance(msg, flavor='inline_query') text = helpers.nameToId(queryString) regions = select(r for r in Regione)[:] results = [ InlineQueryResultArticle( id="reg_{}".format(region.name), title=region.name, input_message_content=InputTextMessageContent( message_text="{} <b>{}</b> oggi è: {}.\n" "<i>Ultimo aggiornamento: {}</i>".format( helpers.getEmoji(region.color), region.name, region.color, region.updatedTime), parse_mode="HTML"), reply_markup=keyboards.infoColorePvt(region.color), description="{} {}".format(helpers.getEmoji(region.color), region.color), thumb_url= "https://pesaventofilippo.com/assets/images/projects/checolorebot.png" ) for region in regions if text in helpers.nameToId(region.name) ] bot.answerInlineQuery(queryId, results, cache_time=3600, is_personal=False)
def button_press(msg): chatId, query_data = glance(msg, flavor="callback_query")[1:3] query_split = query_data.split("#") message_id = int(query_split[1]) button = query_split[0] data = Data.get(chatId=chatId) if button == "logout_yes": helpers.clearUserData(chatId) bot.editMessageText((chatId, message_id), "😯 Fatto, sei stato disconnesso!\n" "Premi /login per entrare di nuovo.\n\n" "Premi /help se serve aiuto.", reply_markup=None) elif button == "logout_no": bot.editMessageText((chatId, message_id), "<i>Logout annullato.</i>", parse_mode="HTML", reply_markup=None) elif button == "overview_ext": costo = data.ext_costoChiamate + data.ext_costoGiga + data.ext_costoSms + data.ext_costoMms bot.editMessageText((chatId, message_id), f"ℹ️ <b>Riepilogo piano estero</b>\n\n" f"📞 Chiamate: <b>{data.ext_totChiamate}</b>\n" f"🌐 Dati consumati: <b>{data.ext_totGiga['count']}{data.ext_totGiga['unit']}</b> su <b>" f"{data.ext_pianoGiga['count']}{data.ext_pianoGiga['unit']}</b>\n" f"✉️ SMS Inviati: <b>{data.ext_totSms}</b>\n" f"📧 MMS Inviati: <b>{data.ext_totMms}</b>\n\n" f"💸 Costi extra: {costo:.2f}€", parse_mode="HTML", reply_markup=keyboards.overviewIta(message_id)) elif button == "overview_ita": costo = data.costoChiamate + data.costoGiga + data.costoSms + data.costoMms bot.editMessageText((chatId, message_id), f"ℹ️ <b>Riepilogo piano</b>\n\n" f"📞 Chiamate: <b>{data.totChiamate}</b>\n" f"🌐 Dati consumati: <b>{data.totGiga['count']}{data.totGiga['unit']}</b> su <b>" f"{data.pianoGiga['count']}{data.pianoGiga['unit']}</b>\n" f"✉️ SMS Inviati: <b>{data.totSms}</b>\n" f"📧 MMS Inviati: <b>{data.totMms}</b>\n\n" f"💸 Costi extra: {costo:.2f}€", parse_mode="HTML", reply_markup=keyboards.overviewExt(message_id))
def button(msg): chatId, query_data = glance(msg, flavor="callback_query")[1:3] user = User.get(chatId=chatId) query_split = query_data.split("#") text = query_split[0] message_id = int(query_split[1]) if text.startswith("selcat"): text_split = text.split('_') book = Book.get(id=int(text_split[2])) book.category = Category.get(id=int(text_split[1])) user.status = "normal" bot.editMessageText( (chatId, message_id), f"🗂 Successfully moved book <b>{book.name}</b> to category " f"<b>{book.category.name}</b>!", parse_mode="HTML", reply_markup=None) elif text.startswith("movebook"): book_id = int(text.split('_')[1]) user.status = f"selecting_category#{book_id}" bot.editMessageText( (chatId, message_id), "Please select a category for the book, or type a name to create a new one:", reply_markup=keyboards.category(book_id, message_id)) elif text.startswith("delbook"): book_id = int(text.split('_')[1]) book = Book.get(id=book_id) name = book.name book.delete() bot.editMessageText((chatId, message_id), f"🗑 <b>{name}</b> successfully deleted.", parse_mode="HTML", reply_markup=None) elif text.startswith("searchcat"): cat_id = int(text.split('_')[1]) cat = Category.get(id=cat_id) res = "" for b in sorted(cat.books, key=lambda x: x.name): res += f"\n📖 <a href=\"https://t.me/freebooksbbot?start=getbook_{b.id}\">{b.name}</a>" bot.editMessageText( (chatId, message_id), f"🔍 <b>Category: {cat.name}</b>\n" f"Click on any book title, then click on \"Start\" at the bottom to " f"download the ebook:\n" + res, parse_mode="HTML", reply_markup=keyboards.back_search(message_id), disable_web_page_preview=True) elif text == "backsearch": bot.editMessageText((chatId, message_id), "🔍 <b>Book Search</b>\n" "Pick a category from the list below:", parse_mode="HTML", reply_markup=keyboards.search_cat(message_id)) elif text == "moveall": bot.editMessageReplyMarkup((chatId, message_id), keyboards.manageBooks("move", message_id, show_all=True)) elif text == "delall": bot.editMessageReplyMarkup((chatId, message_id), keyboards.manageBooks("del", message_id, show_all=True))