Skip to content
This repository has been archived by the owner on Nov 12, 2022. It is now read-only.

Commit

Permalink
2.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
222ryan authored May 27, 2022
1 parent 3263609 commit 03cfef5
Show file tree
Hide file tree
Showing 17 changed files with 1,950 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Commands/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ async def roles(self, ctx):
embed = discord.Embed(title="🔓 // LEVEL ROLES", description=f"**Level Roles for** `{ctx.guild.name}`")
role_array = np.asarray(await KumosLab.Database.get.roles(guild=ctx.guild))
role_level_array = np.asarray(await KumosLab.Database.get.roleLevel(guild=ctx.guild))
if role_array is None or len(role_array) < 1:
if role_array is None or role_level_array is None:
embed.add_field(name="Roles:", value="`There are no roles to unlock!`")
embed.add_field(name="Level:", value="`No level required!`")
return
else:
embed.add_field(name="Roles:", value=f"`{str(role_array).replace('[', '').replace(']', '')}`")
embed.add_field(name="Level:", value=f"`{str(role_level_array).replace('[', '').replace(']', '')}`", inline=False)
Expand Down
101 changes: 101 additions & 0 deletions Database/Create/ClanCard/clan_card.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import discord
from discord import File
from easy_pil import Editor, load_image_async, Font, load_image
from ruamel.yaml import YAML
import Commands.rank


import KumosLab.Database.get


yaml = YAML()
with open("Configs/config.yml", "r", encoding="utf-8") as file:
config = yaml.load(file)
with open("Configs/clan_addon.yml", "r", encoding="utf-8") as file:
clan_config = yaml.load(file)

def translate(num):
num = float('{:.3g}'.format(num))
magnitude = 0
while abs(num) >= 1000:
magnitude += 1
num /= 1000.0
return '{}{}'.format('{:f}'.format(num).rstrip('0').rstrip('.'), ['', 'K', 'M', 'B', 'T'][magnitude])

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



153 changes: 153 additions & 0 deletions Database/Create/Leaderboard/Local/leaderboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import asyncio
import sqlite3

import discord
from discord.ext import commands
from ruamel.yaml import YAML
import KumosLab.Database.conversion as conversion


yaml = YAML()
with open("Configs/config.yml", "r", encoding="utf-8") as file:
config = yaml.load(file)

async def leaderboard(self=None, ctx=None, guild=None, leader_type=None):
if self is None:
print("[Leaderboard-Local] Self is None")
return
if ctx is None:
print("[Leaderboard-Local] Context is None")
return
if guild is None:
print("[Leaderboard-Local] Guild is None")
return
if leader_type is None:
print("[Leaderboard-Local] Type is None")
return
db = sqlite3.connect("KumosLab/Database/Local/userbase.sqlite")
cursor = db.cursor()
# sort by xp desc
if leader_type.lower() == "local":
cursor.execute(
"SELECT * FROM levelling WHERE guild_id = ? ORDER BY xp DESC", (guild.id,))
result = cursor.fetchall()
embed = discord.Embed(title=f":trophy: {guild}'s Leaderboard", colour=config['leaderboard_embed_colour'])
else:
cursor.execute("SELECT * FROM levelling ORDER BY xp DESC")
result = cursor.fetchall()
embed = discord.Embed(title=f"🌎 Global Leaderboard", colour=config['leaderboard_embed_colour'])
if result is None:
return "Server Not Found!"

users = []
level = []
xp = []
guild = []

for x in result:
users.append(x[1])
level.append(x[3])
xp.append(x[4])
guild_obj = self.client.get_guild(x[2])
guild.append(guild_obj.name)

pagination = list(zip(users, level, xp, guild))
pages = [pagination[i:i + 10] for i in range(0, len(pagination), 10)]
page = 0
num = 0
user_list = []
level_list = []
xp_list = []
guild_list = []
for i in pages:
embed.clear_fields()
for users, levels, xp, guild in i:
num += 1
if leader_type.lower() == "local":
embed.add_field(name=f"#{num}: {users}", value=f"```Level: {levels:,} - {conversion.translate(xp)} XP```", inline=True)
else:
embed.add_field(name=f"#{num}: {users} - {guild}", value=f"```Level: {levels:,} - {conversion.translate(xp)} XP```", inline=True)
embed.set_footer(text=f"Page {page + 1}/{len(pages)}")
message = await ctx.send(embed=embed)
page += 1
await message.add_reaction("⬅")
await message.add_reaction("➡")
await message.add_reaction("❌")

while True:
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ["⬅", "➡", "❌"] and reaction.message.id == message.id

try:
reaction, user = await ctx.bot.wait_for("reaction_add", timeout=60.0, check=check)

if str(reaction.emoji) == "⬅":
if page == 1:
pass
else:
page -= 1
embed.clear_fields()
for users, levels, xp, guild in pages[page - 1]:
num -= 1
user_list.append(users)
level_list.append(levels)
xp_list.append(xp)
guild_list.append(guild)
for x in range(0, len(user_list)):
if leader_type.lower() == "local":
embed.add_field(name=f"#{x + 1 + num - len(user_list)}: {user_list[x]}",
value=f"```Level {level_list[x]:,} - {conversion.translate(xp_list[x])} XP```", inline=True)
else:
embed.add_field(
name=f"#{x + 1 + num - len(user_list)}: {user_list[x]} - {guild_list[x]}",
value=f"```Level {level_list[x]:,} - {conversion.translate(xp_list[x])} XP```",
inline=True)
user_list.clear()
level_list.clear()
xp_list.clear()
guild_list.clear()
embed.set_footer(text=f"Page {page}/{len(pages)}")
await message.edit(embed=embed)
await message.remove_reaction("⬅", user)
await message.remove_reaction("➡", user)
await message.remove_reaction("❌", user)
elif str(reaction.emoji) == "➡":
if page == 1:
pass
else:
page += 1
embed.clear_fields()
for users, levels, xp, guild in pages[page - 1]:
num += 1
user_list.append(users)
level_list.append(levels)
xp_list.append(xp)
guild_list.append(guild)
for x in range(0, len(user_list)):
if leader_type.lower() == "local":
embed.add_field(name=f"#{x + 1 + num - len(user_list)}: {user_list[x]}",
value=f"```Level {level_list[x]:,} - {conversion.translate(xp_list[x])} XP```",
inline=True)
else:
embed.add_field(
name=f"#{x + 1 + num - len(user_list)}: {user_list[x]} - {guild_list[x]}",
value=f"```Level {level_list[x]:,} - {conversion.translate(xp_list[x])} XP```",
inline=True)
user_list.clear()
level_list.clear()
xp_list.clear()
guild_list.clear()
embed.set_footer(text=f"Page {page}/{len(pages)}")
await message.edit(embed=embed)
await message.remove_reaction("⬅", user)
await message.remove_reaction("➡", user)
await message.remove_reaction("❌", user)
elif str(reaction.emoji) == "❌":
await message.delete()
return
except asyncio.TimeoutError:
await message.delete()
return



Loading

0 comments on commit 03cfef5

Please sign in to comment.