add button
This commit is contained in:
parent
ef18f67115
commit
219e28b420
25
bot.py
25
bot.py
@ -1,9 +1,10 @@
|
|||||||
from telegram import Update
|
from telegram import Update
|
||||||
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler, MessageHandler, filters, InlineQueryHandler
|
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler, MessageHandler, filters, InlineQueryHandler, \
|
||||||
|
CallbackContext, CallbackQueryHandler
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from tgbot.config import TOKEN
|
from tgbot.config import TOKEN
|
||||||
from tgbot.shit.handlers import handle_xitter, handle_red_ebalo, handle_hentai
|
from tgbot.shit.handlers import handle_xitter, handle_red_ebalo, handle_hentai, handle_cute_button
|
||||||
from tgbot.shit.render import render_text_on_image, image_to_string
|
from tgbot.shit.render import render_text_on_image, image_to_string
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
@ -12,6 +13,7 @@ logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
await context.bot.send_message(chat_id=update.effective_chat.id,
|
await context.bot.send_message(chat_id=update.effective_chat.id,
|
||||||
text='WE ARE A PARTY OF UTTER MADNESS, '
|
text='WE ARE A PARTY OF UTTER MADNESS, '
|
||||||
@ -37,6 +39,20 @@ async def image2string(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|||||||
await update.message.reply_text(s)
|
await update.message.reply_text(s)
|
||||||
|
|
||||||
|
|
||||||
|
async def callback_query_handler(update: Update, context: CallbackContext):
|
||||||
|
query = update.callback_query
|
||||||
|
|
||||||
|
if query.data == "show_cute_popup":
|
||||||
|
await context.bot.answer_callback_query(
|
||||||
|
callback_query_id=query.id,
|
||||||
|
text="Hey! This button is for you! Thank you for clicking it, you are awesome!",
|
||||||
|
show_alert=True
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
|
await query.answer()
|
||||||
|
|
||||||
|
|
||||||
async def handle_inline(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
async def handle_inline(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
query = update.inline_query.query
|
query = update.inline_query.query
|
||||||
if not query:
|
if not query:
|
||||||
@ -50,6 +66,10 @@ async def handle_inline(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|||||||
await handle_hentai(update, context)
|
await handle_hentai(update, context)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if query.startswith("button!"):
|
||||||
|
await handle_cute_button(update, context)
|
||||||
|
return
|
||||||
|
|
||||||
await handle_red_ebalo(update, context)
|
await handle_red_ebalo(update, context)
|
||||||
|
|
||||||
|
|
||||||
@ -64,6 +84,7 @@ def main():
|
|||||||
application.add_handler(MessageHandler(filters.PHOTO, image2string))
|
application.add_handler(MessageHandler(filters.PHOTO, image2string))
|
||||||
application.add_handler(picture_handler)
|
application.add_handler(picture_handler)
|
||||||
application.add_handler(InlineQueryHandler(handle_inline))
|
application.add_handler(InlineQueryHandler(handle_inline))
|
||||||
|
application.add_handler(CallbackQueryHandler(callback_query_handler))
|
||||||
|
|
||||||
application.run_polling()
|
application.run_polling()
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from pybooru import Danbooru
|
from pybooru import Danbooru
|
||||||
from telegram import Update
|
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup, InlineQueryResultArticle, \
|
||||||
|
InputTextMessageContent
|
||||||
from telegram.ext import ContextTypes
|
from telegram.ext import ContextTypes
|
||||||
|
|
||||||
from tgbot.config import STICKER_SHITHOLE, BOORU_API_URL, INLINE_QUERY_CACHE_SECONDS, DANBOORU_API_KEY
|
from tgbot.config import STICKER_SHITHOLE, BOORU_API_URL, INLINE_QUERY_CACHE_SECONDS, DANBOORU_API_KEY
|
||||||
@ -53,6 +56,21 @@ async def handle_red_ebalo(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|||||||
await context.bot.answer_inline_query(update.inline_query.id, results)
|
await context.bot.answer_inline_query(update.inline_query.id, results)
|
||||||
|
|
||||||
|
|
||||||
|
async def handle_cute_button(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
|
|
||||||
|
button = InlineKeyboardButton("Click me!", callback_data="show_cute_popup")
|
||||||
|
keyboard = InlineKeyboardMarkup([[button]])
|
||||||
|
|
||||||
|
result = InlineQueryResultArticle(
|
||||||
|
id=str(uuid.uuid4()),
|
||||||
|
title="Cute button!",
|
||||||
|
input_message_content=InputTextMessageContent("Here is a post with a cute button:"),
|
||||||
|
reply_markup=keyboard
|
||||||
|
)
|
||||||
|
|
||||||
|
await context.bot.answer_inline_query(update.inline_query.id, [result])
|
||||||
|
|
||||||
|
|
||||||
async def handle_hentai(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
async def handle_hentai(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
query = update.inline_query.query.replace("hentai", "").replace("—", "--")
|
query = update.inline_query.query.replace("hentai", "").replace("—", "--")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user