Skip to content

Commit

Permalink
Fixed major bugs and updates for Hypixel API V2
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinTrinh1227 committed May 21, 2024
1 parent 2c32a81 commit e934eb2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
14 changes: 6 additions & 8 deletions commands/bedwars_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ async def bedwars(self, ctx, *, username):
response = requests.get(url)
uuid = response.json()['id']

requestlink = f"https://api.hypixel.net/player?key={hypixel_api_key}&uuid={uuid}"
requestlink = f"https://api.hypixel.net/v2/player?key={hypixel_api_key}&uuid={uuid}"
hydata = requests.get(requestlink).json()
#print(hydata)

#finals stats
bedwars_final_kills = hydata["player"]["stats"]["Bedwars"]["final_kills_bedwars"]
Expand All @@ -67,20 +68,17 @@ async def bedwars(self, ctx, *, username):
#other statistics
bedwars_level = hydata["player"]["achievements"]["bedwars_level"] #bedwars level


background_image = Image.open("./assets/backgrounds/bedwars_stats.png")
front_response = requests.get(f"https://visage.surgeplay.com/full/300/{uuid}.png?y=-50")
front_skin = Image.open(BytesIO(front_response.content))

try:
front_response = requests.get(f"https://visage.surgeplay.com/full/300/{uuid}.png?y=-50")
front_response = requests.get(f"https://starlightskins.lunareclipse.studio/render/isometric/{uuid}/full")
front_skin = Image.open(BytesIO(front_response.content))
except:
front_skin = Image.open("./assets/resources/default_skin_front.png")


resized_front_skin = front_skin.resize((115, 285))
# Paste the downloaded image onto the background
background_image.paste(front_skin, (437, 38), front_skin)
background_image.paste(resized_front_skin, (470, 45), resized_front_skin)

header_text = f"{username}'s Overall Stats"
footer_text = f"© {ctx.guild.name}"
Expand All @@ -100,7 +98,7 @@ async def bedwars(self, ctx, *, username):
draw.text((pillow.center(222, bedwars_final_deaths, font_stat), 142), f"{bedwars_final_deaths}", (255, 255, 255), font=font_stat)
draw.text((pillow.center(360, bedwars_fkdr, font_stat), 142), f"{bedwars_fkdr}", (255, 255, 255), font=font_stat)

# beds stats row
# beds stats row50
draw.text((pillow.center(70, bedwars_beds_broken, font_stat), 203), f"{bedwars_beds_broken}", (255, 255, 255), font=font_stat)
draw.text((pillow.center(222, bedwars_beds_lost, font_stat), 203), f"{bedwars_beds_lost}", (255, 255, 255), font=font_stat)
draw.text((pillow.center(360, bedwars_bed_bblr, font_stat), 203), f"{bedwars_bed_bblr}", (255, 255, 255), font=font_stat)
Expand Down
11 changes: 7 additions & 4 deletions commands/guild_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

with open('config.json') as json_file:
data = json.load(json_file)

with open('guild_cache.json') as json_file:
guild_data = json.load(json_file)["guild_data"]["guild"]

embed_color = int(data["general"]["embed_color"].strip("#"), 16) #convert hex color to hexadecimal format
hypixel_guild_id = data["hypixel_ids"]["guild_id"]
Expand All @@ -30,6 +27,8 @@ def __init__(self, client):
@commands.cooldown(1, 30, commands.BucketType.user) # 20 seconds.
async def guildinfo(self, ctx):

with open('guild_cache.json') as json_file:
guild_data = json.load(json_file)["guild_data"]["guild"]

try:

Expand All @@ -38,6 +37,7 @@ async def guildinfo(self, ctx):
total_guild_exp = guild_data['exp']
guild_description = guild_data['description']


try:
guild_master_uuid = guild_data["members"][0]["uuid"]
g_master_url = f"https://api.mojang.com/user/profile/{guild_master_uuid}"
Expand Down Expand Up @@ -87,7 +87,10 @@ async def guildinfo(self, ctx):
""",
colour = embed_color
)
embed.set_author(name = f"Requested by {ctx.author}", icon_url=ctx.author.avatar.url)
if ctx.author.avatar:
embed.set_author(name = f"Requested by {ctx.author}", icon_url=ctx.author.avatar.url)
else:
embed.set_author(name = f"Requested by {ctx.author}")
embed.set_thumbnail(url = "{}".format(ctx.guild.icon.url)),
embed.timestamp = datetime.datetime.now()
embed.set_footer(text=f"©️ {ctx.guild.name}", icon_url = ctx.guild.icon.url)
Expand Down

0 comments on commit e934eb2

Please sign in to comment.