2023-10-16 09:46:31 -04:00
|
|
|
import io
|
|
|
|
|
2020-05-10 22:59:51 -04:00
|
|
|
from PIL import Image, ImageOps
|
2023-10-16 09:46:31 -04:00
|
|
|
|
2020-09-13 13:50:36 -04:00
|
|
|
from ubot import ldr
|
2023-10-16 09:46:31 -04:00
|
|
|
|
|
|
|
|
2020-05-02 17:04:27 -04:00
|
|
|
@ldr.add("chatid")
|
2023-10-16 09:46:31 -04:00
|
|
|
async def chatidgetter(event):
|
|
|
|
if event.is_reply:
|
|
|
|
reply = await event.get_reply_message()
|
|
|
|
if reply.forward and reply.forward.channel_id:
|
2020-06-06 11:04:14 -04:00
|
|
|
await event.reply(f"**Channel ID:** {reply.forward.channel_id}")
|
2023-10-16 09:46:31 -04:00
|
|
|
return
|
|
|
|
chat_id = reply.chat_id
|
|
|
|
else:
|
|
|
|
chat_id = event.chat_id
|
|
|
|
|
2020-06-06 11:04:14 -04:00
|
|
|
await event.reply(f"**Chat ID:** {chat_id}")
|
2023-10-16 09:46:31 -04:00
|
|
|
|
|
|
|
|
2020-05-02 17:04:27 -04:00
|
|
|
@ldr.add("userid")
|
2023-10-16 09:46:31 -04:00
|
|
|
async def useridgetter(event):
|
|
|
|
if event.is_reply:
|
|
|
|
reply = await event.get_reply_message()
|
2020-10-03 11:27:11 -04:00
|
|
|
user_id = reply.sender_id
|
2023-10-16 09:46:31 -04:00
|
|
|
else:
|
2020-10-03 11:27:11 -04:00
|
|
|
user_id = event.sender_id
|
2023-10-16 09:46:31 -04:00
|
|
|
|
2020-06-06 11:04:14 -04:00
|
|
|
await event.reply(f"**User ID:** {user_id}")
|
2023-10-16 09:46:31 -04:00
|
|
|
|
|
|
|
|
2020-07-21 09:44:28 -04:00
|
|
|
@ldr.add("stickpng", help="Converts stickers to PNG files.")
|
2023-10-16 09:46:31 -04:00
|
|
|
async def stickertopng(event):
|
2021-02-13 12:06:21 -05:00
|
|
|
sticker = await event.get_sticker()
|
2023-10-16 09:46:31 -04:00
|
|
|
|
2021-02-13 12:06:21 -05:00
|
|
|
if not sticker:
|
2020-06-06 11:04:14 -04:00
|
|
|
await event.reply("Reply to a sticker to get it as a PNG file!")
|
2023-10-16 09:46:31 -04:00
|
|
|
return
|
|
|
|
|
|
|
|
sticker_webp_io = io.BytesIO()
|
2021-02-13 12:06:21 -05:00
|
|
|
await event.client.download_media(sticker, sticker_webp_io)
|
2020-12-04 21:03:55 -05:00
|
|
|
await event.reply(file=await ldr.run_async(stickertopngsync, sticker_webp_io), force_document=True)
|
|
|
|
|
|
|
|
|
|
|
|
def stickertopngsync(sticker_webp_io):
|
2023-10-16 09:46:31 -04:00
|
|
|
sticker_webp = Image.open(sticker_webp_io)
|
|
|
|
sticker_png_io = io.BytesIO()
|
|
|
|
sticker_webp.save(sticker_png_io, "PNG")
|
|
|
|
sticker_png_io.name = "sticker.png"
|
|
|
|
sticker_png_io.seek(0)
|
|
|
|
|
2020-12-04 21:03:55 -05:00
|
|
|
return sticker_png_io
|
2020-05-10 22:59:51 -04:00
|
|
|
|
|
|
|
|
2020-07-21 09:44:28 -04:00
|
|
|
@ldr.add("stickflip", help="Flips stickers horizontally.")
|
2020-05-10 22:59:51 -04:00
|
|
|
async def flipsticker(event):
|
2021-02-13 12:06:21 -05:00
|
|
|
sticker = await event.get_sticker()
|
2020-05-10 22:59:51 -04:00
|
|
|
|
2021-02-13 12:06:21 -05:00
|
|
|
if not sticker:
|
2020-06-06 11:04:14 -04:00
|
|
|
await event.reply("Reply to a sticker to flip that bitch!")
|
2020-05-10 22:59:51 -04:00
|
|
|
return
|
|
|
|
|
|
|
|
sticker_webp_io = io.BytesIO()
|
2021-02-13 12:06:21 -05:00
|
|
|
await event.client.download_media(sticker, sticker_webp_io)
|
2020-12-04 21:03:55 -05:00
|
|
|
await event.reply(file=await ldr.run_async(flipstickersync, sticker_webp_io))
|
|
|
|
|
|
|
|
|
|
|
|
def flipstickersync(sticker_webp_io):
|
2020-05-10 22:59:51 -04:00
|
|
|
sticker_webp = Image.open(sticker_webp_io)
|
|
|
|
sticker_webp = ImageOps.mirror(sticker_webp)
|
|
|
|
sticker_flipped_io = io.BytesIO()
|
|
|
|
sticker_webp.save(sticker_flipped_io, "WebP")
|
|
|
|
sticker_flipped_io.name = "sticker.webp"
|
|
|
|
sticker_flipped_io.seek(0)
|
|
|
|
|
2020-12-04 21:03:55 -05:00
|
|
|
return sticker_flipped_io
|
2020-05-11 10:47:09 -04:00
|
|
|
|
|
|
|
|
2020-07-21 09:44:28 -04:00
|
|
|
@ldr.add("stickimg", help="Converts images to sticker sized PNG files.")
|
2020-05-11 10:47:09 -04:00
|
|
|
async def createsticker(event):
|
2021-02-13 12:06:21 -05:00
|
|
|
data = await event.get_image()
|
2020-05-11 10:47:09 -04:00
|
|
|
|
2021-02-13 12:06:21 -05:00
|
|
|
if not data:
|
|
|
|
await event.reply("Reply to or caption an image to make it sticker-sized!")
|
|
|
|
return
|
2020-05-11 10:47:09 -04:00
|
|
|
|
|
|
|
image_io = io.BytesIO()
|
|
|
|
await event.client.download_media(data, image_io)
|
2020-12-04 21:03:55 -05:00
|
|
|
await event.reply(file=await ldr.run_async(createstickersync, image_io), force_document=True)
|
|
|
|
|
|
|
|
|
|
|
|
def createstickersync(image_io):
|
2020-05-11 10:47:09 -04:00
|
|
|
sticker_png = Image.open(image_io)
|
|
|
|
sticker_png = sticker_png.crop(sticker_png.getbbox())
|
|
|
|
|
|
|
|
final_width = 512
|
|
|
|
final_height = 512
|
|
|
|
|
|
|
|
if sticker_png.width > sticker_png.height:
|
|
|
|
final_height = 512 * (sticker_png.height / sticker_png.width)
|
|
|
|
elif sticker_png.width < sticker_png.height:
|
|
|
|
final_width = 512 * (sticker_png.width / sticker_png.height)
|
|
|
|
|
|
|
|
sticker_png = ImageOps.fit(sticker_png, (int(final_width), int(final_height)))
|
|
|
|
sticker_new_io = io.BytesIO()
|
|
|
|
sticker_png.save(sticker_new_io, "PNG")
|
|
|
|
sticker_new_io.name = "sticker.png"
|
|
|
|
sticker_new_io.seek(0)
|
|
|
|
|
2020-12-04 21:03:55 -05:00
|
|
|
return sticker_new_io
|