Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
2.9 kB
3
Indexable
from BotAmino import BotAmino, Parameters ,File
from PIL import Image, ImageDraw, ImageFont
import os
from easy_pil import Editor, Canvas, load_image, Font
import io
from zipfile import ZipFile
import requests 
import urllib.request
bg_name="name.png"
levels={"1":4, "2":5, "3":10, "4":24, "5":50, "6":100, "7":200, "8":500, "9":1000, "10":2000, "11":3000, "12":5000, "13":7000, "14":10000, "15":20000, "16":40000, "17":60000, "18":100000, "19":250000,"20":500000}
def convert(im):
    with io.BytesIO() as f:
        im.save(f, format='PNG')
        return f.getvalue()

def zipurl(url):
	resp = urllib.request.urlopen(url)
	zipf = ZipFile(io.BytesIO(resp.read()))
	inflist = zipf.infolist()
	for f in inflist:
	    if "frame" in str(f):
	    	#if str(f.filename) !="frame.webp":
		    ifile = zipf.open(f)
		    img = Image.open(ifile)
		    return img
	    		

def calPercent(x, y, integer = False):
   percent = x / y * 100
   
   if integer:
       return int(percent)
   return percent
 

@client.command('rank')
def cavas(data: Parameters):
        p=data.subClient.get_user_info(data.authorId)
        level=p.level
        final=levels[str(level+1)]
        rep=int(p.reputation)
        percentage=calPercent(rep,final)
        print(percentage)
        background = Editor(bg_name)
        profile =load_image(str(data.authorIcon))
        frame=data.subClient.get_user_info(data.authorId).avatarFrame

        profile = Editor(profile).resize((150, 150)).circle_image()
        

        poppins =ImageFont.truetype('ll.ttf', 70)
        poppins_small = Font(path="lr.ttf").poppins(size=30)
        
        square = Canvas((500, 500), "#06FFBF")
        square = Editor(square)
        square.rotate(30, expand=True)

        background.paste(square.image, (600, -250))
        background.paste(profile.image, (30, 30))
        if frame!=None:
        		url=frame["resourceUrl"]
        		img1=zipurl(url)
        		if img1 !=None:
	        		av2 = Editor(img1).resize((170, 170)).circle_image()
	        		background.paste(av2, (25, 25))
        
        background.rectangle((30, 220), width=650, height=40, fill="white", radius=20)
        background.bar(
            (30, 220),
            max_width=650,
            height=40,
            percentage=percentage,
            fill="#2596be",
            radius=20,
        )
        background.text((200, 40), str(data.author), font=poppins, color="white")

        background.rectangle((200, 100), width=350, height=2, fill="#17F3F6")
        background.text(
            (200, 130),
            f"Level :{level}"
            + f" Reputation :{rep}",
            font=poppins_small,
            color="white",
        )
        data.subClient.full_embed(message=f"{data.author}",chatId=data.chatId,image=background.image_bytes,link=f"ndc://user-profile/{data.authorId}")
        print("done")