azils3/bash
0
1# Ultroid - UserBot2# Copyright (C) 2021-2025 TeamUltroid3#4# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >5# PLease read the GNU Affero General Public License in6# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.7"""8✘ Commands Available -9 10• `{i}border <reply to photo/sticker>`11 To create border around that media..12 Ex - `{i}border 12,22,23`13 - `{i}border 12,22,23 ; width (in number)`14 15• `{i}grey <reply to any media>`16 To make it black nd white.17 18• `{i}color <reply to any Black nd White media>`19 To make it Colorfull.20 21• `{i}toon <reply to any media>`22 To make it toon.23 24• `{i}danger <reply to any media>`25 To make it look Danger.26 27• `{i}negative <reply to any media>`28 To make negative image.29 30• `{i}blur <reply to any media>`31 To make it blurry.32 33• `{i}quad <reply to any media>`34 create a Vortex.35 36• `{i}mirror <reply to any media>`37 To create mirror pic.38 39• `{i}flip <reply to any media>`40 To make it flip.41 42• `{i}sketch <reply to any media>`43 To draw its sketch.44 45• `{i}blue <reply to any media>`46 just cool.47 48• `{i}csample <color name /color code>`49 example : `{i}csample red`50 `{i}csample #ffffff`51 52• `{i}pixelator <reply image>`53 Create a Pixelated Image..54"""55import os56 57from . import LOGS, con58 59try:60 import cv261except ImportError:62 LOGS.error(f"{__file__}: OpenCv not Installed.")63 64import numpy as np65 66try:67 from PIL import Image68except ImportError:69 Image = None70 LOGS.info(f"{__file__}: PIL not Installed.")71 72from . import upload_file as upf73from telethon.errors.rpcerrorlist import (74 ChatSendMediaForbiddenError,75 MessageDeleteForbiddenError,76)77 78from . import (79 Redis,80 async_searcher,81 download_file,82 get_string,83 requests,84 udB,85 ultroid_cmd,86)87 88 89@ultroid_cmd(pattern="color$")90async def _(event):91 reply = await event.get_reply_message()92 if not (reply and reply.media):93 return await event.eor("`Reply To a Black and White Image`")94 xx = await event.eor("`Coloring image 🎨🖌️...`")95 image = await reply.download_media()96 img = cv2.VideoCapture(image)97 ret, frame = img.read()98 cv2.imwrite("ult.jpg", frame)99 if udB.get_key("DEEP_API"):100 key = Redis("DEEP_API")101 else:102 key = "quickstart-QUdJIGlzIGNvbWluZy4uLi4K"103 r = requests.post(104 "https://api.deepai.org/api/colorizer",105 files={"image": open("ult.jpg", "rb")},106 headers={"api-key": key},107 )108 os.remove("ult.jpg")109 os.remove(image)110 if "status" in r.json():111 return await event.edit(112 r.json()["status"] + "\nGet api nd set `{i}setdb DEEP_API key`"113 )114 r_json = r.json()["output_url"]115 await event.client.send_file(event.chat_id, r_json, reply_to=reply)116 await xx.delete()117 118 119@ultroid_cmd(pattern="(grey|blur|negative|danger|mirror|quad|sketch|flip|toon)$")120async def ult_tools(event):121 match = event.pattern_match.group(1)122 ureply = await event.get_reply_message()123 if not (ureply and (ureply.media)):124 await event.eor(get_string("cvt_3"))125 return126 ultt = await ureply.download_media()127 xx = await event.eor(get_string("com_1"))128 if ultt.endswith(".tgs"):129 xx = await xx.edit(get_string("sts_9"))130 file = await con.convert(ultt, convert_to="png", outname="ult")131 ult = cv2.imread(file)132 if match == "grey":133 ultroid = cv2.cvtColor(ult, cv2.COLOR_BGR2GRAY)134 elif match == "blur":135 ultroid = cv2.GaussianBlur(ult, (35, 35), 0)136 elif match == "negative":137 ultroid = cv2.bitwise_not(ult)138 elif match == "danger":139 dan = cv2.cvtColor(ult, cv2.COLOR_BGR2RGB)140 ultroid = cv2.cvtColor(dan, cv2.COLOR_HSV2BGR)141 elif match == "mirror":142 ish = cv2.flip(ult, 1)143 ultroid = cv2.hconcat([ult, ish])144 elif match == "flip":145 trn = cv2.flip(ult, 1)146 ish = cv2.rotate(trn, cv2.ROTATE_180)147 ultroid = cv2.vconcat([ult, ish])148 elif match == "quad":149 ult = cv2.imread(file)150 roid = cv2.flip(ult, 1)151 mici = cv2.hconcat([ult, roid])152 fr = cv2.flip(mici, 1)153 trn = cv2.rotate(fr, cv2.ROTATE_180)154 ultroid = cv2.vconcat([mici, trn])155 elif match == "sketch":156 gray_image = cv2.cvtColor(ult, cv2.COLOR_BGR2GRAY)157 inverted_gray_image = 255 - gray_image158 blurred_img = cv2.GaussianBlur(inverted_gray_image, (21, 21), 0)159 inverted_blurred_img = 255 - blurred_img160 ultroid = cv2.divide(gray_image, inverted_blurred_img, scale=256.0)161 elif match == "toon":162 height, width, _ = ult.shape163 samples = np.zeros([height * width, 3], dtype=np.float32)164 count = 0165 for x in range(height):166 for y in range(width):167 samples[count] = ult[x][y]168 count += 1169 _, labels, centers = cv2.kmeans(170 samples,171 12,172 None,173 (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 10000, 0.0001),174 5,175 cv2.KMEANS_PP_CENTERS,176 )177 centers = np.uint8(centers)178 ish = centers[labels.flatten()]179 ultroid = ish.reshape(ult.shape)180 cv2.imwrite("ult.jpg", ultroid)181 await ureply.reply(182 file="ult.jpg",183 force_document=False,184 )185 await xx.delete()186 os.remove("ult.jpg")187 os.remove(file)188 189 190@ultroid_cmd(pattern="csample (.*)")191async def sampl(ult):192 if color := ult.pattern_match.group(1).strip():193 img = Image.new("RGB", (200, 100), f"{color}")194 img.save("csample.png")195 try:196 try:197 await ult.delete()198 await ult.respond(f"Colour Sample for `{color}` !", file="csample.png")199 except MessageDeleteForbiddenError:200 await ult.reply(f"Colour Sample for `{color}` !", file="csample.png")201 except ChatSendMediaForbiddenError:202 await ult.eor("Umm! Sending Media is disabled here!")203 204 else:205 await ult.eor("Wrong Color Name/Hex Code specified!")206 207 208@ultroid_cmd(209 pattern="blue$",210)211async def ultd(event):212 ureply = await event.get_reply_message()213 xx = await event.eor("`...`")214 if not (ureply and (ureply.media)):215 await xx.edit(get_string("cvt_3"))216 return217 ultt = await ureply.download_media()218 if ultt.endswith(".tgs"):219 await xx.edit(get_string("sts_9"))220 file = await con.convert(ultt, convert_to="png", outname="ult")221 lnk = upf(file)222 r = await async_searcher(223 f"https://nekobot.xyz/api/imagegen?type=blurpify&image={lnk}", re_json=True224 )225 ms = r.get("message")226 if not r["success"]:227 return await xx.edit(ms)228 await download_file(ms, "ult.png")229 img = Image.open("ult.png").convert("RGB")230 img.save("ult.webp", "webp")231 await event.client.send_file(232 event.chat_id,233 "ult.webp",234 force_document=False,235 reply_to=event.reply_to_msg_id,236 )237 await xx.delete()238 os.remove("ult.png")239 os.remove("ult.webp")240 os.remove(ultt)241 242 243@ultroid_cmd(pattern="border( (.*)|$)")244async def ok(event):245 hm = await event.get_reply_message()246 if not (hm and (hm.photo or hm.sticker)):247 return await event.eor("`Reply to Sticker or Photo..`")248 col = event.pattern_match.group(1).strip()249 wh = 20250 if not col:251 col = [255, 255, 255]252 else:253 try:254 if ";" in col:255 col_ = col.split(";", maxsplit=1)256 wh = int(col_[1])257 col = col_[0]258 col = [int(col) for col in col.split(",")[:2]]259 except ValueError:260 return await event.eor("`Not a Valid Input...`")261 okla = await hm.download_media()262 img1 = cv2.imread(okla)263 constant = cv2.copyMakeBorder(img1, wh, wh, wh, wh, cv2.BORDER_CONSTANT, value=col)264 cv2.imwrite("output.png", constant)265 await event.client.send_file(event.chat.id, "output.png")266 os.remove("output.png")267 os.remove(okla)268 await event.delete()269 270 271@ultroid_cmd(pattern="pixelator( (.*)|$)")272async def pixelator(event):273 reply_message = await event.get_reply_message()274 if not (reply_message and (reply_message.photo or reply_message.sticker)):275 return await event.eor("`Reply to a photo`")276 hw = 50277 try:278 hw = int(event.pattern_match.group(1).strip())279 except (ValueError, TypeError):280 pass281 msg = await event.eor(get_string("com_1"))282 image = await reply_message.download_media()283 input_ = cv2.imread(image)284 height, width = input_.shape[:2]285 w, h = (hw, hw)286 temp = cv2.resize(input_, (w, h), interpolation=cv2.INTER_LINEAR)287 output = cv2.resize(temp, (width, height), interpolation=cv2.INTER_NEAREST)288 cv2.imwrite("output.jpg", output)289 await msg.respond("• Pixelated by Ultroid", file="output.jpg")290 await msg.delete()291 os.remove("output.jpg")292 os.remove(image)293 