Esempio n. 1
0
    async def setborder(self, ctx, url: str = None):
        if url is None:
            embed = discord.Embed(
                description=
                f"🔴 **ERROR**: `Incorrect Usage! - {config['Prefix']}setborder <link>`"
            )
            await ctx.send(embed=embed)
            return
        try:
            await ctx.message.delete()

            # This tries to load the image from the url -- if incorrect it will throw an error resulting in the exception below
            load_image(str(url))

            await KumosLab.Database.set.border(user=ctx.author,
                                               guild=ctx.guild,
                                               link=url)
            embed = discord.Embed(
                description=
                f"🟢 **SUCCESS**: `Border Changed To`: [Link]({url})")
            embed.set_thumbnail(url=url)
            await ctx.send(embed=embed)

        except Exception as e:
            embed = discord.Embed(
                description=
                f"🔴 **ERROR**: `Invalid Link! - {config['Prefix']}setborder <link>`"
            )
            await ctx.send(embed=embed)
            return
Esempio n. 2
0
async def levelUp(user: discord.Member = None, guild: discord.Guild = None):
    if user is None:
        print(
            "Error in 'KumosLab/Database/check.py' - User is None for 'levelUp'"
        )
        return
    if guild is None:
        print(
            "Error in 'KumosLab/Database/check.py' - Guild is None for 'levelUp'"
        )
        return

    try:
        user_xp = await KumosLab.Database.get.xp(user=user, guild=guild)
        lvl = 0

        while True:
            if user_xp < ((config['xp_per_level'] / 2 * (lvl**2)) +
                          (config['xp_per_level'] / 2 * lvl)):
                break
            lvl += 1
        user_xp -= ((config['xp_per_level'] / 2 * ((lvl - 1)**2)) +
                    (config['xp_per_level'] / 2 * (lvl - 1)))
        if await KumosLab.Database.get.level(user=user, guild=guild) != lvl:
            await KumosLab.Database.set.level(user=user,
                                              guild=guild,
                                              amount=lvl)

            background_image = load_image(config['level_up_background'])
            background = Editor(background_image).resize(
                (900, 270)).blur(amount=config['level_up_blur'])
            profile_image = load_image(str(user.avatar_url))
            profile = Editor(profile_image).resize((200, 200)).circle_image()

            poppins_big = Font.poppins(variant="bold", size=50)
            poppins_mediam = Font.poppins(variant="bold", size=40)
            poppins_regular = Font.poppins(variant="regular", size=30)

            card_left_shape = [(0, 0), (0, 270), (330, 270), (260, 0)]

            background.polygon(card_left_shape, "#2C2F33")
            border_image = load_image(await KumosLab.Database.get.border(
                user=user, guild=guild))
            border = Editor(border_image).resize((210, 210)).circle_image()
            background.paste(border, (40, 30))
            background.paste(profile, (45, 35))

            background.text((600, 30),
                            "LEVEL UP!",
                            font=poppins_big,
                            color="white",
                            align="center")
            background.text((600, 80),
                            str(user),
                            font=poppins_regular,
                            color="white",
                            align="center")
            background.text((600, 130),
                            f"LEVEL {lvl:,}",
                            font=poppins_mediam,
                            color="white",
                            align="center")
            background.text(
                (600, 170),
                f"{translate(user_xp)}/{translate(int(config['xp_per_level'] * 2 * ((1 / 2) * lvl)))} XP",
                font=poppins_regular,
                color="white",
                align="center")

            embed = discord.Embed()

            member = user
            if await KumosLab.Database.get.mainChannel(guild=guild) is None:
                channel = guild.system_channel
            else:
                channel = discord.utils.get(
                    member.guild.channels,
                    name=await
                    KumosLab.Database.get.mainChannel(guild=member.guild))
            if channel is None:
                return
            if config['level_up_ping'] is True:
                await channel.send(f"{user.mention},")

            level_roles = np.asarray(await
                                     KumosLab.Database.get.roles(guild=guild))
            level_roles_num = np.asarray(
                await KumosLab.Database.get.roleLevel(guild=guild))

            for i in range(len(level_roles)):
                if lvl == int(level_roles_num[i]):
                    await user.add_roles(
                        discord.utils.get(user.guild.roles,
                                          name=level_roles[i]))
                    background.text(
                        (620, 225),
                        f"ROLE UNLOCKED - {level_roles[i]}".replace(
                            "[", "").replace("]", "").replace("'", ''),
                        font=poppins_regular,
                        color="white",
                        align="center",
                    )

                    # remove the previous role
                    if i > 0:
                        await user.remove_roles(
                            discord.utils.get(user.guild.roles,
                                              name=level_roles[i - 1]))
                    else:
                        continue

            card = File(fp=background.image_bytes, filename="level_card.png")
            embed.set_image(url="attachment://level_card.png")
            await channel.send(file=card, embed=embed)
    except Exception as e:
        print(f"Error in 'KumosLab/Database/check.py' - {e}")
