Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a261d56fc | ||
|
|
4ee2280565 | ||
|
|
a24900a957 | ||
|
|
31fa0b50a3 |
@@ -2,11 +2,14 @@
|
||||
Defines cog for on message listener.
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
from nextcord.ext import commands
|
||||
import nextcord
|
||||
|
||||
from cogs.submission.submission_views import SubmissionState # pylint: disable=import-error
|
||||
from cogs.submission.submission_views import get_submission_embed # pylint: disable=import-error
|
||||
from highscores import highscores_config # pylint: disable=import-error
|
||||
from highscores import highscores_data # pylint: disable=import-error
|
||||
from highscores import submission_objects # pylint: disable=import-error
|
||||
|
||||
@@ -30,8 +33,39 @@ class SubmissionListener(commands.Cog, name="Message Listener"):
|
||||
if message.channel.id == highscores_data["submission_channel_id"]:
|
||||
state = submission_objects[message.author.id]["submission_state"]
|
||||
if state == SubmissionState.SCORE and message.content:
|
||||
submission_objects[message.author.id]["score"] = message.content
|
||||
embed = get_submission_embed(message.author.id)
|
||||
|
||||
# check with regex if score matches correctly
|
||||
is_time_record = highscores_config["categories"][
|
||||
submission_objects[message.author.id]["category"]
|
||||
]["is_time_record"]
|
||||
|
||||
time_regex = re.search(
|
||||
"([0-9]{2}:)?[0-9]{2}(\.[0-9])?", # pylint: disable=anomalous-backslash-in-string
|
||||
message.content,
|
||||
)
|
||||
int_regex = re.search("[0-9]+", message.content)
|
||||
if time_regex is None and is_time_record:
|
||||
embed = submission_message.embeds[0]
|
||||
embed.add_field(
|
||||
name="Error",
|
||||
value="Time record must follow format MM:SS.ms or SS.ms or SS.",
|
||||
)
|
||||
elif int_regex is None and not is_time_record:
|
||||
embed = submission_message.embeds[0]
|
||||
embed.add_field(name="Error", value="Number record must only be number.")
|
||||
else:
|
||||
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(
|
||||
embed=embed,
|
||||
)
|
||||
|
||||
@@ -195,6 +195,7 @@ 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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
+4
-15
@@ -36,15 +36,11 @@ def format_highscore_message(boss_name: str):
|
||||
username: str = score_pair[0].ljust(highscores_data["username_length"], " ")
|
||||
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 + " "
|
||||
# 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:
|
||||
@@ -92,13 +88,6 @@ async def submit_score(
|
||||
|
||||
boss_category_config = highscores_config["categories"][category]
|
||||
|
||||
# Splitting on pipe. My discord has multiple names on account split by pipe.
|
||||
# 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:")
|
||||
|
||||
# create score tuple for either time or int
|
||||
# define sort index
|
||||
if boss_category_config["is_time_record"]:
|
||||
|
||||
Reference in New Issue
Block a user