From 140cc19a14ee90b3e7d60c2e999e565382968741 Mon Sep 17 00:00:00 2001 From: Wudi Date: Thu, 19 Mar 2026 15:00:24 +0530 Subject: [PATCH 1/5] google.py fix --- userbot/core/inlinebot.py | 71 +++++++++++++++++++++++++++++++++++++++ userbot/plugins/google.py | 22 +++++++----- 2 files changed, 85 insertions(+), 8 deletions(-) diff --git a/userbot/core/inlinebot.py b/userbot/core/inlinebot.py index 4033abcf90..923906d1ae 100644 --- a/userbot/core/inlinebot.py +++ b/userbot/core/inlinebot.py @@ -1,11 +1,17 @@ +import io import json import math import os import random +import requests import re import time +import urllib.parse +import textwrap from pathlib import Path +from PIL import Image, ImageDraw, ImageFont + from telethon import Button, types from telethon.events import CallbackQuery, InlineQuery from youtubesearchpython import VideosSearch @@ -456,6 +462,9 @@ async def inline_handler(event): elif str_y[0].lower() == "ytdl" and len(str_y) == 2: result = await youtube_data_article(event, str_y) await event.answer([result] if result else None) + elif str_y[0].lower() == "google" and len(str_y) >= 2: + result = await google_search_article(event, str_y[1].strip()) + await event.answer([result] if result else None) elif string == "age_verification_alert": result = await age_verification_article(event) await event.answer([result] if result else None) @@ -518,6 +527,68 @@ async def youtube_data_article(event, str_y): ) return result +async def google_search_article(event, input_str): + font_url = "https://github.com/TgCatUB/CatUserbot-Resources/raw/master/Resources/fonts/roboto_regular.ttf" + image_url = "https://raw.githubusercontent.com/ZAR0X/CatUserbot-Resources/refs/heads/master/Resources/Inline/google.webp" + print("This worked 1") + font_res = requests.get(font_url) + font_res.raise_for_status() + font_data = io.BytesIO(font_res.content) + + img_res = requests.get(image_url) + img_res.raise_for_status() + img = Image.open(io.BytesIO(img_res.content)).convert("RGBA") + + draw = ImageDraw.Draw(img) + + box_x1, box_y1, box_x2, box_y2 = 40, 240, 472, 370 + box_width = box_x2 - box_x1 + box_height = box_y2 - box_y1 + + font_size = 40 + if len(input_str) > 35: + font_size = 32 + if len(input_str) > 80: + font_size = 24 + + font = ImageFont.truetype(font_data, font_size) + + avg_char_width = font.getlength("a") if hasattr(font, "getlength") else font.getsize("a")[0] + chars_per_line = max(1, int(box_width / (avg_char_width * 1.05))) + + lines = textwrap.wrap(input_str, width=chars_per_line) + wrapped_text = "\n".join(lines) + + if hasattr(draw, "multiline_textbbox"): + left, top, right, bottom = draw.multiline_textbbox((0, 0), wrapped_text, font=font) + else: + w, h = draw.multiline_textsize(wrapped_text, font=font) + left, top, right, bottom = 0, 0, w, h + + text_w = right - left + text_h = bottom - top + + x = box_x1 + (box_width - text_w) / 2 + y = box_y1 + (box_height - text_h) / 2 + + draw.multiline_text((x, y), wrapped_text, font=font, fill="#3c4043", align="center") + print("This worked 2") + out_buffer = io.BytesIO() + out_buffer.name = "google_search.png" + img.save(out_buffer, "PNG") + out_buffer.seek(0) + + search_query_url = f"https://www.google.com/search?q={urllib.parse.quote_plus(input_str)}" + buttons = [Button.url("Google Search", search_query_url)] + + uploaded_file = await catub.tgbot.upload_file(out_buffer) + print("This worked 3") + return event.builder.photo( + file=uploaded_file, + text="", # Ensuring only the image and button are sent + buttons=buttons + ) + async def hide_troll_secret(event, query, match, match3): user_list = [] diff --git a/userbot/plugins/google.py b/userbot/plugins/google.py index e721e3793d..5a5763bc2f 100644 --- a/userbot/plugins/google.py +++ b/userbot/plugins/google.py @@ -1,14 +1,20 @@ -"""Reverse search image and Google search""" +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# CatUserBot #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# +# Copyright (C) 2020-2023 by TgCatUB@Github. + +# This file is part of: https://github.com/TgCatUB/catuserbot +# and is released under the "GNU v3.0 License Agreement". + +# Please see: https://github.com/TgCatUB/catuserbot/blob/master/LICENSE +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# -import contextlib import os import re from datetime import datetime - +import contextlib from search_engine_parser import BingSearch, GoogleSearch, YahooSearch from search_engine_parser.core.exceptions import NoResultsOrTrafficError -from userbot import BOTLOG, BOTLOG_CHATID, Convert, catub +from userbot import BOTLOG, BOTLOG_CHATID, Convert, catub, Config from ..core.managers import edit_delete, edit_or_reply from ..helpers.functions import deEmojify, unsavegif @@ -226,12 +232,12 @@ async def google_search(event): if not input_str: return await edit_delete(event, "__What should i search? Give search query plox.__") input_str = deEmojify(input_str).strip() - if len(input_str) > 195 or len(input_str) < 1: + if len(input_str) > 150 or len(input_str) < 1: return await edit_delete( event, - "__Plox your search query exceeds 200 characters or you search query is empty.__", + "__Plox your search query exceeds 150 characters or your search query is empty.__", ) - query = f"#12{input_str}" - results = await event.client.inline_query("@StickerizerBot", query) + query = f"google {input_str}" + results = await event.client.inline_query(Config.TG_BOT_USERNAME, query) await results[0].click(event.chat_id, reply_to=reply_to_id, hide_via=True) await event.delete() From 62d2347ee19dd68dae53aa6f90ecf527e5c61392 Mon Sep 17 00:00:00 2001 From: Wudi Date: Thu, 19 Mar 2026 23:09:09 +0530 Subject: [PATCH 2/5] google.py fix --- userbot/plugins/google.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/userbot/plugins/google.py b/userbot/plugins/google.py index 5a5763bc2f..13ff44b905 100644 --- a/userbot/plugins/google.py +++ b/userbot/plugins/google.py @@ -237,7 +237,10 @@ async def google_search(event): event, "__Plox your search query exceeds 150 characters or your search query is empty.__", ) + catevent = await edit_or_reply(event, "`Processing query...`") + query = f"google {input_str}" results = await event.client.inline_query(Config.TG_BOT_USERNAME, query) await results[0].click(event.chat_id, reply_to=reply_to_id, hide_via=True) + await catevent.delete() await event.delete() From fa21e4a8572177855dde4062c5d2ae32b9b357fb Mon Sep 17 00:00:00 2001 From: Wudi Date: Thu, 19 Mar 2026 23:20:26 +0530 Subject: [PATCH 3/5] google.py fix --- userbot/core/inlinebot.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/userbot/core/inlinebot.py b/userbot/core/inlinebot.py index 923906d1ae..865751fc18 100644 --- a/userbot/core/inlinebot.py +++ b/userbot/core/inlinebot.py @@ -530,7 +530,6 @@ async def youtube_data_article(event, str_y): async def google_search_article(event, input_str): font_url = "https://github.com/TgCatUB/CatUserbot-Resources/raw/master/Resources/fonts/roboto_regular.ttf" image_url = "https://raw.githubusercontent.com/ZAR0X/CatUserbot-Resources/refs/heads/master/Resources/Inline/google.webp" - print("This worked 1") font_res = requests.get(font_url) font_res.raise_for_status() font_data = io.BytesIO(font_res.content) @@ -572,7 +571,6 @@ async def google_search_article(event, input_str): y = box_y1 + (box_height - text_h) / 2 draw.multiline_text((x, y), wrapped_text, font=font, fill="#3c4043", align="center") - print("This worked 2") out_buffer = io.BytesIO() out_buffer.name = "google_search.png" img.save(out_buffer, "PNG") @@ -582,7 +580,6 @@ async def google_search_article(event, input_str): buttons = [Button.url("Google Search", search_query_url)] uploaded_file = await catub.tgbot.upload_file(out_buffer) - print("This worked 3") return event.builder.photo( file=uploaded_file, text="", # Ensuring only the image and button are sent From fd2e09249cc78350c7106803d9cf4a90b85fd5a1 Mon Sep 17 00:00:00 2001 From: Wudi Date: Thu, 19 Mar 2026 23:30:58 +0530 Subject: [PATCH 4/5] alive.py anime caption api update --- userbot/plugins/alive.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/userbot/plugins/alive.py b/userbot/plugins/alive.py index c71048d325..b30606e7de 100644 --- a/userbot/plugins/alive.py +++ b/userbot/plugins/alive.py @@ -40,10 +40,10 @@ async def amireallyalive(event): cat_caption = gvarstatus("ALIVE_TEMPLATE") or temp if "ANIME" in cat_caption: try: - response = requests.get("https://animechan.xyz/api/random", timeout=10) + response = requests.get("https://api.animechan.io/v1/quotes/random", timeout=10) if response.ok: data = response.json() - ANIME = f"**“{data['quote']}” - {data['character']} ({data['anime']})**" + ANIME = f"**“{data['data']['content']}” - {data['data']['character']['name']} ({data['data']['anime']['name']})**" else: response.raise_for_status() except Exception as exception: From 429dd9690f63f280124b8686915f24811d94e9b1 Mon Sep 17 00:00:00 2001 From: Wudi Date: Wed, 25 Mar 2026 11:23:10 +0530 Subject: [PATCH 5/5] fix: update google image URL --- userbot/core/inlinebot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/userbot/core/inlinebot.py b/userbot/core/inlinebot.py index 865751fc18..87aedcc5f4 100644 --- a/userbot/core/inlinebot.py +++ b/userbot/core/inlinebot.py @@ -529,7 +529,7 @@ async def youtube_data_article(event, str_y): async def google_search_article(event, input_str): font_url = "https://github.com/TgCatUB/CatUserbot-Resources/raw/master/Resources/fonts/roboto_regular.ttf" - image_url = "https://raw.githubusercontent.com/ZAR0X/CatUserbot-Resources/refs/heads/master/Resources/Inline/google.webp" + image_url = "https://raw.githubusercontent.com/TgCatUB/CatUserbot-Resources/refs/heads/master/Resources/Inline/google.webp" font_res = requests.get(font_url) font_res.raise_for_status() font_data = io.BytesIO(font_res.content)