Esempio n. 3
0
async def generate(user: discord.Member = None,
                   guild: discord.Guild = None,
                   clan_Name: str = None):
    if guild is None:
        print("[Custom] Guild is None")
        return
    if user is None:
        print("[Custom] User is None")
        return
    if clan_Name is None:
        print("[Custom] Clan_Name is None")
        return
    try:
        xp = await KumosLab.Database.get.clanXP(clan_Name=clan_Name,
                                                guild=guild)
        level = 1

        rank_colour = await KumosLab.Database.get.clanColour(
            clan_Name=clan_Name, guild=guild)
        clan_owner = await KumosLab.Database.get.clanOwner(clan_Name=clan_Name,
                                                           guild=guild)

        blur = 0

        while True:
            if xp < ((config['xp_per_level'] / 2 * (level**2)) +
                     (config['xp_per_level'] / 2 * level)):
                break
            level += 1
        xp -= ((config['xp_per_level'] / 2 * (level - 1)**2) +
               (config['xp_per_level'] / 2 * (level - 1)))

        next_level_xp = int(config['xp_per_level'] * 2 * ((1 / 2) * level))

        percentage = int((xp / next_level_xp) * 100)

        clan_logo = await KumosLab.Database.get.clanLogo(clan_Name=clan_Name,
                                                         guild=guild)
        clan_background = clan_config['clan_card_background']

        background_image = load_image(str(clan_background))
        background = Editor(background_image).resize(
            (1280, 720)).blur(amount=int(blur))

        profile_border = load_image(clan_config['clan_icon_border'])
        profile_border = Editor(profile_border).resize((250, 260))

        profile_image = load_image(clan_logo)
        profile = Editor(profile_image).resize((240, 250))

        font_25 = Font.poppins(size=35, variant="bold")
        font_60_bold = Font.poppins(size=60, variant="bold")
        font_40_bold = Font.poppins(size=50, variant="bold")

        background.paste(profile_border, (30, 40))
        background.paste(profile, (35, 45))

        background.text((300, 40),
                        f"{clan_owner}",
                        font=font_60_bold,
                        color=rank_colour)

        background.text((270, 150),
                        f"Level: {level:,}",
                        font=font_25,
                        color="white")

        background.rectangle((260, 190), width=600, height=40, radius=20)
        if percentage > 5:
            background.bar(
                (260, 190),
                max_width=600,
                height=40,
                percentage=percentage,
                fill=rank_colour,
                radius=20,
            )

        background.text((845, 145),
                        f"{translate(xp)} / {translate(next_level_xp)}",
                        font=font_25,
                        color="white",
                        align="right")

        card = File(fp=background.image_bytes, filename="rank_card.png")
        return card

    except Exception as e:
        print(f"[Custom Rank Card] {e}")
        raise e
Esempio n. 4
0
async def generate(user: discord.Member = None, guild: discord.Guild = None):
    if guild is None:
        print("[Custom] Guild is None")
        return
    if user is None:
        print("[Custom] User is None")
        return
    try:
        xp = await KumosLab.Database.get.xp(user=user, guild=guild)
        level = 1

        rank_colour = await KumosLab.Database.get.colour(user=user, guild=guild)

        blur = await KumosLab.Database.get.blur(user=user, guild=guild)

        while True:
            if xp < ((config['xp_per_level'] / 2 * (level ** 2)) + (config['xp_per_level'] / 2 * level)):
                break
            level += 1
        xp -= ((config['xp_per_level'] / 2 * (level - 1) ** 2) + (config['xp_per_level'] / 2 * (level - 1)))

        next_level_xp = int(config['xp_per_level'] * 2 * ((1 / 2) * level))

        percentage = int((xp / next_level_xp) * 100)

        user_background = await KumosLab.Database.get.background(user=user, guild=guild)
        user_border = await KumosLab.Database.get.border(user=user, guild=guild)

        background_image = load_image(str(user_background))
        background = Editor(background_image).resize((1050, 300)).blur(amount=int(blur))

        user_ranking = await KumosLab.Database.get.rankings(user=user, guild=guild)

        profile_image = load_image(user.avatar_url)
        profile = Editor(profile_image).resize((200, 210))
        border_image = load_image(user_border)
        border = Editor(border_image).resize((210, 220))


        font_25 = Font.poppins(size=35, variant="bold")
        font_60_bold = Font.poppins(size=60, variant="bold")
        font_40_bold = Font.poppins(size=50, variant="bold")

        background.paste(border, (30, 40))
        background.paste(profile, (35, 45))

        if config['name_colour'] is True:
            background.text((260, 40), f"{user}", font=font_60_bold, color=rank_colour)
            background.text(
                (870, 190), f"#{translate(user_ranking)}", font=font_40_bold,
                color=rank_colour
            )
        else:
            background.text((250, 40), f"{user}",
                            font=font_60_bold, color="white")
            background.text(
                (870, 190), f"#{await KumosLab.Database.get.rankings(user=user, guild=user.guild):,}", font=font_40_bold,
                color="white"
            )
        background.text((270, 150), f"Level: {level:,}", font=font_25, color="white")

        background.rectangle((260, 190), width=600, height=40, radius=20)
        if percentage > 5:
            background.bar(
                (260, 190),
                max_width=600,
                height=40,
                percentage=percentage,
                fill=rank_colour,
                radius=20,
            )

        background.text(
            (845, 145), f"{translate(xp)} / {translate(next_level_xp)}", font=font_25, color="white", align="right"
        )

        card = File(fp=background.image_bytes, filename="rank_card.png")
        return card

    except Exception as e:
        print(f"[Custom Rank Card] {e}")
        raise e