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}qrcode <text/reply to text>`11 `Makes qrcode of text`12 13• `{i}addqr <reply image> <text>`14 `Makes qr of text and add it to image.`15 16• `{i}qrdecode <reply to qrcode>`17 `It decodes the qrcode.`18"""19import os20 21from pyUltroid import ULTConfig22 23try:24 import cv225except ImportError:26 cv2 = None27 28import qrcode29from PIL import Image30from telethon.tl.types import MessageMediaDocument as doc31 32from . import check_filename, get_string, ultroid_bot, ultroid_cmd33 34 35@ultroid_cmd(pattern="qrcode( (.*)|$)")36async def cd(e):37 reply = await e.get_reply_message()38 msg = e.pattern_match.group(1).strip()39 if reply and reply.text:40 msg = reply.text41 elif not msg:42 return await e.eor("`Give Some Text or Reply", time=5)43 default, cimg = ULTConfig.thumb, None44 if reply and (reply.sticker or reply.photo):45 cimg = await reply.download_media()46 elif ultroid_bot.me.photo and not ultroid_bot.me.photo.has_video:47 cimg = (await e.client.get_profile_photos(ultroid_bot.uid, limit=1))[0]48 49 kk = await e.eor(get_string("com_1"))50 img = cimg or default51 ok = Image.open(img)52 logo = ok.resize((60, 60))53 cod = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H)54 cod.add_data(msg)55 cod.make()56 imgg = cod.make_image().convert("RGB")57 pstn = ((imgg.size[0] - logo.size[0]) // 2, (imgg.size[1] - logo.size[1]) // 2)58 imgg.paste(logo, pstn)59 newname = check_filename("qr.jpg")60 imgg.save(newname)61 await e.client.send_file(e.chat_id, newname, supports_streaming=True)62 await kk.delete()63 os.remove(newname)64 if cimg:65 os.remove(cimg)66 67 68@ultroid_cmd(pattern="addqr( (.*)|$)")69async def qrwater(e):70 msg = e.pattern_match.group(1).strip()71 r = await e.get_reply_message()72 dl = await e.client.download_media(73 r, thumb=-1 if isinstance(r.media, doc) else None74 )75 if not dl:76 return await e.eor("`Reply Any Media and Give Text`", time=5)77 kk = await e.eor(get_string("com_1"))78 img_bg = Image.open(dl)79 qr = qrcode.QRCode(box_size=5)80 qr.add_data(msg)81 qr.make()82 img_qr = qr.make_image()83 pos = (img_bg.size[0] - img_qr.size[0], img_bg.size[1] - img_qr.size[1])84 img_bg.paste(img_qr, pos)85 img_bg.save(dl)86 await e.client.send_file(e.chat_id, dl, supports_streaming=True)87 await kk.delete()88 os.remove(dl)89 90 91@ultroid_cmd(pattern="qrdecode$")92async def decod(e):93 r = await e.get_reply_message()94 if not (r and r.media):95 return await e.eor("`Reply to Qrcode Media`", time=5)96 kk = await e.eor(get_string("com_1"))97 dl = await e.client.download_media(98 r, thumb=-1 if isinstance(r.media, doc) else None99 )100 if not dl:101 return102 im = cv2.imread(dl)103 try:104 det = cv2.QRCodeDetector()105 tx, y, z = det.detectAndDecode(im)106 await kk.edit("**Decoded Text:\n\n**" + tx)107 except BaseException:108 await kk.edit("`Reply To Media in Which Qr image present.`")109 os.remove(dl)110 