Skip to content

Commit

Permalink
Merge pull request #71 from Zalk0/dev
Browse files Browse the repository at this point in the history
Bug fixes + add new docker image + update deps
  • Loading branch information
gylfirst authored Aug 9, 2024
2 parents fdfee31 + baad71f commit ff2070b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
push: true
build-args: version=v0.0.${{ github.run_number }}
tags: gylfirst/chouettebot:latest,gylfirst/chouettebot:v0.0.${{ github.run_number }}
platforms: linux/amd64, linux/arm/v6, linux/arm/v7
platforms: linux/amd64, linux/arm/v6, linux/arm/v7, linux/arm64
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.1
rev: v0.5.7
hooks:
# Run the linter.
- id: ruff
Expand Down
44 changes: 22 additions & 22 deletions chouette/utils/ranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
SPACES = " " * 38


async def format_number(number) -> str:
def format_number(number) -> str:
"""Permet de formater un nombre en K, M ou B."""
if number >= 1_000_000_000:
return f"{number / 1_000_000_000:.2f}B"
Expand Down Expand Up @@ -41,7 +41,7 @@ async def update_stats(api_key: str) -> str:
return msg


async def parse_data(data: dict) -> tuple[dict, list]:
def parse_data(data: dict) -> tuple[dict, list]:
"""Parse les données de la guilde sur Hypixel Skyblock."""
ranking = {}
skills = [
Expand All @@ -57,7 +57,7 @@ async def parse_data(data: dict) -> tuple[dict, list]:
"dungeoneering",
]
slayers = ["zombie", "spider", "wolf", "enderman", "blaze", "vampire"]
level_cap = []
level_cap = [[], []]

for player in data:
for key, value in data[player].items():
Expand All @@ -79,29 +79,28 @@ async def parse_data(data: dict) -> tuple[dict, list]:
ranking[slayer] = {}
ranking[slayer][data[player]["pseudo"]] = value[slayers.index(slayer)]
if key == "level_cap":
level_cap.append(value[0])
level_cap[0].append(value[0])
# TODO: for taming
# -> level_cap.append(value[1])
# -> level_cap[1].append(value[1])

# Sorting the nested dictionaries by value
for category in ranking:
if isinstance(ranking[category], dict):
unsorted = ranking[category]
ranking[category] = dict(
sorted(ranking[category].items(), key=lambda item: item[1], reverse=True)
)
elif category == "skills" or category == "slayers":
for subcategory in ranking[category]:
ranking[category][subcategory] = dict(
sorted(
ranking[category][subcategory].items(),
key=lambda item: item[1],
reverse=True,
)
)
# In the case of farming we need sort the level_cap too
if category == "farming":
level_cap[0] = [
level_cap[0][list(unsorted.keys()).index(key)] for key in ranking[category]
]
else:
raise ValueError(f"Unknown category while sorting: {category}")
return ranking, level_cap


async def generate_ranking_message(data, category, level_cap):
def generate_ranking_message(data, category, level_cap):
skills_list: list[str] = [
"fishing",
"alchemy",
Expand Down Expand Up @@ -135,8 +134,8 @@ async def generate_ranking_message(data, category, level_cap):
value = min(value, 50.00)
# Set max level to level cap for farming
if category == "farming":
value = min(value, level_cap[0] + 50)
# TODO: if taming -> level_cap[1] + 50
value = min(value, level_cap[0][i] + 50)
# TODO: if taming -> level_cap[1][i] + 50
elif category in slayers_list:
if category == "zombie":
value = experience_to_level(type_xp="slayer_zombie", xp_amount=value)
Expand All @@ -147,10 +146,11 @@ async def generate_ranking_message(data, category, level_cap):
else:
value = experience_to_level(type_xp="slayer_web", xp_amount=value)
else:
raise ValueError(f"Unknown category: {category}")
raise ValueError(f"Unknown category in the ranking: {category}")
value = f"{value:.2f}"
elif category == "networth":
value = await format_number(value)
value = format_number(value)

if i == 0:
message = f"\N{FIRST PLACE MEDAL} **{player}** ({value})"
elif i == 1:
Expand All @@ -168,15 +168,15 @@ async def display_ranking(img: str) -> discord.Embed:
month = await month_to_str(date.today().month)
year = date.today().year
ranking = discord.Embed(
title=f"Classement du mois de {month} {year}",
title=f"Classement de début {month} {year}",
description="Voici le classement de la guilde sur Hypixel Skyblock.",
color=discord.Colour.from_rgb(0, 170, 255),
)
ranking.set_footer(text="\N{WHITE HEAVY CHECK MARK} Mis à jour le 1er de chaque mois à 8h00")
data, level_cap = await parse_data(await load_skyblock())
data, level_cap = parse_data(await load_skyblock())
for category in data:
if isinstance(data[category], dict):
messages = await generate_ranking_message(data, category, level_cap)
messages = generate_ranking_message(data, category, level_cap)
ranking.add_field(
name=f"**[ {category.capitalize()} ]**",
value="\n".join(messages),
Expand Down
4 changes: 2 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-r requirements.txt
pre-commit ~= 3.7
ruff == 0.5.1
pre-commit ~= 3.8
ruff == 0.5.7
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
aiohttp ~= 3.9.5
aiohttp ~= 3.10.2
discord.py[speed] ~= 2.4.0
python-dotenv ~= 1.0.1
tomlkit ~= 0.12.5
tomlkit ~= 0.13.0
tzdata; os_name == "nt"

0 comments on commit ff2070b

Please sign in to comment.