Bug fixes V2.1 (#467)
* Ultroid 2025 Co-authored-by: New-dev0 <New-dev0@users.noreply.github.com> Co-authored-by: Amit Sharma <buddhhu@users.noreply.github.com> Co-authored-by: TechiError <techierror@users.noreply.github.com> Co-authored-by: Aditya <me@xditya.me> Co-authored-by: 1Danish-00 <danish@ultroid.tech> Co-authored-by: Arnab Paryali <Arnabxd@users.noreply.github.com> Co-authored-by: hellboi_atul <hellboi-atul@users.noreply.github.com> Co-authored-by: sppidy <sppidy@users.noreply.github.com> by Devesh Pal
This commit is contained in:
@@ -20,8 +20,8 @@ try:
|
||||
from pyUltroid.fns.gDrive import GDriveManager
|
||||
except ImportError:
|
||||
GDriveManager = None
|
||||
from telegraph import upload_file as upl
|
||||
from telethon import Button, events
|
||||
from catbox import CatboxUploader
|
||||
from telethon.tl.types import MessageMediaWebPage
|
||||
from telethon.utils import get_peer_id
|
||||
|
||||
@@ -34,9 +34,9 @@ from . import *
|
||||
# --------------------------------------------------------------------#
|
||||
telegraph = telegraph_client()
|
||||
GDrive = GDriveManager() if GDriveManager else None
|
||||
uploader = CatboxUploader()
|
||||
# --------------------------------------------------------------------#
|
||||
|
||||
|
||||
def text_to_url(event):
|
||||
"""function to get media url (with|without) Webpage"""
|
||||
if isinstance(event.media, MessageMediaWebPage):
|
||||
@@ -322,9 +322,9 @@ async def update(eve):
|
||||
await eve.edit(get_string("clst_1"))
|
||||
call_back()
|
||||
await bash("git pull && pip3 install -r requirements.txt")
|
||||
await bash("pip3 install -r requirements.txt --break-system-packages")
|
||||
execl(sys.executable, sys.executable, "-m", "pyUltroid")
|
||||
|
||||
|
||||
@callback(re.compile("changes(.*)"), owner=True)
|
||||
async def changes(okk):
|
||||
match = okk.data_match.group(1).decode("utf-8")
|
||||
@@ -384,11 +384,14 @@ async def _(e):
|
||||
if "|" in ok:
|
||||
ok, index = ok.split("|")
|
||||
with open(ok, "r") as hmm:
|
||||
_, key = await get_paste(hmm.read())
|
||||
link = f"https://spaceb.in/{key}"
|
||||
raw = f"https://spaceb.in/api/v1/documents/{key}/raw"
|
||||
if not _:
|
||||
_, data = await get_paste(hmm.read())
|
||||
if not data.get("link"):
|
||||
return await e.answer(key[:30], alert=True)
|
||||
if not key.startswith("http"):
|
||||
link, raw = data["link"], data["raw"]
|
||||
else:
|
||||
link = key
|
||||
raw = f"{key}/raw"
|
||||
if ok.startswith("addons"):
|
||||
key = "Addons"
|
||||
elif ok.startswith("vcbot"):
|
||||
@@ -830,8 +833,7 @@ async def media(event):
|
||||
else:
|
||||
media = await event.client.download_media(response, "alvpc")
|
||||
try:
|
||||
x = upl(media)
|
||||
url = f"https://graph.org/{x[0]}"
|
||||
url = uploader.upload_file(media)
|
||||
remove(media)
|
||||
except BaseException as er:
|
||||
LOGS.exception(er)
|
||||
@@ -969,8 +971,7 @@ async def media(event):
|
||||
url = response.file.id
|
||||
else:
|
||||
try:
|
||||
x = upl(media)
|
||||
url = f"https://graph.org/{x[0]}"
|
||||
url = uploader.upload_file(media)
|
||||
remove(media)
|
||||
except BaseException as er:
|
||||
LOGS.exception(er)
|
||||
@@ -1239,8 +1240,7 @@ async def media(event):
|
||||
url = text_to_url(response)
|
||||
else:
|
||||
try:
|
||||
x = upl(media)
|
||||
url = f"https://graph.org/{x[0]}"
|
||||
url = uploader.upload_file(media)
|
||||
remove(media)
|
||||
except BaseException as er:
|
||||
LOGS.exception(er)
|
||||
|
||||
@@ -14,23 +14,28 @@
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import re
|
||||
import re, uuid, operator
|
||||
from random import choice, shuffle
|
||||
|
||||
from akipy.async_akipy import Akinator, akipyLOGS
|
||||
from akipy.async_akipy import Akinator
|
||||
from telethon.errors.rpcerrorlist import BotMethodInvalidError
|
||||
from telethon.events import Raw
|
||||
from telethon.tl.types import InputMediaPoll, Poll, PollAnswer, UpdateMessagePollVote
|
||||
|
||||
from pyUltroid._misc._decorators import ultroid_cmd
|
||||
from logging import getLogger
|
||||
from html import unescape
|
||||
from telethon.tl.types import TextWithEntities
|
||||
from pyUltroid.fns.helper import inline_mention
|
||||
from pyUltroid.fns.tools import async_searcher
|
||||
from telethon.errors import ChatSendStickersForbiddenError
|
||||
|
||||
from . import * # Ensure this import matches your project structure
|
||||
|
||||
games = {}
|
||||
aki_photo = "https://graph.org/file/3cc8825c029fd0cab9edc.jpg"
|
||||
|
||||
akipyLOGS = getLogger("akipy")
|
||||
|
||||
@ultroid_cmd(pattern="akinator")
|
||||
async def akina(e):
|
||||
@@ -133,11 +138,7 @@ async def eiagx(e):
|
||||
|
||||
# ----------------------- Main Command ------------------- #
|
||||
|
||||
GIMAGES = [
|
||||
"https://graph.org/file/1c51015bae5205a65fd69.jpg",
|
||||
"https://imgwhale.xyz/3xyr322l64j9590",
|
||||
]
|
||||
|
||||
GIMAGE = "https://graph.org/file/1c51015bae5205a65fd69.jpg"
|
||||
|
||||
@asst_cmd(pattern="startgame", owner=True)
|
||||
async def magic(event):
|
||||
@@ -147,7 +148,7 @@ async def magic(event):
|
||||
]
|
||||
await event.reply(
|
||||
get_string("games_1"),
|
||||
file=choice(GIMAGES),
|
||||
file=GIMAGE,
|
||||
buttons=buttons,
|
||||
)
|
||||
|
||||
@@ -243,10 +244,10 @@ async def choose_cata(event):
|
||||
if TRIVIA_CHATS[chat].get("cancel") is not None:
|
||||
break
|
||||
ansi = str(uuid.uuid1()).split("-")[0].encode()
|
||||
opts = [PollAnswer(unescape(q["correct_answer"]), ansi)]
|
||||
opts = [PollAnswer(TextWithEntities(unescape(q["correct_answer"]), entities=[]), ansi)]
|
||||
[
|
||||
opts.append(
|
||||
PollAnswer(unescape(a), str(uuid.uuid1()).split("-")[0].encode())
|
||||
PollAnswer(TextWithEntities(unescape(a), entities=[]), str(uuid.uuid1()).split("-")[0].encode())
|
||||
)
|
||||
for a in q["incorrect_answers"]
|
||||
]
|
||||
@@ -254,7 +255,10 @@ async def choose_cata(event):
|
||||
poll = InputMediaPoll(
|
||||
Poll(
|
||||
0,
|
||||
TextWithEntities(
|
||||
f"[{copper+1}]. " + unescape(q["question"]),
|
||||
entities=[]
|
||||
),
|
||||
answers=opts,
|
||||
public_voters=True,
|
||||
quiz=True,
|
||||
@@ -298,13 +302,22 @@ async def choose_cata(event):
|
||||
@asst.on(
|
||||
Raw(UpdateMessagePollVote, func=lambda x: TRIVIA_CHATS and POLLS.get(x.poll_id))
|
||||
)
|
||||
async def pollish(eve):
|
||||
async def pollish(eve: UpdateMessagePollVote):
|
||||
if POLLS.get(eve.poll_id)["chat"] not in TRIVIA_CHATS.keys():
|
||||
return
|
||||
if not eve.options:
|
||||
# Consider as correct answer if no options selected
|
||||
chat = POLLS.get(eve.poll_id)["chat"]
|
||||
user = eve.peer.user_id
|
||||
if not TRIVIA_CHATS.get(chat, {}).get(user):
|
||||
TRIVIA_CHATS[chat][user] = 1
|
||||
else:
|
||||
TRIVIA_CHATS[chat][user] += 1
|
||||
return
|
||||
if POLLS[eve.poll_id]["answer"] != eve.options[0]:
|
||||
return
|
||||
chat = POLLS.get(eve.poll_id)["chat"]
|
||||
user = eve.user_id
|
||||
user = eve.peer.user_id
|
||||
if not TRIVIA_CHATS.get(chat, {}).get(user):
|
||||
TRIVIA_CHATS[chat][user] = 1
|
||||
else:
|
||||
|
||||
@@ -25,6 +25,7 @@ from pyUltroid.fns.tools import *
|
||||
from pyUltroid.startup._database import _BaseDatabase as Database
|
||||
from pyUltroid.version import __version__, ultroid_version
|
||||
from strings import get_help, get_string
|
||||
from catbox import CatboxUploader
|
||||
|
||||
udB: Database
|
||||
|
||||
@@ -50,6 +51,9 @@ def inline_pic():
|
||||
|
||||
|
||||
Telegraph = telegraph_client()
|
||||
cat_uploader = CatboxUploader()
|
||||
|
||||
upload_file = cat_uploader.upload_file
|
||||
|
||||
List = []
|
||||
Dict = {}
|
||||
@@ -84,6 +88,7 @@ KANGING_STR = [
|
||||
"Mr.Steal-Your-Sticker is stealing this sticker... ",
|
||||
]
|
||||
|
||||
|
||||
ATRA_COL = [
|
||||
"DarkCyan",
|
||||
"DeepSkyBlue",
|
||||
|
||||
@@ -115,8 +115,12 @@ async def inline_handler(event):
|
||||
@in_pattern("pasta", owner=True)
|
||||
async def _(event):
|
||||
ok = event.text.split("-")[1]
|
||||
if not ok.startswith("http"):
|
||||
link = f"https://spaceb.in/{ok}"
|
||||
raw = f"https://spaceb.in/api/v1/documents/{ok}/raw"
|
||||
else:
|
||||
link = ok
|
||||
raw = f"{ok}/raw"
|
||||
result = await event.builder.article(
|
||||
title="Paste",
|
||||
text="Pasted to Spacebin 🌌",
|
||||
|
||||
@@ -12,7 +12,6 @@ __doc__ = get_help("help_afk")
|
||||
|
||||
import asyncio
|
||||
|
||||
from telegraph import upload_file as uf
|
||||
from telethon import events
|
||||
|
||||
from pyUltroid.dB.afk_db import add_afk, del_afk, is_afk
|
||||
@@ -28,6 +27,7 @@ from . import (
|
||||
udB,
|
||||
ultroid_bot,
|
||||
ultroid_cmd,
|
||||
upload_file
|
||||
)
|
||||
|
||||
old_afk_msg = []
|
||||
@@ -50,8 +50,7 @@ async def set_afk(event):
|
||||
media_type = mediainfo(reply.media)
|
||||
if media_type.startswith(("pic", "gif")):
|
||||
file = await event.client.download_media(reply.media)
|
||||
iurl = uf(file)
|
||||
media = f"https://graph.org{iurl[0]}"
|
||||
media = upload_file(file)
|
||||
else:
|
||||
media = reply.file.id
|
||||
await event.eor("`Done`", time=2)
|
||||
|
||||
@@ -13,14 +13,9 @@ import os
|
||||
|
||||
from pyUltroid.dB.asstcmd_db import add_cmd, cmd_reply, list_cmds, rem_cmd
|
||||
from pyUltroid.fns.tools import create_tl_btn, format_btn, get_msg_button
|
||||
|
||||
try:
|
||||
from telegraph import upload_file as uf
|
||||
except ImportError:
|
||||
uf = None
|
||||
from telethon import events, utils
|
||||
|
||||
from . import asst, get_string, mediainfo, udB, ultroid_cmd
|
||||
from . import asst, get_string, mediainfo, udB, ultroid_cmd, upload_file
|
||||
|
||||
|
||||
@ultroid_cmd(pattern="addcmd( (.*)|$)")
|
||||
@@ -36,16 +31,14 @@ async def ac(e):
|
||||
wut = mediainfo(wt.media)
|
||||
if wut.startswith(("pic", "gif")):
|
||||
dl = await e.client.download_media(wt.media)
|
||||
variable = uf(dl)
|
||||
m = upload_file(dl)
|
||||
os.remove(dl)
|
||||
m = f"https://graph.org{variable[0]}"
|
||||
elif wut == "video":
|
||||
if wt.media.document.size > 8 * 1000 * 1000:
|
||||
return await e.eor(get_string("com_4"), time=5)
|
||||
dl = await e.client.download_media(wt.media)
|
||||
variable = uf(dl)
|
||||
m = upload_file(dl)
|
||||
os.remove(dl)
|
||||
m = f"https://graph.org{variable[0]}"
|
||||
else:
|
||||
m = utils.pack_bot_file_id(wt.media)
|
||||
if wt.text:
|
||||
|
||||
@@ -26,8 +26,7 @@ from . import (
|
||||
mediainfo,
|
||||
stdr,
|
||||
time_formatter,
|
||||
ultroid_cmd,
|
||||
uploader,
|
||||
ultroid_cmd
|
||||
)
|
||||
|
||||
__doc__ = get_help("help_audiotools")
|
||||
@@ -104,13 +103,15 @@ async def trim_aud(e):
|
||||
await bash(cmd)
|
||||
os.remove(file.name)
|
||||
f_time = time.time()
|
||||
mmmm = await uploader(out, out, f_time, xxx, f"Uploading {out}...")
|
||||
n_file, _ = await e.client.fast_uploader(
|
||||
out, show_progress=True, event=e, message="Uploading...", to_delete=True
|
||||
)
|
||||
attributes = await set_attributes(out)
|
||||
|
||||
caption = get_string("audiotools_7").format(ss, dd)
|
||||
await e.client.send_file(
|
||||
e.chat_id,
|
||||
mmmm,
|
||||
n_file,
|
||||
thumb=ULTConfig.thumb,
|
||||
caption=caption,
|
||||
attributes=attributes,
|
||||
@@ -147,13 +148,15 @@ async def ex_aud(e):
|
||||
|
||||
f_time = time.time()
|
||||
try:
|
||||
fo = await uploader(out_file, out_file, f_time, msg, f"Uploading {out_file}...")
|
||||
n_file, _ = await e.client.fast_uploader(
|
||||
out_file, show_progress=True, event=e, message="Uploading...", to_delete=True
|
||||
)
|
||||
|
||||
except FileNotFoundError:
|
||||
return await eor(msg, get_string("audiotools_9"))
|
||||
await e.reply(
|
||||
get_string("audiotools_10"),
|
||||
file=fo,
|
||||
file=n_file,
|
||||
thumb=ULTConfig.thumb,
|
||||
attributes=attributes,
|
||||
)
|
||||
|
||||
@@ -211,6 +211,7 @@ async def restartbt(ult):
|
||||
if heroku_api:
|
||||
return await restart(ok)
|
||||
await bash("git pull && pip3 install -r requirements.txt")
|
||||
await bash("pip3 install -r requirements.txt --break-system-packages")
|
||||
if len(sys.argv) > 1:
|
||||
os.execl(sys.executable, sys.executable, "main.py")
|
||||
else:
|
||||
@@ -324,6 +325,7 @@ async def _(e):
|
||||
or "soft" in e.pattern_match.group(1).strip()
|
||||
):
|
||||
await bash("git pull -f && pip3 install -r requirements.txt")
|
||||
await bash("pip3 install -r requirements.txt --break-system-packages")
|
||||
call_back()
|
||||
await xx.edit(get_string("upd_7"))
|
||||
os.execl(sys.executable, "python3", "-m", "pyUltroid")
|
||||
|
||||
@@ -11,7 +11,7 @@ __doc__ = get_help("help_button")
|
||||
|
||||
import os
|
||||
|
||||
from telegraph import upload_file as uf
|
||||
from . import upload_file as uf
|
||||
from telethon.utils import pack_bot_file_id
|
||||
|
||||
from pyUltroid.fns.tools import create_tl_btn, get_msg_button
|
||||
@@ -31,15 +31,13 @@ async def butt(event):
|
||||
wut = mediainfo(wt.media)
|
||||
if wut and wut.startswith(("pic", "gif")):
|
||||
dl = await wt.download_media()
|
||||
variable = uf(dl)
|
||||
media = f"https://graph.org{variable[0]}"
|
||||
media = uf(dl)
|
||||
elif wut == "video":
|
||||
if wt.media.document.size > 8 * 1000 * 1000:
|
||||
return await event.eor(get_string("com_4"), time=5)
|
||||
dl = await wt.download_media()
|
||||
variable = uf(dl)
|
||||
media = uf(dl)
|
||||
os.remove(dl)
|
||||
media = f"https://graph.org{variable[0]}"
|
||||
else:
|
||||
media = pack_bot_file_id(wt.media)
|
||||
try:
|
||||
|
||||
@@ -139,7 +139,9 @@ async def _(e):
|
||||
caption += f"**Compressed Size: **`{humanbytes(c_size)}`\n"
|
||||
caption += f"**Compression Ratio: **`{differ:.2f}%`\n"
|
||||
caption += f"\n**Time Taken To Compress: **`{difff}`"
|
||||
mmmm = await uploader(out, out, f_time, xxx, f"Uploading {out}...")
|
||||
n_file, _ = await e.client.fast_uploader(
|
||||
out, show_progress=True, event=e, message="Uploading...", to_delete=True
|
||||
)
|
||||
if to_stream:
|
||||
data = await metadata(out)
|
||||
width = data["width"]
|
||||
@@ -152,7 +154,7 @@ async def _(e):
|
||||
]
|
||||
await e.client.send_file(
|
||||
e.chat_id,
|
||||
mmmm,
|
||||
n_file,
|
||||
thumb=ULTConfig.thumb,
|
||||
caption=caption,
|
||||
attributes=attributes,
|
||||
@@ -162,7 +164,7 @@ async def _(e):
|
||||
else:
|
||||
await e.client.send_file(
|
||||
e.chat_id,
|
||||
mmmm,
|
||||
n_file,
|
||||
thumb=ULTConfig.thumb,
|
||||
caption=caption,
|
||||
force_document=True,
|
||||
|
||||
@@ -25,7 +25,7 @@ except ImportError:
|
||||
LOGS.info(f"{__file__}: PIL not Installed.")
|
||||
Image = None
|
||||
|
||||
from telegraph import upload_file as uf
|
||||
from . import upload_file as uf
|
||||
|
||||
from . import (
|
||||
ULTConfig,
|
||||
@@ -53,9 +53,8 @@ async def _(e):
|
||||
dl = await r.download_media(thumb=-1)
|
||||
else:
|
||||
return await e.eor("`Reply to Photo or media with thumb...`")
|
||||
variable = uf(dl)
|
||||
nn = uf(dl)
|
||||
os.remove(dl)
|
||||
nn = f"https://graph.org{variable[0]}"
|
||||
udB.set_key("CUSTOM_THUMBNAIL", str(nn))
|
||||
await bash(f"wget {nn} -O resources/extras/ultroid.jpg")
|
||||
await e.eor(get_string("cvt_6").format(nn), link_preview=False)
|
||||
@@ -93,10 +92,12 @@ async def imak(event):
|
||||
if not os.path.exists(inp) or os.path.exists(inp) and not os.path.getsize(inp):
|
||||
os.rename(file, inp)
|
||||
k = time.time()
|
||||
xxx = await uploader(inp, inp, k, xx, get_string("com_6"))
|
||||
n_file, _ = await event.client.fast_uploader(
|
||||
inp, show_progress=True, event=event, message="Uploading...", to_delete=True
|
||||
)
|
||||
await event.reply(
|
||||
f"`{xxx.name}`",
|
||||
file=xxx,
|
||||
f"`{n_file.name}`",
|
||||
file=n_file,
|
||||
force_document=True,
|
||||
thumb=ULTConfig.thumb,
|
||||
)
|
||||
@@ -135,14 +136,18 @@ async def uconverter(event):
|
||||
except KeyError:
|
||||
return await xx.edit(get_string("sts_3").format("gif/img/sticker/webm"))
|
||||
file = await con.convert(b, outname="ultroid", convert_to=convert)
|
||||
print(file)
|
||||
|
||||
if file:
|
||||
await event.client.send_file(
|
||||
event.chat_id, file, reply_to=event.reply_to_msg_id or event.id
|
||||
)
|
||||
os.remove(file)
|
||||
else:
|
||||
await xx.edit("`Failed to convert`")
|
||||
return
|
||||
await xx.delete()
|
||||
|
||||
|
||||
@ultroid_cmd(
|
||||
pattern="doc( (.*)|$)",
|
||||
)
|
||||
@@ -183,9 +188,9 @@ async def _(event):
|
||||
try:
|
||||
await xx.edit(f"```{d}```")
|
||||
except BaseException:
|
||||
what, key = await get_paste(d)
|
||||
what, data = await get_paste(d)
|
||||
await xx.edit(
|
||||
f"**MESSAGE EXCEEDS TELEGRAM LIMITS**\n\nSo Pasted It On [SPACEBIN](https://spaceb.in/{key})"
|
||||
f"**MESSAGE EXCEEDS TELEGRAM LIMITS**\n\nSo Pasted It On [SPACEBIN]({data['link']})"
|
||||
)
|
||||
if rem:
|
||||
os.remove(b)
|
||||
|
||||
@@ -33,10 +33,8 @@ try:
|
||||
from yaml import safe_load
|
||||
except ImportError:
|
||||
from pyUltroid.fns.tools import safe_load
|
||||
try:
|
||||
from telegraph import upload_file as uf
|
||||
except ImportError:
|
||||
uf = None
|
||||
|
||||
from . import upload_file as uf
|
||||
from telethon.tl import functions
|
||||
|
||||
fn = functions
|
||||
@@ -99,7 +97,7 @@ async def _(event):
|
||||
f"Unknown Response from Carbon: `{li}`\n\nstdout`:{stdout}`\nstderr: `{stderr}`"
|
||||
)
|
||||
return
|
||||
url = f"https://graph.org{uf(li)[-1]}"
|
||||
url = uf(li)
|
||||
OUT = f"[\xad]({url}){OUT}"
|
||||
out = "**• OUTPUT:**"
|
||||
remove(li)
|
||||
@@ -121,7 +119,7 @@ async def _(event):
|
||||
f"Unknown Response from Carbon: `{li}`\n\nstdout`:{stdout}`\nstderr: `{stderr}`"
|
||||
)
|
||||
return
|
||||
url = f"https://graph.org{uf(li)[-1]}"
|
||||
url = uf(li)
|
||||
OUT = f"[\xad]({url}){OUT}"
|
||||
out = "**• OUTPUT:**"
|
||||
remove(li)
|
||||
|
||||
@@ -12,14 +12,13 @@ __doc__ = get_help("help_filter")
|
||||
import os
|
||||
import re
|
||||
|
||||
from telegraph import upload_file as uf
|
||||
from telethon.tl.types import User
|
||||
from telethon.utils import pack_bot_file_id
|
||||
|
||||
from pyUltroid.dB.filter_db import add_filter, get_filter, list_filter, rem_filter
|
||||
from pyUltroid.fns.tools import create_tl_btn, format_btn, get_msg_button
|
||||
|
||||
from . import events, get_string, mediainfo, udB, ultroid_bot, ultroid_cmd
|
||||
from . import events, get_string, mediainfo, udB, ultroid_bot, ultroid_cmd, upload_file
|
||||
from ._inline import something
|
||||
|
||||
|
||||
@@ -35,15 +34,14 @@ async def af(e):
|
||||
wut = mediainfo(wt.media)
|
||||
if wut.startswith(("pic", "gif")):
|
||||
dl = await wt.download_media()
|
||||
variable = uf(dl)
|
||||
m = f"https://graph.org{variable[0]}"
|
||||
m = upload_file(dl)
|
||||
os.remove(dl)
|
||||
elif wut == "video":
|
||||
if wt.media.document.size > 8 * 1000 * 1000:
|
||||
return await e.eor(get_string("com_4"), time=5)
|
||||
dl = await wt.download_media()
|
||||
variable = uf(dl)
|
||||
m = upload_file(dl)
|
||||
os.remove(dl)
|
||||
m = f"https://graph.org{variable[0]}"
|
||||
else:
|
||||
m = pack_bot_file_id(wt.media)
|
||||
if wt.text:
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
"""
|
||||
import os
|
||||
|
||||
from telegraph import upload_file as uf
|
||||
from . import upload_file as uf
|
||||
from telethon.utils import pack_bot_file_id
|
||||
|
||||
from pyUltroid.dB.greetings_db import (
|
||||
@@ -67,16 +67,14 @@ async def setwel(event):
|
||||
wut = mediainfo(r.media)
|
||||
if wut.startswith(("pic", "gif")):
|
||||
dl = await r.download_media()
|
||||
variable = uf(dl)
|
||||
m = uf(dl)
|
||||
os.remove(dl)
|
||||
m = f"https://graph.org{variable[0]}"
|
||||
elif wut == "video":
|
||||
if r.media.document.size > 8 * 1000 * 1000:
|
||||
return await eor(x, get_string("com_4"), time=5)
|
||||
dl = await r.download_media()
|
||||
variable = uf(dl)
|
||||
m = uf(dl)
|
||||
os.remove(dl)
|
||||
m = f"https://graph.org{variable[0]}"
|
||||
elif wut == "web":
|
||||
m = None
|
||||
else:
|
||||
@@ -132,16 +130,14 @@ async def setgb(event):
|
||||
wut = mediainfo(r.media)
|
||||
if wut.startswith(("pic", "gif")):
|
||||
dl = await r.download_media()
|
||||
variable = uf(dl)
|
||||
m = uf(dl)
|
||||
os.remove(dl)
|
||||
m = f"https://graph.org{variable[0]}"
|
||||
elif wut == "video":
|
||||
if r.media.document.size > 8 * 1000 * 1000:
|
||||
return await eor(x, get_string("com_4"), time=5)
|
||||
dl = await r.download_media()
|
||||
variable = uf(dl)
|
||||
m = uf(dl)
|
||||
os.remove(dl)
|
||||
m = f"https://graph.org{variable[0]}"
|
||||
elif wut == "web":
|
||||
m = None
|
||||
else:
|
||||
|
||||
@@ -68,7 +68,8 @@ try:
|
||||
except ImportError:
|
||||
Image = None
|
||||
LOGS.info(f"{__file__}: PIL not Installed.")
|
||||
from telegraph import upload_file as upf
|
||||
|
||||
from . import upload_file as upf
|
||||
from telethon.errors.rpcerrorlist import (
|
||||
ChatSendMediaForbiddenError,
|
||||
MessageDeleteForbiddenError,
|
||||
@@ -217,8 +218,7 @@ async def ultd(event):
|
||||
if ultt.endswith(".tgs"):
|
||||
await xx.edit(get_string("sts_9"))
|
||||
file = await con.convert(ultt, convert_to="png", outname="ult")
|
||||
got = upf(file)
|
||||
lnk = f"https://graph.org{got[0]}"
|
||||
lnk = upf(file)
|
||||
r = await async_searcher(
|
||||
f"https://nekobot.xyz/api/imagegen?type=blurpify&image={lnk}", re_json=True
|
||||
)
|
||||
|
||||
@@ -27,6 +27,7 @@ from . import (
|
||||
bash,
|
||||
downloader,
|
||||
get_string,
|
||||
upload_file,
|
||||
is_url_ok,
|
||||
mediainfo,
|
||||
ultroid_cmd,
|
||||
@@ -87,7 +88,7 @@ async def mi(e):
|
||||
makehtml = ""
|
||||
if naam.endswith((".jpg", ".png")):
|
||||
if os.path.exists(naam):
|
||||
med = "https://graph.org" + Telegraph.upload_file(naam)[0]["src"]
|
||||
med = upload_file(naam)
|
||||
else:
|
||||
med = match
|
||||
makehtml += f"<img src='{med}'><br>"
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
"""
|
||||
import os
|
||||
|
||||
from telegraph import upload_file as uf
|
||||
from . import upload_file as uf
|
||||
from telethon.utils import pack_bot_file_id
|
||||
|
||||
from pyUltroid.dB.notes_db import add_note, get_notes, list_note, rem_note
|
||||
@@ -46,16 +46,14 @@ async def an(e):
|
||||
wut = mediainfo(wt.media)
|
||||
if wut.startswith(("pic", "gif")):
|
||||
dl = await wt.download_media()
|
||||
variable = uf(dl)
|
||||
m = uf(dl)
|
||||
os.remove(dl)
|
||||
m = f"https://graph.org{variable[0]}"
|
||||
elif wut == "video":
|
||||
if wt.media.document.size > 8 * 1000 * 1000:
|
||||
return await e.eor(get_string("com_4"), time=5)
|
||||
dl = await wt.download_media()
|
||||
variable = uf(dl)
|
||||
m = uf(dl)
|
||||
os.remove(dl)
|
||||
m = f"https://graph.org{variable[0]}"
|
||||
else:
|
||||
m = pack_bot_file_id(wt.media)
|
||||
if wt.text:
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
Get the quiz poll where answerno is the number of option which is correct
|
||||
|
||||
"""
|
||||
from telethon.tl.types import InputMediaPoll, Poll, PollAnswer
|
||||
from telethon.tl.types import InputMediaPoll, Poll, PollAnswer, TextWithEntities
|
||||
|
||||
from . import get_string, ultroid_cmd
|
||||
|
||||
@@ -57,10 +57,10 @@ async def uri_poll(e):
|
||||
if len(option) <= 1:
|
||||
return await e.eor("`Options Should be More than 1..`", time=5)
|
||||
m = await e.eor(get_string("com_1"))
|
||||
OUT = [PollAnswer(option[on], str(on).encode()) for on in range(len(option))]
|
||||
OUT = [PollAnswer(TextWithEntities(option[on], entities=[]), str(on).encode()) for on in range(len(option))]
|
||||
await e.respond(
|
||||
file=InputMediaPoll(
|
||||
Poll(20, ques, OUT, multiple_choice=mpp, public_voters=publ, quiz=quizo),
|
||||
Poll(20, TextWithEntities(ques, entities=[]), OUT, multiple_choice=mpp, public_voters=publ, quiz=quizo),
|
||||
correct_answers=karzo,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -152,8 +152,10 @@ async def reverse(event):
|
||||
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0",
|
||||
},
|
||||
)
|
||||
with open("response.html", "w") as f:
|
||||
f.write(response)
|
||||
xx = bs(response, "html.parser")
|
||||
div = xx.find_all("div", {"class": "r5a77d"})[0]
|
||||
div = xx.find_all("div", {"class": "kb0PBd"})[0]
|
||||
alls = div.find("a")
|
||||
link = alls["href"]
|
||||
text = alls.text
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
"""
|
||||
import os
|
||||
|
||||
from telegraph import upload_file as uf
|
||||
from . import upload_file as uf
|
||||
from telethon.utils import pack_bot_file_id
|
||||
|
||||
from pyUltroid._misc import sudoers
|
||||
@@ -45,16 +45,14 @@ async def an(e):
|
||||
wut = mediainfo(wt.media)
|
||||
if wut.startswith(("pic", "gif")):
|
||||
dl = await wt.download_media()
|
||||
variable = uf(dl)
|
||||
m = uf(dl)
|
||||
os.remove(dl)
|
||||
m = f"https://graph.org{variable[0]}"
|
||||
elif wut == "video":
|
||||
if wt.media.document.size > 8 * 1000 * 1000:
|
||||
return await e.eor(get_string("com_4"), time=5)
|
||||
dl = await wt.download_media()
|
||||
variable = uf(dl)
|
||||
m = uf(dl)
|
||||
os.remove(dl)
|
||||
m = f"https://graph.org{variable[0]}"
|
||||
else:
|
||||
m = pack_bot_file_id(wt.media)
|
||||
if wt.text:
|
||||
|
||||
@@ -36,10 +36,11 @@ import time
|
||||
from datetime import datetime as dt
|
||||
from random import choice
|
||||
|
||||
import pytz
|
||||
import pytz, asyncio
|
||||
from bs4 import BeautifulSoup as bs
|
||||
from telethon.tl.types import DocumentAttributeVideo
|
||||
|
||||
from requests import Session
|
||||
from cloudscraper import create_scraper
|
||||
from pyUltroid.fns.tools import get_google_images, metadata
|
||||
|
||||
from . import (
|
||||
@@ -59,7 +60,7 @@ from . import (
|
||||
from .beautify import all_col
|
||||
|
||||
File = []
|
||||
|
||||
scraper = create_scraper()
|
||||
|
||||
@ultroid_cmd(
|
||||
pattern="getaudio$",
|
||||
@@ -250,6 +251,7 @@ Zodiac -: {sign}
|
||||
reply_to=event.reply_to_msg_id,
|
||||
)
|
||||
|
||||
session = Session()
|
||||
|
||||
@ultroid_cmd(pattern="sticker( (.*)|$)")
|
||||
async def _(event):
|
||||
@@ -257,23 +259,61 @@ async def _(event):
|
||||
if not x:
|
||||
return await event.eor("`Give something to search`")
|
||||
uu = await event.eor(get_string("com_1"))
|
||||
z = bs(
|
||||
await async_searcher(f"https://combot.org/telegram/stickers?q={x}"),
|
||||
"html.parser",
|
||||
)
|
||||
|
||||
packs = z.find_all("div", "sticker-pack__header")
|
||||
sticks = {
|
||||
c.a["href"]: c.find("div", {"class": "sticker-pack__title"}).text for c in packs
|
||||
headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
||||
}
|
||||
|
||||
max_retries = 3
|
||||
retry_count = 0
|
||||
|
||||
while retry_count < max_retries:
|
||||
try:
|
||||
response = scraper.get(
|
||||
f"https://combot.org/telegram/stickers?q={x}",
|
||||
headers=headers
|
||||
).content
|
||||
|
||||
# Check if response contains Cloudflare challenge
|
||||
if "Just a moment..." in response.decode():
|
||||
retry_count += 1
|
||||
await asyncio.sleep(2) # Wait before retry
|
||||
continue
|
||||
|
||||
z = bs(response, "html.parser")
|
||||
packs = z.find_all("a", {"class": "stickerset__title"})
|
||||
|
||||
if not packs:
|
||||
return await uu.edit(get_string("spcltool_9"))
|
||||
|
||||
break # Success - exit loop
|
||||
|
||||
except Exception as er:
|
||||
retry_count += 1
|
||||
await asyncio.sleep(2)
|
||||
continue
|
||||
|
||||
if retry_count >= max_retries:
|
||||
return await uu.edit("`Failed to fetch stickers after multiple retries`")
|
||||
try:
|
||||
sticks = {}
|
||||
for pack in packs:
|
||||
href = pack.get("href")
|
||||
title = pack.text.strip()
|
||||
if href:
|
||||
href = f"https://t.me/addstickers/{href.split('/')[-1]}"
|
||||
sticks[href] = title
|
||||
|
||||
if not sticks:
|
||||
return await uu.edit(get_string("spcltool_9"))
|
||||
|
||||
a = "SᴛɪᴄᴋEʀs Aᴠᴀɪʟᴀʙʟᴇ ~\n\n"
|
||||
for _, value in sticks.items():
|
||||
a += f"<a href={_}>{value}</a>\n"
|
||||
for href, title in sticks.items():
|
||||
a += f"<a href={href}>{title}</a>\n"
|
||||
await uu.edit(a, parse_mode="html")
|
||||
|
||||
except Exception as e:
|
||||
await uu.edit(f"`Error: {str(e)}`\nTry again later.")
|
||||
|
||||
@ultroid_cmd(pattern="wall( (.*)|$)")
|
||||
async def wall(event):
|
||||
|
||||
@@ -81,8 +81,10 @@ async def twitter_details(event):
|
||||
msg = await event.eor("🔍 `Getting tweet details...`")
|
||||
try:
|
||||
client = await get_client()
|
||||
if "twitter.com" in match or "x.com" in match:
|
||||
tweet_id = match.split("/")[-1].split("?")[0]
|
||||
from urllib.parse import urlparse
|
||||
parsed_url = urlparse(match)
|
||||
if parsed_url.hostname in ["twitter.com", "x.com"]:
|
||||
tweet_id = parsed_url.path.split("/")[-1].split("?")[0]
|
||||
else:
|
||||
tweet_id = match
|
||||
|
||||
|
||||
@@ -67,10 +67,7 @@ from pyUltroid._misc._assistant import asst_cmd
|
||||
from pyUltroid.dB.gban_mute_db import is_gbanned
|
||||
from pyUltroid.fns.tools import get_chat_and_msgid
|
||||
|
||||
try:
|
||||
from telegraph import upload_file as uf
|
||||
except ImportError:
|
||||
uf = None
|
||||
from . import upload_file as uf
|
||||
|
||||
from telethon.errors.rpcerrorlist import ChatForwardsRestrictedError, UserBotError
|
||||
from telethon.errors import MessageTooLongError
|
||||
@@ -266,18 +263,16 @@ async def _(event):
|
||||
return await xx.eor(
|
||||
"`Reply to a Message/Document or Give me Some Text !`", time=5
|
||||
)
|
||||
done, key = await get_paste(message)
|
||||
if not done:
|
||||
return await xx.eor(key)
|
||||
link = f"https://spaceb.in/{key}"
|
||||
raw = f"https://spaceb.in/api/v1/documents/{key}/raw"
|
||||
done, data = await get_paste(message)
|
||||
if not done and data.get("error"):
|
||||
return await xx.eor(data["error"])
|
||||
reply_text = (
|
||||
f"• **Pasted to SpaceBin :** [Space]({link})\n• **Raw Url :** : [Raw]({raw})"
|
||||
f"• **Pasted to SpaceBin :** [Space]({data['link']})\n• **Raw Url :** : [Raw]({data['raw']})"
|
||||
)
|
||||
try:
|
||||
if event.client._bot:
|
||||
return await xx.eor(reply_text)
|
||||
ok = await event.client.inline_query(asst.me.username, f"pasta-{key}")
|
||||
ok = await event.client.inline_query(asst.me.username, f"pasta-{data['link']}")
|
||||
await ok[0].click(event.chat_id, reply_to=event.reply_to_msg_id, hide_via=True)
|
||||
await xx.delete()
|
||||
except BaseException as e:
|
||||
@@ -506,7 +501,7 @@ async def telegraphcmd(event):
|
||||
getit = file
|
||||
if "document" not in dar:
|
||||
try:
|
||||
nn = f"https://graph.org{uf(getit)[0]}"
|
||||
nn = uf(getit)
|
||||
amsg = f"Uploaded to [Telegraph]({nn}) !"
|
||||
except Exception as e:
|
||||
amsg = f"Error : {e}"
|
||||
|
||||
@@ -74,7 +74,8 @@ async def writer(e):
|
||||
font = ImageFont.truetype("resources/fonts/assfont.ttf", 30)
|
||||
x, y = 150, 140
|
||||
lines = text_set(text)
|
||||
line_height = font.getsize("hg")[1]
|
||||
bbox = font.getbbox("hg")
|
||||
line_height = bbox[3] - bbox[1]
|
||||
for line in lines:
|
||||
draw.text((x, y), line, fill=(1, 22, 55), font=font)
|
||||
y = y + line_height - 5
|
||||
|
||||
@@ -63,13 +63,15 @@ async def zipp(event):
|
||||
else:
|
||||
await bash(f"zip -r {inp} {file}")
|
||||
k = time.time()
|
||||
xxx = await uploader(inp, inp, k, xx, get_string("com_6"))
|
||||
n_file, _ = await event.client.fast_uploader(
|
||||
inp, show_progress=True, event=event, message="Uploading...", to_delete=True
|
||||
)
|
||||
await event.client.send_file(
|
||||
event.chat_id,
|
||||
xxx,
|
||||
n_file,
|
||||
force_document=True,
|
||||
thumb=ULTConfig.thumb,
|
||||
caption=f"`{xxx.name}`",
|
||||
caption=f"`{n_file.name}`",
|
||||
reply_to=reply,
|
||||
)
|
||||
os.remove(inp)
|
||||
@@ -104,13 +106,15 @@ async def unzipp(event):
|
||||
ok = get_all_files("unzip")
|
||||
for x in ok:
|
||||
k = time.time()
|
||||
xxx = await uploader(x, x, k, xx, get_string("com_6"))
|
||||
n_file, _ = await event.client.fast_uploader(
|
||||
x, show_progress=True, event=event, message="Uploading...", to_delete=True
|
||||
)
|
||||
await event.client.send_file(
|
||||
event.chat_id,
|
||||
xxx,
|
||||
n_file,
|
||||
force_document=True,
|
||||
thumb=ULTConfig.thumb,
|
||||
caption=f"`{xxx.name}`",
|
||||
caption=f"`{n_file.name}`",
|
||||
)
|
||||
await xx.delete()
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import string
|
||||
from logging import WARNING
|
||||
from random import choice, randrange, shuffle
|
||||
from traceback import format_exc
|
||||
from catbox import CatboxUploader
|
||||
|
||||
from pyUltroid.exceptions import DependencyMissingError
|
||||
|
||||
@@ -59,6 +60,7 @@ try:
|
||||
except ImportError:
|
||||
BeautifulSoup = None
|
||||
|
||||
uploader = CatboxUploader()
|
||||
|
||||
async def randomchannel(
|
||||
tochat, channel, range1, range2, caption=None, client=ultroid_bot
|
||||
@@ -295,15 +297,7 @@ class Quotly:
|
||||
async def telegraph(file_):
|
||||
file = file_ + ".png"
|
||||
Image.open(file_).save(file, "PNG")
|
||||
files = {"file": open(file, "rb").read()}
|
||||
uri = (
|
||||
"https://graph.org"
|
||||
+ (
|
||||
await async_searcher(
|
||||
"https://graph.org/upload", post=True, data=files, re_json=True
|
||||
)
|
||||
)[0]["src"]
|
||||
)
|
||||
uri = uploader.upload_file(file)
|
||||
os.remove(file)
|
||||
os.remove(file_)
|
||||
return uri
|
||||
|
||||
@@ -9,9 +9,9 @@ import json
|
||||
import math
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
import re, subprocess
|
||||
import secrets
|
||||
import ssl
|
||||
import ssl, html
|
||||
from io import BytesIO
|
||||
from json.decoder import JSONDecodeError
|
||||
from traceback import format_exc
|
||||
@@ -118,8 +118,12 @@ async def metadata(file):
|
||||
raise DependencyMissingError(
|
||||
f"'{_}' is not installed!\nInstall it to use this command."
|
||||
)
|
||||
|
||||
data = {}
|
||||
_info = json.loads(out)["media"]["track"]
|
||||
_info = json.loads(out)["media"]
|
||||
if not _info:
|
||||
return {}
|
||||
_info = _info["track"]
|
||||
info = _info[0]
|
||||
if info.get("Format") in ["GIF", "PNG"]:
|
||||
return {
|
||||
@@ -385,96 +389,110 @@ class LogoHelper:
|
||||
|
||||
|
||||
async def get_paste(data: str, extension: str = "txt"):
|
||||
ssl_context = ssl.create_default_context(cafile=certifi.where())
|
||||
json = {"content": data, "extension": extension}
|
||||
key = await async_searcher(
|
||||
url="https://spaceb.in/api/v1/documents/",
|
||||
json=json,
|
||||
ssl=ssl_context,
|
||||
post=True,
|
||||
re_json=True,
|
||||
)
|
||||
try:
|
||||
return True, key["payload"]["id"]
|
||||
except KeyError:
|
||||
if "the length must be between 2 and 400000." in key["error"]:
|
||||
return await get_paste(data[-400000:], extension=extension)
|
||||
return False, key["error"]
|
||||
url = "https://spaceb.in/api/"
|
||||
res = await async_searcher(url, json={"content": data, "extension": extension}, post=True, re_json=True)
|
||||
return True, {
|
||||
"link": f"https://spaceb.in/{res['payload']['id']}",
|
||||
"raw": f"https://spaceb.in/{res['payload']['id']}/raw"
|
||||
}
|
||||
except Exception:
|
||||
try:
|
||||
url = "https://dpaste.org/api/"
|
||||
data = {
|
||||
'format': 'json',
|
||||
'content': data.encode('utf-8'),
|
||||
'lexer': extension,
|
||||
'expires': '604800', # expire in week
|
||||
}
|
||||
res = await async_searcher(url, data=data, post=True, re_json=True)
|
||||
return True, {
|
||||
"link": res["url"],
|
||||
"raw": f'{res["url"]}/raw'
|
||||
}
|
||||
except Exception as e:
|
||||
LOGS.info(e)
|
||||
return None, str(e)
|
||||
return None, {
|
||||
"link": None,
|
||||
"raw": None,
|
||||
"error": str(e)
|
||||
}
|
||||
|
||||
|
||||
# --------------------------------------
|
||||
# https://stackoverflow.com/a/74563494
|
||||
|
||||
|
||||
async def get_google_images(query):
|
||||
soup = BeautifulSoup(
|
||||
await async_searcher(
|
||||
"https://google.com/search",
|
||||
params={"q": query, "tbm": "isch"},
|
||||
headers={"User-Agent": random.choice(some_random_headers)},
|
||||
),
|
||||
"lxml",
|
||||
)
|
||||
google_images = []
|
||||
all_script_tags = soup.select("script")
|
||||
matched_images_data = "".join(
|
||||
re.findall(r"AF_initDataCallback\(([^<]+)\);", str(all_script_tags))
|
||||
)
|
||||
matched_images_data_fix = json.dumps(matched_images_data)
|
||||
matched_images_data_json = json.loads(matched_images_data_fix)
|
||||
matched_google_image_data = re.findall(
|
||||
r"\"b-GRID_STATE0\"(.*)sideChannel:\s?{}}", matched_images_data_json
|
||||
)
|
||||
matched_google_images_thumbnails = ", ".join(
|
||||
re.findall(
|
||||
r"\[\"(https\:\/\/encrypted-tbn0\.gstatic\.com\/images\?.*?)\",\d+,\d+\]",
|
||||
str(matched_google_image_data),
|
||||
)
|
||||
).split(", ")
|
||||
thumbnails = [
|
||||
bytes(bytes(thumbnail, "ascii").decode("unicode-escape"), "ascii").decode(
|
||||
"unicode-escape"
|
||||
)
|
||||
for thumbnail in matched_google_images_thumbnails
|
||||
]
|
||||
removed_matched_google_images_thumbnails = re.sub(
|
||||
r"\[\"(https\:\/\/encrypted-tbn0\.gstatic\.com\/images\?.*?)\",\d+,\d+\]",
|
||||
"",
|
||||
str(matched_google_image_data),
|
||||
)
|
||||
matched_google_full_resolution_images = re.findall(
|
||||
r"(?:'|,),\[\"(https:|http.*?)\",\d+,\d+\]",
|
||||
removed_matched_google_images_thumbnails,
|
||||
)
|
||||
full_res_images = [
|
||||
bytes(bytes(img, "ascii").decode("unicode-escape"), "ascii").decode(
|
||||
"unicode-escape"
|
||||
)
|
||||
for img in matched_google_full_resolution_images
|
||||
]
|
||||
for index, (metadata, thumbnail, original) in enumerate(
|
||||
zip(soup.select(".isv-r.PNCib.MSM1fd.BUooTd"), thumbnails, full_res_images),
|
||||
start=1,
|
||||
):
|
||||
google_images.append(
|
||||
"""Get image results from Google Custom Search API.
|
||||
|
||||
Args:
|
||||
query (str): Search query string
|
||||
|
||||
Returns:
|
||||
list: List of dicts containing image info (title, link, source, thumbnail, original)
|
||||
"""
|
||||
LOGS.info(f"Searching Google Images for: {query}")
|
||||
|
||||
# Google Custom Search API credentials
|
||||
google_keys = [
|
||||
{
|
||||
"title": metadata.select_one(".VFACy.kGQAp.sMi44c.lNHeqe.WGvvNb")[
|
||||
"title"
|
||||
],
|
||||
"link": metadata.select_one(".VFACy.kGQAp.sMi44c.lNHeqe.WGvvNb")[
|
||||
"href"
|
||||
],
|
||||
"source": metadata.select_one(".fxgdke").text,
|
||||
"thumbnail": thumbnail,
|
||||
"original": original,
|
||||
"key": "AIzaSyAj75v6vHWLJdJaYcj44tLz7bdsrh2g7Y0",
|
||||
"cx": "712a54749d99a449e"
|
||||
},
|
||||
{
|
||||
"key": "AIzaSyDFQQwPLCzcJ9FDao-B7zDusBxk8GoZ0HY",
|
||||
"cx": "001bbd139705f44a6"
|
||||
},
|
||||
{
|
||||
"key": "AIzaSyD0sRNZUa8-0kq9LAREDAFKLNO1HPmikRU",
|
||||
"cx": "4717c609c54e24250"
|
||||
}
|
||||
]
|
||||
key_index = random.randint(0, len(google_keys) - 1)
|
||||
GOOGLE_API_KEY = google_keys[key_index]["key"]
|
||||
GOOGLE_CX = google_keys[key_index]["cx"]
|
||||
try:
|
||||
# Construct API URL
|
||||
url = (
|
||||
"https://www.googleapis.com/customsearch/v1"
|
||||
f"?q={quote(query)}"
|
||||
f"&cx={GOOGLE_CX}"
|
||||
f"&key={GOOGLE_API_KEY}"
|
||||
"&searchType=image"
|
||||
"&num=10" # Number of results
|
||||
)
|
||||
|
||||
# Make API request
|
||||
response = await async_searcher(url, re_json=True)
|
||||
print("response")
|
||||
if not response or "items" not in response:
|
||||
LOGS.error("No results from Google Custom Search API")
|
||||
return []
|
||||
|
||||
# Process results
|
||||
google_images = []
|
||||
for item in response["items"]:
|
||||
try:
|
||||
google_images.append({
|
||||
"title": item.get("title", ""),
|
||||
"link": item.get("contextLink", ""), # Page containing image
|
||||
"source": item.get("displayLink", ""),
|
||||
"thumbnail": item.get("image", {}).get("thumbnailLink", item["link"]),
|
||||
"original": item["link"] # Original image URL
|
||||
})
|
||||
except Exception as e:
|
||||
LOGS.warning(f"Failed to process image result: {str(e)}")
|
||||
continue
|
||||
|
||||
# Randomize results order
|
||||
random.shuffle(google_images)
|
||||
|
||||
LOGS.info(f"Found {len(google_images)} images for query: {query}")
|
||||
return google_images
|
||||
|
||||
except Exception as e:
|
||||
LOGS.exception(f"Error in get_google_images: {str(e)}")
|
||||
return []
|
||||
|
||||
|
||||
# Thanks https://t.me/ImSafone for ChatBotApi
|
||||
|
||||
@@ -672,7 +690,7 @@ async def get_file_link(msg):
|
||||
|
||||
|
||||
async def get_stored_file(event, hash):
|
||||
from .. import udB
|
||||
from .. import udB, asst
|
||||
|
||||
msg_id = get_stored_msg(hash)
|
||||
if not msg_id:
|
||||
@@ -689,38 +707,23 @@ async def get_stored_file(event, hash):
|
||||
await asst.send_message(event.chat_id, msg.text, file=msg.media, reply_to=event.id)
|
||||
|
||||
|
||||
def _package_rpc(text, lang_src="auto", lang_tgt="auto"):
|
||||
GOOGLE_TTS_RPC = ["MkEWBc"]
|
||||
parameter = [[text.strip(), lang_src, lang_tgt, True], [1]]
|
||||
escaped_parameter = json.dumps(parameter, separators=(",", ":"))
|
||||
rpc = [[[random.choice(GOOGLE_TTS_RPC), escaped_parameter, None, "generic"]]]
|
||||
espaced_rpc = json.dumps(rpc, separators=(",", ":"))
|
||||
freq = "f.req={}&".format(quote(espaced_rpc))
|
||||
return freq
|
||||
def translate(text, lang_tgt="en", lang_src="auto", timeout=60, detect=False):
|
||||
pattern = r'(?s)class="(?:t0|result-container)">(.*?)<'
|
||||
escaped_text = quote(text.encode("utf8"))
|
||||
url = "https://translate.google.com/m?tl=%s&sl=%s&q=%s" % (
|
||||
lang_tgt,
|
||||
lang_src,
|
||||
escaped_text,
|
||||
)
|
||||
response = requests.get(url, timeout=timeout).content
|
||||
result = response.decode("utf8")
|
||||
result = re.findall(pattern, result)
|
||||
if not result:
|
||||
return ""
|
||||
text = html.unescape(result[0])
|
||||
return (text, None) if detect else text
|
||||
|
||||
|
||||
def translate(*args, **kwargs):
|
||||
headers = {
|
||||
"Referer": "https://translate.google.co.in",
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) "
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
||||
"Chrome/47.0.2526.106 Safari/537.36",
|
||||
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
|
||||
}
|
||||
x = requests.post(
|
||||
"https://translate.google.co.in/_/TranslateWebserverUi/data/batchexecute",
|
||||
headers=headers,
|
||||
data=_package_rpc(*args, **kwargs),
|
||||
).text
|
||||
response = ""
|
||||
data = json.loads(json.loads(x[4:])[0][2])[1][0][0]
|
||||
subind = data[-2]
|
||||
if not subind:
|
||||
subind = data[-1]
|
||||
for i in subind:
|
||||
response += i[0]
|
||||
return response
|
||||
|
||||
|
||||
def cmd_regex_replace(cmd):
|
||||
return (
|
||||
@@ -751,31 +754,59 @@ class TgConverter:
|
||||
@staticmethod
|
||||
async def animated_sticker(file, out_path="sticker.tgs", throw=False, remove=False):
|
||||
"""Convert to/from animated sticker."""
|
||||
LOGS.info(f"Converting animated sticker: {file} -> {out_path}")
|
||||
try:
|
||||
if out_path.endswith("webp"):
|
||||
er, out = await bash(
|
||||
f"lottie_convert.py --webp-quality 100 --webp-skip-frames 100 '{file}' '{out_path}'"
|
||||
)
|
||||
else:
|
||||
er, out = await bash(f"lottie_convert.py '{file}' '{out_path}'")
|
||||
if er and throw:
|
||||
|
||||
if er:
|
||||
LOGS.error(f"Error in animated_sticker conversion: {er}")
|
||||
if throw:
|
||||
raise LottieException(er)
|
||||
if remove:
|
||||
if remove and os.path.exists(file):
|
||||
os.remove(file)
|
||||
LOGS.info(f"Removed original file: {file}")
|
||||
if os.path.exists(out_path):
|
||||
LOGS.info(f"Successfully converted to {out_path}")
|
||||
return out_path
|
||||
LOGS.error(f"Output file not created: {out_path}")
|
||||
return None
|
||||
except Exception as e:
|
||||
LOGS.exception(f"Unexpected error in animated_sticker: {str(e)}")
|
||||
if throw:
|
||||
raise
|
||||
|
||||
@staticmethod
|
||||
async def animated_to_gif(file, out_path="gif.gif"):
|
||||
"""Convert animated sticker to gif."""
|
||||
await bash(
|
||||
LOGS.info(f"Converting to gif: {file} -> {out_path}")
|
||||
try:
|
||||
er, out = await bash(
|
||||
f"lottie_convert.py '{_unquote_text(file)}' '{_unquote_text(out_path)}'"
|
||||
)
|
||||
if er:
|
||||
LOGS.error(f"Error in animated_to_gif conversion: {er}")
|
||||
if os.path.exists(out_path):
|
||||
LOGS.info("Successfully converted to gif")
|
||||
return out_path
|
||||
LOGS.error("Gif conversion failed - output file not created")
|
||||
return None
|
||||
except Exception as e:
|
||||
LOGS.exception(f"Unexpected error in animated_to_gif: {str(e)}")
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def resize_photo_sticker(photo):
|
||||
"""Resize the given photo to 512x512 (for creating telegram sticker)."""
|
||||
LOGS.info(f"Resizing photo for sticker: {photo}")
|
||||
try:
|
||||
image = Image.open(photo)
|
||||
original_size = (image.width, image.height)
|
||||
|
||||
if (image.width and image.height) < 512:
|
||||
size1 = image.width
|
||||
size2 = image.height
|
||||
@@ -794,7 +825,12 @@ class TgConverter:
|
||||
else:
|
||||
maxsize = (512, 512)
|
||||
image.thumbnail(maxsize)
|
||||
|
||||
LOGS.info(f"Resized image from {original_size} to {image.size}")
|
||||
return image
|
||||
except Exception as e:
|
||||
LOGS.exception(f"Error in resize_photo_sticker: {str(e)}")
|
||||
raise
|
||||
|
||||
@staticmethod
|
||||
async def ffmpeg_convert(input_, output, remove=False):
|
||||
@@ -803,9 +839,11 @@ class TgConverter:
|
||||
input_, name=output[:-5], remove=remove
|
||||
)
|
||||
if output.endswith(".gif"):
|
||||
await bash(f"ffmpeg -i '{input_}' -an -sn -c:v copy '{output}.mp4' -y")
|
||||
out, er = await bash(f"ffmpeg -i '{input_}' -an -sn -c:v copy '{output}.mp4' -y")
|
||||
LOGS.info(f"FFmpeg output: {out}, Error: {er}")
|
||||
else:
|
||||
await bash(f"ffmpeg -i '{input_}' '{output}' -y")
|
||||
out, er = await bash(f"ffmpeg -i '{input_}' '{output}' -y")
|
||||
LOGS.info(f"FFmpeg output: {out}, Error: {er}")
|
||||
if remove:
|
||||
os.remove(input_)
|
||||
if os.path.exists(output):
|
||||
@@ -813,9 +851,12 @@ class TgConverter:
|
||||
|
||||
@staticmethod
|
||||
async def create_webm(file, name="video", remove=False):
|
||||
LOGS.info(f"Creating webm: {file} -> {name}.webm")
|
||||
try:
|
||||
_ = await metadata(file)
|
||||
name += ".webm"
|
||||
h, w = _["height"], _["width"]
|
||||
|
||||
if h == w and h != 512:
|
||||
h, w = 512, 512
|
||||
if h != 512 or w != 512:
|
||||
@@ -823,26 +864,68 @@ class TgConverter:
|
||||
h, w = 512, -1
|
||||
if w > h:
|
||||
h, w = -1, 512
|
||||
|
||||
await bash(
|
||||
f'ffmpeg -i "{file}" -preset fast -an -to 00:00:03 -crf 30 -bufsize 256k -b:v {_["bitrate"]} -vf "scale={w}:{h},fps=30" -c:v libvpx-vp9 "{name}" -y'
|
||||
)
|
||||
if remove:
|
||||
|
||||
if remove and os.path.exists(file):
|
||||
os.remove(file)
|
||||
LOGS.info(f"Removed original file: {file}")
|
||||
|
||||
if os.path.exists(name):
|
||||
LOGS.info(f"Successfully created webm: {name}")
|
||||
return name
|
||||
|
||||
LOGS.error(f"Webm creation failed - output file not created: {name}")
|
||||
return None
|
||||
except Exception as e:
|
||||
LOGS.exception(f"Error in create_webm: {str(e)}")
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def to_image(input_, name, remove=False):
|
||||
"""Convert video/gif to image using first frame."""
|
||||
LOGS.info(f"Converting to image: {input_} -> {name}")
|
||||
try:
|
||||
if not input_:
|
||||
LOGS.error("Input file is None")
|
||||
return None
|
||||
|
||||
if not os.path.exists(input_):
|
||||
LOGS.error(f"Input file does not exist: {input_}")
|
||||
return None
|
||||
|
||||
try:
|
||||
import cv2
|
||||
except ImportError:
|
||||
raise DependencyMissingError("This function needs 'cv2' to be installed.")
|
||||
|
||||
img = cv2.VideoCapture(input_)
|
||||
ult, roid = img.read()
|
||||
cv2.imwrite(name, roid)
|
||||
if remove:
|
||||
success, frame = img.read()
|
||||
|
||||
if not success:
|
||||
LOGS.error(f"Failed to read frame from {input_}")
|
||||
return None
|
||||
|
||||
cv2.imwrite(name, frame)
|
||||
img.release()
|
||||
|
||||
if not os.path.exists(name):
|
||||
LOGS.error(f"Failed to save image: {name}")
|
||||
return None
|
||||
|
||||
if remove and os.path.exists(input_):
|
||||
os.remove(input_)
|
||||
LOGS.info(f"Removed original file: {input_}")
|
||||
|
||||
LOGS.info(f"Successfully converted to image: {name}")
|
||||
return name
|
||||
|
||||
except Exception as e:
|
||||
LOGS.exception(f"Error in to_image conversion: {str(e)}")
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
async def convert(
|
||||
input_file,
|
||||
@@ -851,9 +934,21 @@ class TgConverter:
|
||||
allowed_formats=[],
|
||||
remove_old=True,
|
||||
):
|
||||
"""Convert between different file formats."""
|
||||
LOGS.info(f"Converting {input_file} to {convert_to or allowed_formats}")
|
||||
|
||||
if not input_file:
|
||||
LOGS.error("Input file is None")
|
||||
return None
|
||||
|
||||
if not os.path.exists(input_file):
|
||||
LOGS.error(f"Input file does not exist: {input_file}")
|
||||
return None
|
||||
|
||||
if "." in input_file:
|
||||
ext = input_file.split(".")[-1].lower()
|
||||
else:
|
||||
LOGS.error("Input file has no extension")
|
||||
return input_file
|
||||
|
||||
if (
|
||||
@@ -866,19 +961,24 @@ class TgConverter:
|
||||
def recycle_type(exte):
|
||||
return convert_to == exte or exte in allowed_formats
|
||||
|
||||
try:
|
||||
# Sticker to Something
|
||||
if ext == "tgs":
|
||||
for extn in ["webp", "json", "png", "mp4", "gif"]:
|
||||
if recycle_type(extn):
|
||||
name = outname + "." + extn
|
||||
return await TgConverter.animated_sticker(
|
||||
result = await TgConverter.animated_sticker(
|
||||
input_file, name, remove=remove_old
|
||||
)
|
||||
if result:
|
||||
return result
|
||||
if recycle_type("webm"):
|
||||
input_file = await TgConverter.convert(
|
||||
gif_file = await TgConverter.convert(
|
||||
input_file, convert_to="gif", remove_old=remove_old
|
||||
)
|
||||
return await TgConverter.create_webm(input_file, outname, remove=True)
|
||||
if gif_file:
|
||||
return await TgConverter.create_webm(gif_file, outname, remove=True)
|
||||
|
||||
# Json -> Tgs
|
||||
elif ext == "json":
|
||||
if recycle_type("tgs"):
|
||||
@@ -886,40 +986,65 @@ class TgConverter:
|
||||
return await TgConverter.animated_sticker(
|
||||
input_file, name, remove=remove_old
|
||||
)
|
||||
|
||||
# Video to Something
|
||||
elif ext in ["webm", "mp4", "gif"]:
|
||||
for exte in ["webm", "mp4", "gif"]:
|
||||
if recycle_type(exte):
|
||||
name = outname + "." + exte
|
||||
return await TgConverter.ffmpeg_convert(
|
||||
result = await TgConverter.ffmpeg_convert(
|
||||
input_file, name, remove=remove_old
|
||||
)
|
||||
if result:
|
||||
return result
|
||||
|
||||
for exte in ["png", "jpg", "jpeg", "webp"]:
|
||||
if recycle_type(exte):
|
||||
name = outname + "." + exte
|
||||
return TgConverter.to_image(input_file, name, remove=remove_old)
|
||||
result = TgConverter.to_image(input_file, name, remove=remove_old)
|
||||
if result:
|
||||
return result
|
||||
|
||||
# Image to Something
|
||||
elif ext in ["jpg", "jpeg", "png", "webp"]:
|
||||
for extn in ["png", "webp", "ico"]:
|
||||
if recycle_type(extn):
|
||||
try:
|
||||
img = Image.open(input_file)
|
||||
name = outname + "." + extn
|
||||
img.save(name, extn.upper())
|
||||
if remove_old:
|
||||
if remove_old and os.path.exists(input_file):
|
||||
os.remove(input_file)
|
||||
LOGS.info(f"Removed original file: {input_file}")
|
||||
return name
|
||||
except Exception as e:
|
||||
LOGS.error(f"Failed to convert image to {extn}: {str(e)}")
|
||||
continue
|
||||
|
||||
for extn in ["webm", "gif", "mp4"]:
|
||||
if recycle_type(extn):
|
||||
name = outname + "." + extn
|
||||
if extn == "webm":
|
||||
input_file = await TgConverter.convert(
|
||||
png_file = await TgConverter.convert(
|
||||
input_file,
|
||||
convert_to="png",
|
||||
remove_old=remove_old,
|
||||
)
|
||||
if png_file:
|
||||
return await TgConverter.ffmpeg_convert(
|
||||
input_file, name, remove=True if extn == "webm" else remove_old
|
||||
png_file, name, remove=True
|
||||
)
|
||||
else:
|
||||
return await TgConverter.ffmpeg_convert(
|
||||
input_file, name, remove=remove_old
|
||||
)
|
||||
|
||||
LOGS.error(f"No valid conversion found for {input_file} to {convert_to or allowed_formats}")
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
LOGS.exception(f"Error in convert: {str(e)}")
|
||||
return None
|
||||
|
||||
|
||||
def _get_value(stri):
|
||||
|
||||
@@ -128,6 +128,7 @@ class UltroidClient(TelegramClient):
|
||||
with contextlib.suppress(FileNotFoundError):
|
||||
os.remove(file)
|
||||
return files["raw_file"], time.time() - start_time
|
||||
|
||||
from pyUltroid.fns.FastTelethon import upload_file
|
||||
from pyUltroid.fns.helper import progress
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
__version__ = "2025.02.19"
|
||||
ultroid_version = "2.0"
|
||||
__version__ = "2025.02.23"
|
||||
ultroid_version = "2.1"
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
# Important Requirements here.
|
||||
telethon
|
||||
# https://github.com/TeamUltroid/Telethon/archive/ultroid.zip
|
||||
https://github.com/New-dev0/Telethon-Patch/archive/main.zip
|
||||
python-decouple
|
||||
python-dotenv
|
||||
telegraph
|
||||
enhancer
|
||||
requests
|
||||
aiohttp
|
||||
catbox-uploader
|
||||
cloudscraper
|
||||
@@ -76,6 +76,7 @@ def start():
|
||||
print("\nCongrats. All done!\nTime to start the bot!")
|
||||
print("\nInstalling requirements... This might take a while...")
|
||||
os.system("pip3 install --no-cache-dir -r requirements.txt")
|
||||
os.system("pip3 install -r requirements.txt --break-system-packages")
|
||||
ask = input(
|
||||
"Enter 'yes/y' to Install other requirements, required for local deployment."
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Required only for Local Deploys
|
||||
# ------------------------------------------------------ #
|
||||
|
||||
git+https://github.com/ufoptg/akipy.git
|
||||
akipy
|
||||
apscheduler
|
||||
aiohttp
|
||||
bs4
|
||||
|
||||
Reference in New Issue
Block a user