Compare commits

..
6 changed files with 55 additions and 29 deletions
+13 -2
View File
@@ -54,7 +54,16 @@ class SubmissionListener(commands.Cog, name="Message Listener"):
embed = submission_message.embeds[0]
embed.add_field(name="Error", value="Number record must only be number.")
else:
submission_objects[message.author.id]["score"] = message.content
score = message.content
if is_time_record:
# standardize time score format.
# add colon if its not there
if score.find(":") == -1:
score = "00:" + score
# add a 0 if there isn't 2 digits before a colon
elif len(score.split(":", maxsplit=1)[0]) < 2:
score = "0" + score
submission_objects[message.author.id]["score"] = score
embed = get_submission_embed(message.author.id)
await submission_message.edit(
@@ -65,7 +74,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,
+4 -1
View File
@@ -195,13 +195,16 @@ class SubmissionCreateButton(nextcord.ui.View):
# a user should only have 1 submission active at once.
# submitting with dummy message_id until message created
# split username on pipe.
submission_objects[interaction.user.id] = {
"message_id": 0,
"submission_state": SubmissionState.CATEGORY,
"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)
+9 -9
View File
@@ -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()
+13 -5
View File
@@ -212,8 +212,8 @@
"Spooned Log"
],
"Taraket the Necromancer": [
"Kill Count",
"Kill Time",
"Solo Kill Count",
"Solo Kill Time",
"Group Kill Count",
"Group Kill Time",
"Spooned Log"
@@ -244,8 +244,8 @@
"Spooned Log"
],
"Verak Lith": [
"Kill Count",
"Kill Time",
"Solo Kill Count",
"Solo Kill Time",
"Group Kill Count",
"Group Kill Time",
"Spooned Log"
@@ -318,10 +318,18 @@
"ascending": true,
"is_time_record": true
},
"Solo Kill Count": {
"ascending": false,
"is_time_record": false
},
"Solo Kill Time": {
"ascending": true,
"is_time_record": true
},
"Spooned Log": {
"ascending": true,
"is_time_record": false
}
},
"highscore_size": 3
}
}
+1 -1
View File
@@ -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}
+15 -11
View File
@@ -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"]
@@ -30,10 +30,21 @@ 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]
# pad username to max length.
username: str = score_pair[0].ljust(highscores_data["username_length"], " ")
score: str = str(score_pair[1])
if highscores_config["categories"][key]["is_time_record"]:
# pad score to correct length
# MM:SS.ms is 7 characters long
score = score.ljust(7, " ")
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 + "```"
@@ -77,13 +88,6 @@ 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]
# strip leading zeros and colon from score
score = score.lstrip("0:")
# create score tuple for either time or int
# define sort index
if boss_category_config["is_time_record"]: