From 73ef8503ae811923ed9ea9d317f970c312fdf0d2 Mon Sep 17 00:00:00 2001 From: Gylfirst <30391973+gylfirst@users.noreply.github.com> Date: Fri, 9 Aug 2024 00:50:35 +0200 Subject: [PATCH 1/6] chore: update deps + add arm64 for docker build --- .github/workflows/docker-image.yaml | 2 +- .pre-commit-config.yaml | 2 +- requirements-dev.txt | 4 ++-- requirements.txt | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker-image.yaml b/.github/workflows/docker-image.yaml index 14ec0d3..e146818 100644 --- a/.github/workflows/docker-image.yaml +++ b/.github/workflows/docker-image.yaml @@ -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/v8 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 82cbfdf..48f64d4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.5.1 + rev: v0.5.6 hooks: # Run the linter. - id: ruff diff --git a/requirements-dev.txt b/requirements-dev.txt index 8a74f30..9541831 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,3 @@ -r requirements.txt -pre-commit ~= 3.7 -ruff == 0.5.1 +pre-commit ~= 3.8 +ruff == 0.5.6 diff --git a/requirements.txt b/requirements.txt index a6b0714..ab2fe64 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -aiohttp ~= 3.9.5 +aiohttp ~= 3.10.1 discord.py[speed] ~= 2.4.0 python-dotenv ~= 1.0.1 -tomlkit ~= 0.12.5 +tomlkit ~= 0.13.0 tzdata; os_name == "nt" From 071677518aa725c40a7d97011ebf38d1c9d5ae95 Mon Sep 17 00:00:00 2001 From: Gylfirst <30391973+gylfirst@users.noreply.github.com> Date: Fri, 9 Aug 2024 01:00:24 +0200 Subject: [PATCH 2/6] chore: update ruff and aiohttp dependencies --- .pre-commit-config.yaml | 2 +- requirements-dev.txt | 2 +- requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 48f64d4..6bc5216 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.5.6 + rev: v0.5.7 hooks: # Run the linter. - id: ruff diff --git a/requirements-dev.txt b/requirements-dev.txt index 9541831..457f0ae 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,3 @@ -r requirements.txt pre-commit ~= 3.8 -ruff == 0.5.6 +ruff == 0.5.7 diff --git a/requirements.txt b/requirements.txt index ab2fe64..23224fd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -aiohttp ~= 3.10.1 +aiohttp ~= 3.10.2 discord.py[speed] ~= 2.4.0 python-dotenv ~= 1.0.1 tomlkit ~= 0.13.0 From bfea973ae379c17caac3d26aa5716aa750e643ee Mon Sep 17 00:00:00 2001 From: Gylfirst <30391973+gylfirst@users.noreply.github.com> Date: Fri, 9 Aug 2024 01:34:04 +0200 Subject: [PATCH 3/6] =?UTF-8?q?chore:=20update=20ranking=20title=20to=20"C?= =?UTF-8?q?lassement=20de=20d=C3=A9but=20{month}=20{year}"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chouette/utils/ranking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chouette/utils/ranking.py b/chouette/utils/ranking.py index 05a7d86..624fb84 100644 --- a/chouette/utils/ranking.py +++ b/chouette/utils/ranking.py @@ -168,7 +168,7 @@ 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), ) From fba0231380aa02ae1caad6ac5168c2ffe28a295e Mon Sep 17 00:00:00 2001 From: Zalk0 <88582103+zalk0@users.noreply.github.com> Date: Fri, 9 Aug 2024 11:11:23 +0200 Subject: [PATCH 4/6] fix(ranking): level_cap incorrectly saved and accessed + remove useless asynchronous statements --- chouette/utils/ranking.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/chouette/utils/ranking.py b/chouette/utils/ranking.py index 624fb84..64dd693 100644 --- a/chouette/utils/ranking.py +++ b/chouette/utils/ranking.py @@ -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" @@ -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 = [ @@ -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(): @@ -79,9 +79,9 @@ 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: @@ -101,7 +101,7 @@ async def parse_data(data: dict) -> tuple[dict, list]: 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", @@ -135,8 +135,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) @@ -150,7 +150,8 @@ async def generate_ranking_message(data, category, level_cap): raise ValueError(f"Unknown category: {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: @@ -173,10 +174,10 @@ async def display_ranking(img: str) -> discord.Embed: 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), From 8a6b44a54ed40c278c2716198bbac2780c3c528f Mon Sep 17 00:00:00 2001 From: Zalk0 <88582103+zalk0@users.noreply.github.com> Date: Fri, 9 Aug 2024 12:07:48 +0200 Subject: [PATCH 5/6] fix(ranking): sort level_cap while sorting xp --- chouette/utils/ranking.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/chouette/utils/ranking.py b/chouette/utils/ranking.py index 64dd693..b6733f3 100644 --- a/chouette/utils/ranking.py +++ b/chouette/utils/ranking.py @@ -86,18 +86,17 @@ def parse_data(data: dict) -> tuple[dict, list]: # 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 @@ -147,7 +146,7 @@ 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 = format_number(value) From baad71fd7192739e326983a336ea58b824f440fe Mon Sep 17 00:00:00 2001 From: Gylfirst <30391973+gylfirst@users.noreply.github.com> Date: Fri, 9 Aug 2024 13:47:54 +0200 Subject: [PATCH 6/6] chore: update docker build platforms to include linux/arm64 --- .github/workflows/docker-image.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yaml b/.github/workflows/docker-image.yaml index e146818..872bdf5 100644 --- a/.github/workflows/docker-image.yaml +++ b/.github/workflows/docker-image.yaml @@ -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, linux/arm64/v8 + platforms: linux/amd64, linux/arm/v6, linux/arm/v7, linux/arm64