File size: 6,158 Bytes
1f26706 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# Ultroid - UserBot
# Copyright (C) 2021-2025 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
"""
β Commands Available -
β’ `{i}saavn <search query>`
Download songs from Saavn.
β’ `{i}google <query>`
For doing google search.
β’ `{i}github <username>`
Get full information of the users github profile.
β’ `{i}img <query>`
`{i}img <query> ; <no of results>`
For doing Images search.
β’ `{i}reverse`
Reply an Image or sticker to find its sauce.
"""
import os
import requests
from bs4 import BeautifulSoup as bs
try:
from PIL import Image
except ImportError:
Image = None
try:
import cv2
except ImportError:
cv2 = None
from telethon.tl.types import DocumentAttributeAudio
from pyUltroid.fns.misc import google_search
from pyUltroid.fns.tools import get_google_images, saavn_search
from . import LOGS, async_searcher, con, eod, fast_download, get_string, ultroid_cmd
@ultroid_cmd(
pattern="github (.*)",
)
async def gitsearch(event):
usrname = event.pattern_match.group(1).strip()
if not usrname:
return await event.eor(get_string("srch_1"))
url = f"https://api.github.com/users/{usrname}"
ult = await async_searcher(url, re_json=True)
try:
uname = ult["login"]
uid = ult["id"]
upic = f"https://avatars.githubusercontent.com/u/{uid}"
ulink = ult["html_url"]
uacc = ult["name"]
ucomp = ult["company"]
ublog = ult["blog"]
ulocation = ult["location"]
ubio = ult["bio"]
urepos = ult["public_repos"]
ufollowers = ult["followers"]
ufollowing = ult["following"]
except BaseException:
return await event.eor(get_string("srch_2"))
fullusr = f"""
**[GITHUB]({ulink})**
**Name** - {uacc}
**UserName** - {uname}
**ID** - {uid}
**Company** - {ucomp}
**Blog** - {ublog}
**Location** - {ulocation}
**Bio** - {ubio}
**Repos** - {urepos}
**Followers** - {ufollowers}
**Following** - {ufollowing}
"""
await event.respond(fullusr, file=upic)
await event.delete()
@ultroid_cmd(
pattern="google( (.*)|$)",
manager=True,
)
async def google(event):
inp = event.pattern_match.group(1).strip()
if not inp:
return await eod(event, get_string("autopic_1"))
x = await event.eor(get_string("com_2"))
gs = await google_search(inp)
if not gs:
return await eod(x, get_string("autopic_2").format(inp))
out = ""
for res in gs:
text = res["title"]
url = res["link"]
des = res["description"]
out += f" ππ» [{text}]({url})\n`{des}`\n\n"
omk = f"**Google Search Query:**\n`{inp}`\n\n**Results:**\n{out}"
await x.eor(omk, link_preview=False)
@ultroid_cmd(pattern="img( (.*)|$)")
async def goimg(event):
query = event.pattern_match.group(1).strip()
if not query:
return await event.eor(get_string("autopic_1"))
nn = await event.eor(get_string("com_1"))
lmt = 5
if ";" in query:
try:
lmt = int(query.split(";")[1])
query = query.split(";")[0]
except BaseException:
pass
images = await get_google_images(query)
for img in images[:lmt]:
try:
await event.client.send_file(event.chat_id, file=img["original"])
except Exception as er:
LOGS.exception(er)
await nn.delete()
@ultroid_cmd(pattern="reverse$")
async def reverse(event):
reply = await event.get_reply_message()
if not reply:
return await event.eor("`Reply to an Image`")
ult = await event.eor(get_string("com_1"))
dl = await reply.download_media()
file = await con.convert(dl, convert_to="png")
img = Image.open(file)
x, y = img.size
files = {"encoded_image": (file, open(file, "rb"))}
grs = requests.post(
"https://www.google.com/searchbyimage/upload",
files=files,
allow_redirects=False,
)
loc = grs.headers.get("Location")
response = await async_searcher(
loc,
headers={
"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": "kb0PBd"})[0]
alls = div.find("a")
link = alls["href"]
text = alls.text
await ult.edit(f"`Dimension ~ {x} : {y}`\nSauce ~ [{text}](google.com{link})")
images = await get_google_images(text)
for z in images[:2]:
try:
await event.client.send_file(
event.chat_id,
file=z["original"],
caption="Similar Images Realted to Search",
)
except Exception as er:
LOGS.exception(er)
os.remove(file)
@ultroid_cmd(
pattern="saavn( (.*)|$)",
)
async def siesace(e):
song = e.pattern_match.group(1).strip()
if not song:
return await e.eor("`Give me Something to Search", time=5)
eve = await e.eor(f"`Searching for {song} on Saavn...`")
try:
data = (await saavn_search(song))[0]
except IndexError:
return await eve.eor(f"`{song} not found on saavn.`")
try:
title = data["title"]
url = data["url"]
img = data["image"]
duration = data["duration"]
performer = data["artists"]
except KeyError:
return await eve.eor("`Something went wrong.`")
song, _ = await fast_download(url, filename=f"{title}.m4a")
thumb, _ = await fast_download(img, filename=f"{title}.jpg")
song, _ = await e.client.fast_uploader(song, to_delete=True)
await eve.eor(
file=song,
text=f"`{title}`\n`From Saavn`",
attributes=[
DocumentAttributeAudio(
duration=int(duration),
title=title,
performer=performer,
)
],
supports_streaming=True,
thumb=thumb,
)
await eve.delete()
os.remove(thumb)
|