Skip to content

Commit cc0d930

Browse files
authored
Bug fix (#383)
2 parents 9ed9f66 + bf8d49e commit cc0d930

5 files changed

Lines changed: 110 additions & 8 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ htmlcov/
4242
.coverage
4343
.coverage.*
4444
.cache
45+
cache/
46+
temp
4547
nosetests.xml
4648
coverage.xml
4749
*.cover
@@ -105,3 +107,5 @@ config.py
105107
# mypy
106108
.mypy_cache/
107109
*.bak
110+
111+
CatTgbot.session

stringsetup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616

1717
with TelegramClient(StringSession(), APP_ID, API_HASH) as client:
1818
print(client.session.save())
19-
client.sendmessage("me", client.session.save())
19+
client.send_message("me", client.session.save())

userbot/core/inlinebot.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@
77
# Please see: https://github.com/TgCatUB/catuserbot/blob/master/LICENSE
88
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
99

10+
import io
1011
import json
1112
import math
1213
import os
1314
import random
1415
import re
16+
import requests
1517
import time
18+
import urllib.parse
19+
import textwrap
1620
from pathlib import Path
1721

22+
from PIL import Image, ImageDraw, ImageFont
1823
from telethon import Button, types
1924
from telethon.events import CallbackQuery, InlineQuery
2025
from youtubesearchpython import VideosSearch
@@ -475,6 +480,9 @@ async def inline_handler(event):
475480
elif str_y[0].lower() == "ytdl" and len(str_y) == 2:
476481
result = await youtube_data_article(event, str_y)
477482
await event.answer([result] if result else None)
483+
elif str_y[0].lower() == "google" and len(str_y) >= 2:
484+
result = await google_search_article(event, str_y[1].strip())
485+
await event.answer([result] if result else None)
478486
elif string == "age_verification_alert":
479487
result = await age_verification_article(event)
480488
await event.answer([result] if result else None)
@@ -541,6 +549,65 @@ async def youtube_data_article(event, str_y):
541549
return result
542550

543551

552+
async def google_search_article(event, input_str):
553+
font_url = "https://github.com/TgCatUB/CatUserbot-Resources/raw/master/Resources/fonts/roboto_regular.ttf"
554+
image_url = "https://raw.githubusercontent.com/ZAR0X/CatUserbot-Resources/refs/heads/master/Resources/Inline/google.webp"
555+
font_res = requests.get(font_url)
556+
font_res.raise_for_status()
557+
font_data = io.BytesIO(font_res.content)
558+
559+
img_res = requests.get(image_url)
560+
img_res.raise_for_status()
561+
img = Image.open(io.BytesIO(img_res.content)).convert("RGBA")
562+
563+
draw = ImageDraw.Draw(img)
564+
565+
box_x1, box_y1, box_x2, box_y2 = 40, 240, 472, 370
566+
box_width = box_x2 - box_x1
567+
box_height = box_y2 - box_y1
568+
569+
font_size = 40
570+
if len(input_str) > 35:
571+
font_size = 32
572+
if len(input_str) > 80:
573+
font_size = 24
574+
575+
font = ImageFont.truetype(font_data, font_size)
576+
577+
avg_char_width = font.getlength("a") if hasattr(font, "getlength") else font.getsize("a")[0]
578+
chars_per_line = max(1, int(box_width / (avg_char_width * 1.05)))
579+
580+
lines = textwrap.wrap(input_str, width=chars_per_line)
581+
wrapped_text = "\n".join(lines)
582+
583+
if hasattr(draw, "multiline_textbbox"):
584+
left, top, right, bottom = draw.multiline_textbbox((0, 0), wrapped_text, font=font)
585+
else:
586+
w, h = draw.multiline_textsize(wrapped_text, font=font)
587+
left, top, right, bottom = 0, 0, w, h
588+
589+
text_w = right - left
590+
text_h = bottom - top
591+
592+
x = box_x1 + (box_width - text_w) / 2
593+
y = box_y1 + (box_height - text_h) / 2
594+
595+
draw.multiline_text((x, y), wrapped_text, font=font, fill="#3c4043", align="center")
596+
out_buffer = io.BytesIO()
597+
out_buffer.name = "google_search.png"
598+
img.save(out_buffer, "PNG")
599+
out_buffer.seek(0)
600+
601+
search_query_url = f"https://www.google.com/search?q={urllib.parse.quote_plus(input_str)}"
602+
buttons = [Button.url("Google Search", search_query_url)]
603+
604+
uploaded_file = await catub.tgbot.upload_file(out_buffer)
605+
return event.builder.photo(
606+
file=uploaded_file,
607+
text="", # Ensuring only the image and button are sent
608+
buttons=buttons
609+
)
610+
544611
async def hide_toll_secret(event, query, match, match3):
545612
user_list = []
546613
if match3:

userbot/plugins/alive.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,30 @@
3333

3434
plugin_category = "utils"
3535

36+
ANIME_QUOTE = [
37+
"✮ One’s act, one’s profit 🖤",
38+
"✮ Ten men, ten colors 🖤",
39+
"✮ Wake from death and return to life 🖤",
40+
"✮ Evil cause, evil effect 🖤",
41+
"✮ The weak are meat; the strong eat 🖤",
42+
"✮ Drunken life, dreamy death 🖤",
43+
"✮ One life, one encounter 🖤",
44+
"✮ Different body, same mind 🖤",
45+
"✮ Meeting person always separated 🖤",
46+
"✮ Beautiful person, thin life 🖤",
47+
"✮ Work of self, obtainment of self 🖤",
48+
"✮ If you do not enter the tiger’s cave, you will not catch its cub 🖤",
49+
"✮ Even monkeys fall from trees 🖤",
50+
"✮ There are even bugs that eat knotweed 🖤",
51+
"✮ Spilt water will not return to the tray 🖤",
52+
"✮ Gold coins to a cat 🖤",
53+
"✮ A frog in a well does not know the great sea 🖤",
54+
"✮ One who chases after two hares won’t catch even one 🖤",
55+
"✮ An apprentice near a temple will recite the scriptures untaught 🖤",
56+
"✮ Fall down seven times, stand up eight 🖤",
57+
"✮ Unless an idiot dies, he won’t be cured 🖤",
58+
"✮ Give up on your dreams and die 🖤",
59+
]
3660

3761
@catub.cat_cmd(
3862
pattern="alive$",
@@ -59,8 +83,8 @@ async def amireallyalive(event):
5983
end = datetime.now()
6084
ms = (end - start).microseconds / 1000
6185
_, check_sgnirts = check_data_base_heal_th()
62-
EMOJI = gvarstatus("ALIVE_EMOJI") or " "
63-
ALIVE_TEXT = gvarstatus("ALIVE_TEXT") or "**✮ MY BOT IS RUNNING SUCCESSFULLY ✮**"
86+
EMOJI = gvarstatus("ALIVE_EMOJI") or " ✧✧ "
87+
ALIVE_TEXT = gvarstatus("ALIVE_TEXT") or f"{random.choice(ANIME_QUOTE)}"
6488
CAT_IMG = gvarstatus("ALIVE_PIC")
6589
caption = cat_caption.format(
6690
ALIVE_TEXT=ALIVE_TEXT,

userbot/plugins/google.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from search_engine_parser import BingSearch, GoogleSearch, YahooSearch
1717
from search_engine_parser.core.exceptions import NoResultsOrTrafficError
1818

19-
from userbot import BOTLOG, BOTLOG_CHATID, Convert, catub
19+
from userbot import BOTLOG, BOTLOG_CHATID, Convert, catub, Config
2020

2121
from ..core.managers import edit_delete, edit_or_reply
2222
from ..helpers.functions import deEmojify, unsavegif
@@ -247,12 +247,19 @@ async def google_search(event):
247247
event, "__What should i search? Give search query plox.__"
248248
)
249249
input_str = deEmojify(input_str).strip()
250-
if len(input_str) > 195 or len(input_str) < 1:
250+
if len(input_str) > 150 or len(input_str) < 1:
251251
return await edit_delete(
252252
event,
253-
"__Plox your search query exceeds 200 characters or you search query is empty.__",
253+
"__Plox your search query exceeds 150 characters or your search query is empty.__",
254254
)
255-
query = f"#12{input_str}"
256-
results = await event.client.inline_query("@StickerizerBot", query)
255+
256+
catevent = await edit_or_reply(event, "`Processing query...`")
257+
258+
# try:
259+
query = f"google {input_str}"
260+
results = await event.client.inline_query(Config.TG_BOT_USERNAME, query)
257261
await results[0].click(event.chat_id, reply_to=reply_to_id, hide_via=True)
262+
await catevent.delete()
258263
await event.delete()
264+
# except Exception as e:
265+
# await edit_delete(catevent, f"__Error sending inline result: {str(e)}__")

0 commit comments

Comments
 (0)