Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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,30 @@ 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:
|
||||
submission_objects[message.author.id]["score"] = message.content
|
||||
embed = get_submission_embed(message.author.id)
|
||||
|
||||
await submission_message.edit(
|
||||
embed=embed,
|
||||
)
|
||||
@@ -40,9 +65,7 @@ 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[
|
||||
: highscores_data["username_length"]
|
||||
]
|
||||
submission_objects[message.author.id]["username"] = message.content[:12]
|
||||
embed = get_submission_embed(message.author.id)
|
||||
await submission_message.edit(
|
||||
embed=embed,
|
||||
|
||||
@@ -201,9 +201,7 @@ class SubmissionCreateButton(nextcord.ui.View):
|
||||
"boss_name": boss_name,
|
||||
"score": "",
|
||||
"category": "",
|
||||
"username": interaction.user.display_name.split("|")[0][
|
||||
: highscores_data["username_length"]
|
||||
],
|
||||
"username": interaction.user.display_name.split("|")[0][:12],
|
||||
}
|
||||
|
||||
embed = get_submission_embed(interaction.user.id)
|
||||
|
||||
@@ -10,15 +10,6 @@ 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"
|
||||
)
|
||||
@@ -44,3 +35,12 @@ 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()
|
||||
|
||||
@@ -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, "username_length": 12}
|
||||
data = {"highscore_channel_id": -1, "verification_channel_id": -1}
|
||||
config: dict = open_highscores_config()
|
||||
for boss, categories in config["highscore_table"].items():
|
||||
data[boss] = {"message_id": 0}
|
||||
|
||||
+6
-21
@@ -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(26, " ")
|
||||
ret_string += f"{key}".ljust(25, " ")
|
||||
ret_string += "\n"
|
||||
|
||||
highscore_size = highscores_config["highscore_size"]
|
||||
@@ -30,25 +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_pair = value[i]
|
||||
|
||||
# pad username to max length.
|
||||
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 + " "
|
||||
line_str = f"{i+1}: {username} - "
|
||||
ret_string += line_str + score.rjust(26 - len(line_str) - 1) + " "
|
||||
score = value[i]
|
||||
ret_string += f"{i+1}: {score[0]} - {score[1]}".ljust(25, " ")
|
||||
else:
|
||||
ret_string += f"{i+1}: submit your score".ljust(26, " ")
|
||||
ret_string += f"{i+1}: submit your score".ljust(25, " ")
|
||||
ret_string += "\n"
|
||||
|
||||
return ret_string + "```"
|
||||
@@ -92,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.
|
||||
# cap length to data defined length.
|
||||
user = user.split("|")[0][: highscores_data["username_length"]]
|
||||
user = user.split("|")[0][:12]
|
||||
|
||||
# strip leading zeros and colon from score
|
||||
score = score.lstrip("0:")
|
||||
|
||||
Reference in New Issue
Block a user