From 090184c1e98c85b68c14b7522537cc918e6d1a88 Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Wed, 20 Jul 2022 22:17:20 -0400 Subject: [PATCH 1/6] Tracking username length limit in data file. --- cogs/message_listener/__init__.py | 4 +++- cogs/submission/submission_views.py | 4 +++- utilities/data_storage.py | 2 +- utilities/utils.py | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cogs/message_listener/__init__.py b/cogs/message_listener/__init__.py index da7d7d3..3cfa07b 100644 --- a/cogs/message_listener/__init__.py +++ b/cogs/message_listener/__init__.py @@ -43,7 +43,9 @@ class SubmissionListener(commands.Cog, name="Message Listener"): files=[await attch.to_file() for attch in message.attachments], ) elif state == SubmissionState.NAME and message.content: - submission_objects[message.author.id]["username"] = message.content[:12] + submission_objects[message.author.id]["username"] = message.content[ + : highscores_data["username_length"] + ] embed = get_submission_embed(message.author.id) await submission_message.edit( embed=embed, diff --git a/cogs/submission/submission_views.py b/cogs/submission/submission_views.py index 301a2e9..6918a08 100644 --- a/cogs/submission/submission_views.py +++ b/cogs/submission/submission_views.py @@ -201,7 +201,9 @@ class SubmissionCreateButton(nextcord.ui.View): "boss_name": boss_name, "score": "", "category": "", - "username": interaction.user.display_name.split("|")[0][:12], + "username": interaction.user.display_name.split("|")[0][ + : highscores_data["username_length"] + ], } embed = get_submission_embed(interaction.user.id) diff --git a/utilities/data_storage.py b/utilities/data_storage.py index 7f06c94..d29ea49 100644 --- a/utilities/data_storage.py +++ b/utilities/data_storage.py @@ -28,7 +28,7 @@ def open_highscores_data(): data = json.load(file) else: # create the json object - data = {"highscore_channel_id": -1, "verification_channel_id": -1} + data = {"highscore_channel_id": -1, "verification_channel_id": -1, "username_length": 12} config: dict = open_highscores_config() for boss, categories in config["highscore_table"].items(): data[boss] = {"message_id": 0} diff --git a/utilities/utils.py b/utilities/utils.py index df5de74..8162a3a 100644 --- a/utilities/utils.py +++ b/utilities/utils.py @@ -77,9 +77,9 @@ async def submit_score( boss_category_config = highscores_config["categories"][category] - # capping to 12 characters because runescape names are 12 characters long. # Splitting on pipe. My discord has multiple names on account split by pipe. - user = user.split("|")[0][:12] + # cap length to data defined length. + user = user.split("|")[0][: highscores_data["username_length"]] # strip leading zeros and colon from score score = score.lstrip("0:") From 674ea945883c723dc15521ffe58b930288fae6c7 Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Wed, 20 Jul 2022 22:24:50 -0400 Subject: [PATCH 2/6] Pad username out to max length. --- utilities/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/utilities/utils.py b/utilities/utils.py index 8162a3a..639eeb2 100644 --- a/utilities/utils.py +++ b/utilities/utils.py @@ -30,8 +30,10 @@ def format_highscore_message(boss_name: str): for i in range(highscore_size): for key, value in boss_data["categories"].items(): if len(value) > i: - score = value[i] - ret_string += f"{i+1}: {score[0]} - {score[1]}".ljust(25, " ") + score_pair = value[i] + username = score_pair[0].ljust(highscores_data["username_length"], " ") + score = score_pair[1] + ret_string += f"{i+1}: {username} - {score}".ljust(25, " ") else: ret_string += f"{i+1}: submit your score".ljust(25, " ") ret_string += "\n" From 17c19158108c19ee2d51c113421ffa7a3a919105 Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Wed, 20 Jul 2022 22:31:39 -0400 Subject: [PATCH 3/6] Change location of approve button. Should be on right. --- cogs/submission/verification_view.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cogs/submission/verification_view.py b/cogs/submission/verification_view.py index 89599ea..eb14e23 100644 --- a/cogs/submission/verification_view.py +++ b/cogs/submission/verification_view.py @@ -10,6 +10,15 @@ class VerificationView(nextcord.ui.View): def __init__(self): super().__init__(timeout=None) + @nextcord.ui.button( + label="Deny", style=nextcord.ButtonStyle.red, custom_id="deny-button-submission" + ) + async def deny_button( + self, button: nextcord.ui.Button, interaction: nextcord.Interaction + ): # pylint: disable=unused-argument + """Button for denying score submission.""" + await interaction.message.delete() + @nextcord.ui.button( label="Approve", style=nextcord.ButtonStyle.green, custom_id="approve-button-submission" ) @@ -35,12 +44,3 @@ class VerificationView(nextcord.ui.View): except UnboundLocalError: await interaction.send("Instruct user to submit with all fields.") await interaction.message.edit(view=None) - - @nextcord.ui.button( - label="Deny", style=nextcord.ButtonStyle.red, custom_id="deny-button-submission" - ) - async def deny_button( - self, button: nextcord.ui.Button, interaction: nextcord.Interaction - ): # pylint: disable=unused-argument - """Button for denying score submission.""" - await interaction.message.delete() From 8318bf741a94dc6c93a0a7dabf74b6b64ae9dee5 Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Wed, 20 Jul 2022 22:32:59 -0400 Subject: [PATCH 4/6] Remove old TODO. --- cogs/message_listener/__init__.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/cogs/message_listener/__init__.py b/cogs/message_listener/__init__.py index 3cfa07b..f7bb558 100644 --- a/cogs/message_listener/__init__.py +++ b/cogs/message_listener/__init__.py @@ -26,9 +26,6 @@ class SubmissionListener(commands.Cog, name="Message Listener"): highscores_data["submission_channel_id"] ).fetch_message(message_id) - # TODO want to regex score to ensure it is correct. - # # here is also where score can be standardized in look - # need check if correct user and correct channel if message.channel.id == highscores_data["submission_channel_id"]: state = submission_objects[message.author.id]["submission_state"] From d711763c803a56237ededcd89ece5448f17063d1 Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Wed, 20 Jul 2022 22:35:33 -0400 Subject: [PATCH 5/6] Standardize time score format. --- utilities/utils.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/utilities/utils.py b/utilities/utils.py index 639eeb2..b31da9f 100644 --- a/utilities/utils.py +++ b/utilities/utils.py @@ -31,8 +31,17 @@ def format_highscore_message(boss_name: str): for key, value in boss_data["categories"].items(): if len(value) > i: score_pair = value[i] - username = score_pair[0].ljust(highscores_data["username_length"], " ") - score = score_pair[1] + + # pad username to max length. + username: str = score_pair[0].ljust(highscores_data["username_length"], " ") + score: str = score_pair[1] + + # standardize time score format. + if highscores_config["categories"][key]["is_time_record"]: + if score.find(":") == -1: + score = "00:" + score + if score.find(".") == -1: + score = score + " " ret_string += f"{i+1}: {username} - {score}".ljust(25, " ") else: ret_string += f"{i+1}: submit your score".ljust(25, " ") From ef17d3dc3efcdb24743f4d282c749a07fb0cb009 Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Wed, 20 Jul 2022 22:55:40 -0400 Subject: [PATCH 6/6] Made all scores line up properly. --- utilities/utils.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/utilities/utils.py b/utilities/utils.py index b31da9f..6ca917c 100644 --- a/utilities/utils.py +++ b/utilities/utils.py @@ -21,7 +21,7 @@ def format_highscore_message(boss_name: str): # Gather all categories and add to string for key, value in boss_data["categories"].items(): - ret_string += f"{key}".ljust(25, " ") + ret_string += f"{key}".ljust(26, " ") ret_string += "\n" highscore_size = highscores_config["highscore_size"] @@ -34,17 +34,21 @@ def format_highscore_message(boss_name: str): # pad username to max length. username: str = score_pair[0].ljust(highscores_data["username_length"], " ") - score: str = score_pair[1] + score: str = str(score_pair[1]) # standardize time score format. if highscores_config["categories"][key]["is_time_record"]: if score.find(":") == -1: score = "00:" + score + elif len(score.split(":", maxsplit=1)[0]) < 2: + score = "0" + score if score.find(".") == -1: + # insert 2 spaces to make up for period and ms score = score + " " - ret_string += f"{i+1}: {username} - {score}".ljust(25, " ") + line_str = f"{i+1}: {username} - " + ret_string += line_str + score.rjust(26 - len(line_str) - 1) + " " else: - ret_string += f"{i+1}: submit your score".ljust(25, " ") + ret_string += f"{i+1}: submit your score".ljust(26, " ") ret_string += "\n" return ret_string + "```"