Untitled

 avatar
unknown
plain_text
4 years ago
2.4 kB
5
Indexable
import discord
from discord.ext import commands
from PIL import Image, ImageFont, ImageDraw
from io import BytesIO
import random
import sys


class Love(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.font = ImageFont.truetype('arial.ttf', 24)

    @commands.command()
    async def love(self, ctx, user1: discord.Member, user2: discord.Member):
        if user1 == user2:
            await ctx.send('user1 and user2 must be different')

        else:
            love_image = Image.open('imglove.jpg')
            asset = user1.avatar_url_as(size=128)
            asset2 = user2.avatar_url_as(size=128)
            data = BytesIO(await asset.read())
            data2 = BytesIO(await asset2.read())
            pfp = Image.open(data)
            pfp2 = Image.open(data2)
            pfp = pfp.resize((177, 177))
            pfp2 = pfp2.resize((177, 177))
            love_image.paste(pfp, (282, 264))
            love_image.paste(pfp2, (794, 264))
            draw = ImageDraw.Draw(love_image)
            text1 = f'{user1}'
            text2 = f'{user2}'
            acak = random.randint(1, 100)
            hasil1 = ''
            hasil2 = ''
            hasil3 = ''
            hasil4 = ''
            if acak == 100:
                hasil1 = f'{acak}%'
                hasil2 = 'Sempurna'

            elif acak <= 33:
                hasil1 = f'{acak}%'
                hasil2 = 'Maaf kamu kurang beruntung'

            elif acak > 33 and acak <= 50:
                hasil1 = f'{acak}%'
                hasil2 = 'lumayan cocok'

            elif acak > 50:
                hasil1 = f'{acak}%'
                hasil2 = 'cocok banget'
            draw.text((281, 468), text1, (0, 0, 0), font=self.font)
            draw.text((794, 466), text2, (0, 0, 0), font=self.font)
            draw.text((606, 329), hasil1, (0, 0, 0), font=self.font)
            draw.text((515, 358), hasil2, (0, 0, 0), font=self.font)
            with BytesIO() as buffer:
                love_image.save(buffer, 'profile.jpg')
                buffer.seek(0)
                try:
                    await ctx.send(file=discord.File('profile.jpg'))

                except Exception as e:
                    e = sys.exc_info()
                    print(e)


def setup(bot):
    bot.add_cog(Love(bot))
Editor is loading...