flash / Mikobot /plugins /newuserinfo.py
Karma
Add files via upload
056f521
raw
history blame
5.61 kB
import os
import unidecode
from PIL import Image, ImageChops, ImageDraw, ImageFont
from pyrogram import filters
from pyrogram.enums import ParseMode
from Mikobot import DEMONS, DEV_USERS, DRAGONS, OWNER_ID, TIGERS, WOLVES, app
async def circle(pfp, size=(900, 900)):
pfp = pfp.resize(size, Image.ANTIALIAS).convert("RGBA")
bigsize = (pfp.size[0] * 3, pfp.size[1] * 3)
mask = Image.new("L", bigsize, 0)
draw = ImageDraw.Draw(mask)
draw.ellipse((0, 0) + bigsize, fill=255)
mask = mask.resize(pfp.size, Image.ANTIALIAS)
mask = ImageChops.darker(mask, pfp.split()[-1])
pfp.putalpha(mask)
return pfp
async def download_and_process_pfp(user):
try:
pic = await app.download_media(
user.photo.big_file_id, file_name=f"pp{user.id}.png"
)
if pic:
pfp = Image.open(pic).convert("RGBA")
return await circle(pfp, size=(900, 900))
except Exception as e:
print(e)
finally:
if "pic" in locals() and pic:
os.remove(pic)
return None
async def userinfopic(
user,
user_x,
user_y,
user_id_x,
user_id_y,
pfp_x_offset=0,
pfp_y_offset=0,
pfp_size=(1218, 1385),
):
user_name = unidecode.unidecode(user.first_name)
# Load the background image
background = Image.open("Extra/user.jpg")
background = background.resize(
(background.size[0], background.size[1]), Image.ANTIALIAS
)
draw = ImageDraw.Draw(background)
font = ImageFont.truetype("Extra/default.ttf", 100)
try:
pfp = await download_and_process_pfp(user)
if pfp:
# Adjust pfp_x and pfp_y with the offsets
pfp_x = 927 + pfp_x_offset
pfp_y = (background.size[1] - pfp.size[1]) // 2 - 290 + pfp_y_offset
# Increase the size of the pfp circle
pfp = await circle(pfp, size=pfp_size)
background.paste(pfp, (pfp_x, pfp_y), pfp)
user_text_width, user_text_height = draw.textsize(user_name, font=font)
user_id_text_width, user_id_text_height = draw.textsize(str(user.id), font=font)
draw.text((user_x, user_y), user_name, font=font, fill="white")
draw.text((user_id_x, user_id_y), str(user.id), font=font, fill="white")
userinfo = f"downloads/userinfo_{user.id}.png"
background.save(userinfo)
except Exception as e:
print(e)
userinfo = None
return userinfo
# Command handler for /userinfo
@app.on_message(filters.command("uinfo"))
async def userinfo_command(client, message):
user = message.from_user
user_x, user_y = 1035, 2885
user_id_x, user_id_y = 1035, 2755
try:
# Send a message indicating that user information is being processed
processing_message = await message.reply("Processing user information...")
# Generate user info image
image_path = await userinfopic(user, user_x, user_y, user_id_x, user_id_y)
# Delete the processing message
await processing_message.delete()
if image_path:
# Initialize the caption with basic information
caption = (
f"ใ€Œ **According to the Mikos analogy, the userinfo is...** : ใ€\n\n"
f"โ ๐—œ๐——: {user.id}\n"
f"โ ๐—™๐—ถ๐—ฟ๐˜€๐˜ ๐—ก๐—ฎ๐—บ๐—ฒ: {user.first_name}\n"
f"โ ๐—Ÿ๐—ฎ๐˜€๐˜ ๐—ก๐—ฎ๐—บ๐—ฒ: {user.last_name}\n"
f"โ ๐—จ๐˜€๐—ฒ๐—ฟ๐—ป๐—ฎ๐—บ๐—ฒ: {user.username}\n"
f"โ ๐—จ๐˜€๐—ฒ๐—ฟ๐—น๐—ถ๐—ป๐—ธ: [link](https://t.me/{user.username})\n"
)
# Check if the user's ID matches one of the predefined ranks
if user.id == OWNER_ID:
caption += "\n\nใ€„ The disaster level of this user is **Owner**.\n"
elif user.id in DEV_USERS:
caption += "\n\nใ€„ This user is a member of **Developer**.\n"
elif user.id in DRAGONS:
caption += "\n\nใ€„ The disaster level of this user is **Sudo**.\n"
elif user.id in DEMONS:
caption += "\n\nใ€„ The disaster level of this user is **Demon**.\n"
elif user.id in TIGERS:
caption += "\n\nใ€„ The disaster level of this user is **Tiger**.\n"
elif user.id in WOLVES:
caption += "\n\nใ€„ The disaster level of this user is **Wolf**.\n"
# Add the RANK line only if the user's ID matches one of the predefined ranks
if (
user.id == OWNER_ID
or user.id in DEV_USERS
or user.id in DRAGONS
or user.id in DEMONS
or user.id in TIGERS
or user.id in WOLVES
):
caption += "\n\nใ€„ ๐—ฅ๐—ฎ๐—ป๐—ธ: "
if user.id == OWNER_ID:
caption += "**CREATOR**"
elif user.id in DEV_USERS:
caption += "**DEVELOPER**"
elif user.id in DRAGONS:
caption += "**DRAGON**"
elif user.id in DEMONS:
caption += "**DEMON**"
elif user.id in TIGERS:
caption += "**TIGER**"
elif user.id in WOLVES:
caption += "**WOLF**"
caption += "\n"
await message.reply_photo(
photo=image_path, caption=caption, parse_mode=ParseMode.MARKDOWN
)
os.remove(image_path)
except Exception as e:
print(e)