103 lines
3.2 KiB
Python
103 lines
3.2 KiB
Python
|
import requests
|
||
|
from telegram import Update, InlineQueryResultPhoto
|
||
|
from telegram.ext import ContextTypes
|
||
|
|
||
|
from tgbot.config import STICKER_SHITHOLE, BOORU_API_URL
|
||
|
from tgbot.shit.hentai import QueryParams
|
||
|
from tgbot.shit.render import render_text_on_image
|
||
|
|
||
|
|
||
|
async def handle_xitter(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||
|
query = update.inline_query.query
|
||
|
|
||
|
xcom = "https://x.com"
|
||
|
|
||
|
results = [
|
||
|
{
|
||
|
"type": "article",
|
||
|
"id": "1",
|
||
|
"title": "fix xitter links",
|
||
|
"description": query.replace(xcom, "https://fxtwitter.com"),
|
||
|
"input_message_content": {
|
||
|
"message_text": query.replace(xcom, "https://fxtwitter.com")
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
|
||
|
await context.bot.answer_inline_query(update.inline_query.id, results)
|
||
|
|
||
|
|
||
|
async def handle_red_ebalo(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||
|
query = update.inline_query.query
|
||
|
|
||
|
file = render_text_on_image("tgbot/assets/red_ebalo.png", query)
|
||
|
|
||
|
file_id = (await context.bot.send_sticker(chat_id=STICKER_SHITHOLE, sticker=file)).sticker.file_id
|
||
|
results = [
|
||
|
{
|
||
|
"type": "sticker",
|
||
|
"id": "1",
|
||
|
"sticker_file_id": file_id
|
||
|
}
|
||
|
]
|
||
|
await context.bot.answer_inline_query(update.inline_query.id, results)
|
||
|
|
||
|
|
||
|
async def handle_hentai(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||
|
|
||
|
error_response = [
|
||
|
{
|
||
|
"type": "article",
|
||
|
"id": "1",
|
||
|
"title": "ERROR OCCURRED! That means, at least one of us is a retard.",
|
||
|
"description": "None",
|
||
|
"input_message_content": {
|
||
|
"message_text": "None"
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
|
||
|
query = update.inline_query.query
|
||
|
|
||
|
try:
|
||
|
params = QueryParams.from_query_str(query).__dict__
|
||
|
except ValueError as e:
|
||
|
print(e)
|
||
|
error_response[0]["description"] = "error parsing query"
|
||
|
error_response[0]["input_message_content"]["message_text"] = "error parsing query"
|
||
|
return await context.bot.answer_inline_query(update.inline_query.id, error_response)
|
||
|
|
||
|
response = requests.post(BOORU_API_URL, json=params)
|
||
|
|
||
|
if response.status_code == 200:
|
||
|
|
||
|
posts = response.json()
|
||
|
|
||
|
results = []
|
||
|
|
||
|
for idx, post in enumerate(posts):
|
||
|
booru_post_url = post["booru"]["domain"] + \
|
||
|
post["booru"]["site"]["api"]["postView"] + post["id"]
|
||
|
|
||
|
results.append(
|
||
|
InlineQueryResultPhoto(
|
||
|
id="%d" % idx,
|
||
|
photo_url=post["fileUrl"],
|
||
|
thumbnail_url=post["previewUrl"],
|
||
|
title="IMAGE #%d" % idx,
|
||
|
description="Image from booru",
|
||
|
caption="source -> " + booru_post_url
|
||
|
)
|
||
|
)
|
||
|
|
||
|
await context.bot.answer_inline_query(update.inline_query.id, results)
|
||
|
|
||
|
else:
|
||
|
|
||
|
print(response.text)
|
||
|
|
||
|
error_response[0]["description"] = "booru error"
|
||
|
error_response[0]["input_message_content"]["message_text"] = response.text
|
||
|
|
||
|
return await context.bot.answer_inline_query(update.inline_query.id, error_response)
|