File size: 5,605 Bytes
056f521 |
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 |
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)
|