Compare commits
1
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
|
||||
|
||||
@@ -26,15 +29,34 @@ 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"]
|
||||
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,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user