From d9b55010996f46c2f65a29e69e1db00d43662cc1 Mon Sep 17 00:00:00 2001 From: Gylfirst <30391973+gylfirst@users.noreply.github.com> Date: Fri, 9 Aug 2024 14:03:00 +0200 Subject: [PATCH 1/5] chore: Update Docker build platforms to include linux/arm64 in README + remove 'version' in docker-compose --- README.md | 2 +- docker-compose.yaml.example | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 3300ab6..e0813ab 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ You can also run ruff manually with the commands `ruff check` and `ruff format`. [![Docker Image](https://github.com/Zalk0/ChouetteBot-discord/actions/workflows/docker-image.yaml/badge.svg?branch=main)](https://github.com/Zalk0/ChouetteBot-discord/actions/workflows/docker-image.yaml) -You can use a Docker image to deploy the bot. It's currently supporting amd64, armv6 and armv7 +You can use a Docker image to deploy the bot. It's currently supporting amd64, armv6, armv7 and arm64 architectures. We provide deployment information on the [Docker Hub repository](https://hub.docker.com/r/gylfirst/chouettebot). You can build it from source with: diff --git a/docker-compose.yaml.example b/docker-compose.yaml.example index b03d24f..fd3a3b3 100644 --- a/docker-compose.yaml.example +++ b/docker-compose.yaml.example @@ -1,5 +1,3 @@ -version: "3.8" # Version of docker-compose - services: bot: # If you want to build yourself (check README Docker section) From 00d102802fc9a81798c88f34917fe333740b7fe1 Mon Sep 17 00:00:00 2001 From: Zalk0 <88582103+zalk0@users.noreply.github.com> Date: Thu, 15 Aug 2024 15:58:20 +0200 Subject: [PATCH 2/5] fix: README.md + pyproject.toml + up deps - added badge for Python version in README.md - shorten long lines in README.md - fix license and add readme field in pyproject.toml - update aiohttp, Ruff and TOML Kit --- .pre-commit-config.yaml | 2 +- README.md | 12 +++++++++--- pyproject.toml | 3 ++- requirements-dev.txt | 2 +- requirements.txt | 4 ++-- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6bc5216..8811e87 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.7 + rev: v0.6.0 hooks: # Run the linter. - id: ruff diff --git a/README.md b/README.md index e0813ab..efcb5eb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # ChouetteBot-discord +![Python version 3.9+](https://img.shields.io/badge/Python-3.9+-blue) [![Ruff status](https://github.com/Zalk0/ChouetteBot-discord/actions/workflows/ruff.yaml/badge.svg?branch=main)](https://github.com/Zalk0/ChouetteBot-discord/actions/workflows/ruff.yaml) [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/Zalk0/ChouetteBot-discord/main.svg)](https://results.pre-commit.ci/latest/github/Zalk0/ChouetteBot-discord/main) @@ -55,13 +56,18 @@ You can also run ruff manually with the commands `ruff check` and `ruff format`. [![Docker Image](https://github.com/Zalk0/ChouetteBot-discord/actions/workflows/docker-image.yaml/badge.svg?branch=main)](https://github.com/Zalk0/ChouetteBot-discord/actions/workflows/docker-image.yaml) -You can use a Docker image to deploy the bot. It's currently supporting amd64, armv6, armv7 and arm64 -architectures. We provide deployment information on the [Docker Hub repository](https://hub.docker.com/r/gylfirst/chouettebot). +You can use a Docker image to deploy the bot. +It's currently supporting amd64, armv6, armv7 and arm64 architectures. +We provide deployment information on the +[Docker Hub repository](https://hub.docker.com/r/gylfirst/chouettebot). You can build it from source with: + ```bash docker build . # or docker build --build-arg version=tag -t app:tag . ``` -(see [Docker Build CLI Options](https://docs.docker.com/reference/cli/docker/image/build/#options) to get more info) + +(see [Docker Build CLI Options](https://docs.docker.com/reference/cli/docker/image/build/#options) +to get more info) diff --git a/pyproject.toml b/pyproject.toml index ef08483..0c9f707 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,7 @@ [project] name = "ChouetteBot" -license = "MIT" +license = { text = "MIT License" } +readme = "README.md" requires-python = ">=3.9" [tool.ruff] diff --git a/requirements-dev.txt b/requirements-dev.txt index 457f0ae..d5bd7fb 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,3 @@ -r requirements.txt pre-commit ~= 3.8 -ruff == 0.5.7 +ruff == 0.6.0 diff --git a/requirements.txt b/requirements.txt index 23224fd..821b890 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -aiohttp ~= 3.10.2 +aiohttp ~= 3.10.3 discord.py[speed] ~= 2.4.0 python-dotenv ~= 1.0.1 -tomlkit ~= 0.13.0 +tomlkit ~= 0.13.2 tzdata; os_name == "nt" From 0c76bd8576d0b547e2ff9ef6e8ecf85dd868c0f8 Mon Sep 17 00:00:00 2001 From: Zalk0 <88582103+zalk0@users.noreply.github.com> Date: Sat, 17 Aug 2024 13:42:15 +0200 Subject: [PATCH 3/5] feat: add overflow value to ranking + fix xp values for skills in hypixel_data.py + round level to int if at max level --- chouette/utils/hypixel_data.py | 18 +++++++++---- chouette/utils/ranking.py | 47 +++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/chouette/utils/hypixel_data.py b/chouette/utils/hypixel_data.py index ed64720..e9074aa 100644 --- a/chouette/utils/hypixel_data.py +++ b/chouette/utils/hypixel_data.py @@ -1,4 +1,9 @@ -def experience_to_level(type_xp: str, xp_amount: float) -> float: +from typing import Optional + + +def experience_to_level( + type_xp: str, xp_amount: float, max_level: Optional[int] = None +) -> (float, float): """ Calcule le niveau correspondant à une quantité donnée d'expérience cumulative. @@ -6,6 +11,7 @@ def experience_to_level(type_xp: str, xp_amount: float) -> float: type_xp: Le type d'expérience pour lequel calculer le niveau (compétence, type de slayer, donjon). Pour `slayer_type`, utilisez l'un des suivants: slayer_zombie, slayer_spider, slayer_web, slayer_vampire. xp_amount: La quantité d'expérience cumulée. + max_level: Le niveau maximum Returns: level: Le niveau correspondant à la quantité donnée d'expérience cumulée. @@ -65,11 +71,11 @@ def experience_to_level(type_xp: str, xp_amount: float) -> float: (51, 59472425), (52, 64072425), (53, 68972425), - (54, 74122425), + (54, 74172425), (55, 79672425), (56, 85472425), (57, 91572425), - (58, 97572425), + (58, 97972425), (59, 104672425), (60, 111672425), ] @@ -196,7 +202,9 @@ def experience_to_level(type_xp: str, xp_amount: float) -> float: raise ValueError(f"Unknown type of XP: {type_xp}") for i, (level, xp) in enumerate(xp_data): + if max_level and level == max_level: + return max_level, xp_amount - xp_data[level][1] if xp_amount <= xp: previous_xp = xp_data[i - 1][1] - return level - 1 + (xp_amount - previous_xp) / (xp - previous_xp) - return xp_data[-1][0] + return level - 1 + (xp_amount - previous_xp) / (xp - previous_xp), None + return xp_data[-1][0], xp_amount - xp_data[-1][1] diff --git a/chouette/utils/ranking.py b/chouette/utils/ranking.py index b6733f3..496bb01 100644 --- a/chouette/utils/ranking.py +++ b/chouette/utils/ranking.py @@ -1,3 +1,4 @@ +import math from datetime import date import aiohttp @@ -123,42 +124,52 @@ def generate_ranking_message(data, category, level_cap): ] messages = [] for i, (player, value) in enumerate(data[category].items()): + overflow = None if category != "level" and category != "networth": if category in skills_list: if category != "dungeoneering": - value = experience_to_level(type_xp="skill", xp_amount=value) + max_level = 60 + # Set max level to 50 for skills (alchemy, carpentery, fishing, foraging) + if category in ("alchemy", "carpentery", "fishing", "foraging", "taming"): + max_level = 50 + # Set max level to level cap for farming + if category == "farming": + max_level = level_cap[0][i] + 50 + # TODO: if taming -> level_cap[1][i] + 50 + value, overflow = experience_to_level("skill", value, max_level) else: - value = experience_to_level(type_xp="dungeon", xp_amount=value) - # Set max level to 50 for skills (alchemy, carpentery, fishing, foraging) - if category in ("alchemy", "carpentery", "fishing", "foraging", "taming"): - value = min(value, 50.00) - # Set max level to level cap for farming - if category == "farming": - value = min(value, level_cap[0][i] + 50) - # TODO: if taming -> level_cap[1][i] + 50 + value, overflow = experience_to_level("dungeon", value) elif category in slayers_list: if category == "zombie": - value = experience_to_level(type_xp="slayer_zombie", xp_amount=value) + value, overflow = experience_to_level("slayer_zombie", value) elif category == "spider": - value = experience_to_level(type_xp="slayer_spider", xp_amount=value) + value, overflow = experience_to_level("slayer_spider", value) elif category == "vampire": - value = experience_to_level(type_xp="slayer_vampire", xp_amount=value) + value, overflow = experience_to_level("slayer_vampire", value) else: - value = experience_to_level(type_xp="slayer_web", xp_amount=value) + value, overflow = experience_to_level("slayer_web", value) else: raise ValueError(f"Unknown category in the ranking: {category}") - value = f"{value:.2f}" + + if overflow: + value = f"{value:.0f}" + overflow = math.floor(overflow) + else: + value = f"{value:.2f}" + elif category == "networth": value = format_number(value) if i == 0: - message = f"\N{FIRST PLACE MEDAL} **{player}** ({value})" + message = f"\N{FIRST PLACE MEDAL} **{player}** [{value}]" elif i == 1: - message = f"\N{SECOND PLACE MEDAL} **{player}** ({value})" + message = f"\N{SECOND PLACE MEDAL} **{player}** [{value}]" elif i == 2: - message = f"\N{THIRD PLACE MEDAL} **{player}** ({value})" + message = f"\N{THIRD PLACE MEDAL} **{player}** [{value}]" else: - message = f"\N{MEDIUM BLACK CIRCLE} **{player}** ({value})" + message = f"\N{MEDIUM BLACK CIRCLE} **{player}** [{value}]" + if overflow: + message += f" (*{overflow:,}*)".replace(",", " ") messages.append(message) return messages From d7fd81b7d7bb8a5cc1f4ac17827bf90ef22a7ba8 Mon Sep 17 00:00:00 2001 From: Zalk0 <88582103+zalk0@users.noreply.github.com> Date: Sat, 17 Aug 2024 17:43:59 +0200 Subject: [PATCH 4/5] fix: use simple lists instead of list of tuples - it uses the fact that a list is ordered to have the corresponding levels - shorten the slayer lists by taking out the common part --- chouette/utils/hypixel_data.py | 306 ++++++++++++++++----------------- 1 file changed, 150 insertions(+), 156 deletions(-) diff --git a/chouette/utils/hypixel_data.py b/chouette/utils/hypixel_data.py index e9074aa..61ff308 100644 --- a/chouette/utils/hypixel_data.py +++ b/chouette/utils/hypixel_data.py @@ -16,168 +16,162 @@ def experience_to_level( Returns: level: Le niveau correspondant à la quantité donnée d'expérience cumulée. """ - skill_xp_data: list[tuple[int, int]] = [ - (0, 0), - (1, 50), - (2, 175), - (3, 375), - (4, 675), - (5, 1175), - (6, 1925), - (7, 2925), - (8, 4425), - (9, 6425), - (10, 9925), - (11, 14925), - (12, 22425), - (13, 32425), - (14, 47425), - (15, 67425), - (16, 97425), - (17, 147425), - (18, 222425), - (19, 322425), - (20, 522425), - (21, 822425), - (22, 1222425), - (23, 1722425), - (24, 2322425), - (25, 3022425), - (26, 3822425), - (27, 4722425), - (28, 5722425), - (29, 6822425), - (30, 8022425), - (31, 9322425), - (32, 10722425), - (33, 12222425), - (34, 13822425), - (35, 15522425), - (36, 17322425), - (37, 19222425), - (38, 21222425), - (39, 23322425), - (40, 25522425), - (41, 27822425), - (42, 30222425), - (43, 32722425), - (44, 35322425), - (45, 38072425), - (46, 40972425), - (47, 44072425), - (48, 47472425), - (49, 51172425), - (50, 55172425), - (51, 59472425), - (52, 64072425), - (53, 68972425), - (54, 74172425), - (55, 79672425), - (56, 85472425), - (57, 91572425), - (58, 97972425), - (59, 104672425), - (60, 111672425), + skill_xp_data: list[int] = [ + 0, + 50, + 175, + 375, + 675, + 1175, + 1925, + 2925, + 4425, + 6425, + 9925, + 14925, + 22425, + 32425, + 47425, + 67425, + 97425, + 147425, + 222425, + 322425, + 522425, + 822425, + 1222425, + 1722425, + 2322425, + 3022425, + 3822425, + 4722425, + 5722425, + 6822425, + 8022425, + 9322425, + 10722425, + 12222425, + 13822425, + 15522425, + 17322425, + 19222425, + 21222425, + 23322425, + 25522425, + 27822425, + 30222425, + 32722425, + 35322425, + 38072425, + 40972425, + 44072425, + 47472425, + 51172425, + 55172425, + 59472425, + 64072425, + 68972425, + 74172425, + 79672425, + 85472425, + 91572425, + 97972425, + 104672425, + 111672425, ] - dungeon_xp_data: list[tuple[int, int]] = [ - (0, 0), - (1, 50), - (2, 125), - (3, 235), - (4, 395), - (5, 625), - (6, 955), - (7, 1425), - (8, 2095), - (9, 3045), - (10, 4385), - (11, 6275), - (12, 8940), - (13, 12700), - (14, 17960), - (15, 25340), - (16, 35640), - (17, 50040), - (18, 70040), - (19, 97640), - (20, 135640), - (21, 188140), - (22, 259640), - (23, 356640), - (24, 488640), - (25, 668640), - (26, 911640), - (27, 1239640), - (28, 1684640), - (29, 2284640), - (30, 3084640), - (31, 4149640), - (32, 5559640), - (33, 7459640), - (34, 9959640), - (35, 13259640), - (36, 17559640), - (37, 23159640), - (38, 30359640), - (39, 39559640), - (40, 51559640), - (41, 66559640), - (42, 85559640), - (43, 109559640), - (44, 139559640), - (45, 177559640), - (46, 225559640), - (47, 285559640), - (48, 360559640), - (49, 453559640), - (50, 569809640), + dungeon_xp_data: list[int] = [ + 0, + 50, + 125, + 235, + 395, + 625, + 955, + 1425, + 2095, + 3045, + 4385, + 6275, + 8940, + 12700, + 17960, + 25340, + 35640, + 50040, + 70040, + 97640, + 135640, + 188140, + 259640, + 356640, + 488640, + 668640, + 911640, + 1239640, + 1684640, + 2284640, + 3084640, + 4149640, + 5559640, + 7459640, + 9959640, + 13259640, + 17559640, + 23159640, + 30359640, + 39559640, + 51559640, + 66559640, + 85559640, + 109559640, + 139559640, + 177559640, + 225559640, + 285559640, + 360559640, + 453559640, + 569809640, ] - slayer_xp_data: list[list[tuple[int, int]]] = [ + # Common part for the slayer levels + common_slayer_xp_data: list[int] = [ + 200, + 1000, + 5000, + 20000, + 100000, + 400000, + 1000000, + ] + slayer_xp_data: tuple[list[int], list[int], list[int], list[int]] = ( [ - (0, 0), - (1, 5), - (2, 15), - (3, 200), - (4, 1000), - (5, 5000), - (6, 20000), - (7, 100000), - (8, 400000), - (9, 1000000), + 0, + 5, + 15, + *common_slayer_xp_data, ], [ - (0, 0), - (1, 5), - (2, 25), - (3, 200), - (4, 1000), - (5, 5000), - (6, 20000), - (7, 100000), - (8, 400000), - (9, 1000000), + 0, + 5, + 25, + *common_slayer_xp_data, ], [ - (0, 0), - (1, 10), - (2, 30), - (3, 250), - (4, 1500), - (5, 5000), - (6, 20000), - (7, 100000), - (8, 400000), - (9, 1000000), + 0, + 10, + 30, + 250, + 1500, + *common_slayer_xp_data[2:], ], [ - (0, 0), - (1, 20), - (2, 75), - (3, 240), - (4, 840), - (5, 2400), + 0, + 20, + 75, + 240, + 840, + 2400, ], - ] + ) # Skill XP data if type_xp == "skill": @@ -201,10 +195,10 @@ def experience_to_level( else: raise ValueError(f"Unknown type of XP: {type_xp}") - for i, (level, xp) in enumerate(xp_data): + for level, xp in enumerate(xp_data): if max_level and level == max_level: - return max_level, xp_amount - xp_data[level][1] + return max_level, xp_amount - xp if xp_amount <= xp: - previous_xp = xp_data[i - 1][1] + previous_xp = xp_data[level - 1] return level - 1 + (xp_amount - previous_xp) / (xp - previous_xp), None - return xp_data[-1][0], xp_amount - xp_data[-1][1] + return len(xp_data) - 1, xp_amount - xp_data[-1] From 3eb5dddee94131cb22bad714007e225ff08a6dd4 Mon Sep 17 00:00:00 2001 From: Zalk0 <88582103+zalk0@users.noreply.github.com> Date: Sat, 17 Aug 2024 17:49:40 +0200 Subject: [PATCH 5/5] chore(deps-dev): bump ruff from 0.6.0 to 0.6.1 --- .pre-commit-config.yaml | 2 +- requirements-dev.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8811e87..69f27bc 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.6.0 + rev: v0.6.1 hooks: # Run the linter. - id: ruff diff --git a/requirements-dev.txt b/requirements-dev.txt index d5bd7fb..d8659ba 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,3 @@ -r requirements.txt pre-commit ~= 3.8 -ruff == 0.6.0 +ruff == 0.6.1