From a9534e4044a330f662d4c714c493fd786fcb3840 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Nov 2023 18:11:39 +0000 Subject: [PATCH 1/7] build(deps): update humanize requirement from ~=4.8.0 to ~=4.9.0 Updates the requirements on [humanize](https://github.com/python-humanize/humanize) to permit the latest version. - [Release notes](https://github.com/python-humanize/humanize/releases) - [Commits](https://github.com/python-humanize/humanize/compare/4.8.0...4.9.0) --- updated-dependencies: - dependency-name: humanize dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 3e4b09d..81b2b70 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,6 @@ requests discord~=2.3.2 pyyaml~=6.0 python-dotenv~=1.0.0 -humanize~=4.8.0 +humanize~=4.9.0 sqlitedict~=2.1.0 aiohttp~=3.8.6 From 743482764e14cfe1366d41097d7ee0c4a54a782c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 18:39:21 +0000 Subject: [PATCH 2/7] build(deps): update aiohttp requirement from ~=3.8.6 to ~=3.9.3 Updates the requirements on [aiohttp](https://github.com/aio-libs/aiohttp) to permit the latest version. - [Release notes](https://github.com/aio-libs/aiohttp/releases) - [Changelog](https://github.com/aio-libs/aiohttp/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/aiohttp/compare/v3.8.6...v3.9.3) --- updated-dependencies: - dependency-name: aiohttp dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 3e4b09d..5d26740 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,4 @@ pyyaml~=6.0 python-dotenv~=1.0.0 humanize~=4.8.0 sqlitedict~=2.1.0 -aiohttp~=3.8.6 +aiohttp~=3.9.3 From 67679120d5aa7fc968533aaf786d4489ed4a122f Mon Sep 17 00:00:00 2001 From: fuyu Date: Sat, 20 Apr 2024 02:07:35 +0300 Subject: [PATCH 3/7] remove `parsecommand` --- bot/cogs/osu.py | 44 ----------------------------- helpers/converters.py | 66 ------------------------------------------- 2 files changed, 110 deletions(-) delete mode 100644 helpers/converters.py diff --git a/bot/cogs/osu.py b/bot/cogs/osu.py index 0992260..75c50b0 100644 --- a/bot/cogs/osu.py +++ b/bot/cogs/osu.py @@ -9,7 +9,6 @@ from discord import Embed from discord.ext import commands from bot.bot import config -from helpers.converters import ArgumentConverter from utils.api import * from utils.db import users from utils.enums import GameModes, Grades, Mods, filter_invalid_combos @@ -45,49 +44,6 @@ def construct_avatar_url(player_id): return url + f"?{str(int(time.time()))}" -def parsecommand(input_str): - """ - Returns a tuple containing the username and GameMode - :return: tuple[str, GameModes] - """ - gamemodes = { - '-std': GameModes.STANDARD, - '-rx': GameModes.RX_STANDARD, - '-taiko': GameModes.TAIKO, - '-taikorx': GameModes.RX_TAIKO, - '-ctb': GameModes.CATCH, - '-ctbrx': GameModes.RX_CATCH, - '-mania': GameModes.MANIA, - '-ap': GameModes.AP_STANDARD, - } - - mode = None - username = '' - - if not len(input_str) > 0: - mode = GameModes.STANDARD - return username, mode - - tokens = input_str.split() - for i, token in enumerate(tokens): - if token.startswith('-'): - mode = token - username = ' '.join(tokens[:i]) - break - - if mode is None: - mode = GameModes.STANDARD - username = ' '.join(tokens) - return username, mode - - try: - mode = gamemodes[mode] - except KeyError: - mode = None - - return username, mode - - async def get_username_and_mode( ctx, username: str = None, mode: GameModes = GameModes.STANDARD ): diff --git a/helpers/converters.py b/helpers/converters.py deleted file mode 100644 index 59f1f39..0000000 --- a/helpers/converters.py +++ /dev/null @@ -1,66 +0,0 @@ -from typing import Union -from discord.ext.commands import Converter - -from utils.enums import GameModes, Mods - -__all__ = ("ArgumentConverter",) - -game_modes = { - "osu": GameModes.STANDARD, - "std": GameModes.STANDARD, - "taiko": GameModes.TAIKO, - "catch": GameModes.CATCH, - "ctb": GameModes.CATCH, - "mania": GameModes.MANIA, -} -rx_modes = { - "osu": GameModes.RX_STANDARD, - "std": GameModes.RX_STANDARD, - "taiko": GameModes.RX_TAIKO, - "catch": GameModes.RX_CATCH, - "ctb": GameModes.RX_CATCH, -} -ap_modes = {"osu": GameModes.AP_STANDARD, "std": GameModes.AP_STANDARD} - - -class ArgumentConverter(Converter): - """ - Converts an argument into game mode or mod depending on it's value - """ - - async def convert(self, ctx, arg) -> GameModes: - """ - arg will hold all the arguments specified by the user - this, because of the game modes rely on the specified mod - such as RX; being Gamemodes.RX_STANDARD instead of Gamemodes.STANDARD - """ - - arguments = arg.split() - - if not len(arguments): - raise ValueError("No arguments were specified") - - if arg == "-rx": - return GameModes.RX_STANDARD - if arg == "-ap": - return GameModes.AP_STANDARD - if arg == "-std": - return GameModes.STANDARD - if arg == "-vn": - return GameModes.STANDARD - if arg == "-taiko": - return GameModes.TAIKO - if arg == "-taikorx": - return GameModes.RX_TAIKO - if arg == "-ctb": - return GameModes.CATCH - if arg == "-ctbrx": - return GameModes.RX_CATCH - if arg == "-mania": - return GameModes.MANIA - - if len(arguments) == 1: - if arg in game_modes: - return game_modes[arg] - else: - raise ValueError("Invalid game mode and/or mod") From b82e60d422a5c1fb55e8f77863a077099877f4e0 Mon Sep 17 00:00:00 2001 From: fuyu Date: Sat, 20 Apr 2024 03:25:40 +0300 Subject: [PATCH 4/7] add .editorconfig --- .editorconfig | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1a424d5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = false +max_line_length = 120 +tab_width = 4 From 413e13c63dbf9bce01c44634010d59275a32d96f Mon Sep 17 00:00:00 2001 From: fuyu Date: Sat, 20 Apr 2024 03:27:17 +0300 Subject: [PATCH 5/7] fix: argument parsing on rs --- bot/cogs/osu.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/bot/cogs/osu.py b/bot/cogs/osu.py index 75c50b0..049a090 100644 --- a/bot/cogs/osu.py +++ b/bot/cogs/osu.py @@ -12,6 +12,7 @@ from utils.api import * from utils.db import users from utils.enums import GameModes, Grades, Mods, filter_invalid_combos +from helpers.converters import ArgumentConverter domain = config.get("domain") @@ -45,13 +46,14 @@ def construct_avatar_url(player_id): async def get_username_and_mode( - ctx, username: str = None, mode: GameModes = GameModes.STANDARD + ctx, username: str = None, mode: GameModes = GameModes.STANDARD ): """ Returns a tuple containing the username and GameMode :return: tuple[str, GameModes] :raises ValueError: Set your username using **!setuser**. """ + if username: try: _mode = await ArgumentConverter().convert(ctx, username) @@ -66,7 +68,7 @@ async def get_username_and_mode( if not user and not username: raise ValueError("Set your username using **!setuser**.") else: - return user, mode + return user, mode or GameModes.STANDARD class Cog(commands.Cog, name="osu!"): @@ -85,17 +87,8 @@ async def setuser(self, ctx, *, username): ) @commands.command() - async def rs(self, ctx, *, parameters=''): - user, mode = parsecommand(parameters) - - if not mode: - return await ctx.send("Invalid game mode, please use any of the follow arguments: " - "-std | -rx | -ap | -taiko | -taikorx | -ctb | -ctbrx | -mania") - if not user: - users.get(ctx.author.id) - if not user: - return await ctx.send("Set your username using **!setuser**.") - + async def rs(self, ctx, username: str = None, mode: ArgumentConverter = GameModes.STANDARD): + user, mode = await get_username_and_mode(ctx, username, mode) data = await api.get( "get_player_scores", {"name": user, "scope": "recent", "limit": 1, "mode": mode.value}, @@ -242,6 +235,7 @@ def get_level(score): url=f'https://osu.{domain}/u/{player["id"]}', icon_url=f'https://osu.{domain}/static/images/flags/{player["country"].upper()}.png', ) + embed.set_thumbnail(url=construct_avatar_url(player["id"])) return await ctx.send(embed=embed) From 9f1c713b0e91753e0c60c7cb2f2090740d3a04d8 Mon Sep 17 00:00:00 2001 From: fuyu Date: Sat, 20 Apr 2024 03:27:50 +0300 Subject: [PATCH 6/7] raise `msg` from error if exists --- utils/api.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utils/api.py b/utils/api.py index f126685..c3d7f75 100644 --- a/utils/api.py +++ b/utils/api.py @@ -60,6 +60,8 @@ async def get(self, path: str, params: dict = None): if status := data.get("status"): raise ValueError(status) + elif msg := data.get("msg"): + raise ValueError(msg) else: logging.error( f"Generic error exception was raised for the following response: {data}" From 4c8ac6c3c85b7a7fad30e05472b25c97d589f2e9 Mon Sep 17 00:00:00 2001 From: fuyu Date: Sat, 20 Apr 2024 03:28:57 +0300 Subject: [PATCH 7/7] fix: converter returning `None` instead of raising `ValueError` --- helpers/converters.py | 66 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 helpers/converters.py diff --git a/helpers/converters.py b/helpers/converters.py new file mode 100644 index 0000000..2501c46 --- /dev/null +++ b/helpers/converters.py @@ -0,0 +1,66 @@ +from typing import Union +from discord.ext.commands import Converter + +from utils.enums import GameModes, Mods + +__all__ = ("ArgumentConverter",) + +game_modes = { + "osu": GameModes.STANDARD, + "std": GameModes.STANDARD, + "taiko": GameModes.TAIKO, + "catch": GameModes.CATCH, + "ctb": GameModes.CATCH, + "mania": GameModes.MANIA, +} +rx_modes = { + "osu": GameModes.RX_STANDARD, + "std": GameModes.RX_STANDARD, + "taiko": GameModes.RX_TAIKO, + "catch": GameModes.RX_CATCH, + "ctb": GameModes.RX_CATCH, +} +ap_modes = {"osu": GameModes.AP_STANDARD, "std": GameModes.AP_STANDARD} + + +class ArgumentConverter(Converter): + """ + Converts an argument into game mode or mod depending on it's value + """ + + async def convert(self, ctx, arg) -> GameModes: + """ + arg will hold all the arguments specified by the user + this, because of the game modes rely on the specified mod + such as RX; being Gamemodes.RX_STANDARD instead of Gamemodes.STANDARD + """ + + arguments = arg.split() + + if not len(arguments): + raise ValueError("No arguments were specified") + + if arg == "-rx": + return GameModes.RX_STANDARD + if arg == "-ap": + return GameModes.AP_STANDARD + if arg == "-std": + return GameModes.STANDARD + if arg == "-vn": + return GameModes.STANDARD + if arg == "-taiko": + return GameModes.TAIKO + if arg == "-taikorx": + return GameModes.RX_TAIKO + if arg == "-ctb": + return GameModes.CATCH + if arg == "-ctbrx": + return GameModes.RX_CATCH + if arg == "-mania": + return GameModes.MANIA + + if len(arguments) == 1: + if arg in game_modes: + return game_modes[arg] + + raise ValueError("Invalid game mode and/or mod") \ No newline at end of file