Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions userbot/core/inlinebot.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -518,6 +527,65 @@ 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"
Comment thread
ZAR0X marked this conversation as resolved.
Outdated
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")
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)
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 = []
Expand Down
4 changes: 2 additions & 2 deletions userbot/plugins/alive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 17 additions & 8 deletions userbot/plugins/google.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -226,12 +232,15 @@ 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)
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()