Change submission to use database. Also use ids rather than names.
This commit is contained in:
+29
-27
@@ -4,8 +4,10 @@ Contains classes and enum for tracking data on submissions.
|
||||
|
||||
from enum import Enum
|
||||
|
||||
|
||||
from nextcord import Embed
|
||||
from sqlalchemy import select
|
||||
|
||||
from highscores import session, Category
|
||||
|
||||
|
||||
class SubmissionState(Enum):
|
||||
@@ -21,45 +23,46 @@ class SubmissionState(Enum):
|
||||
VERIFY = 6
|
||||
|
||||
|
||||
# TODO remake into a data class
|
||||
class Submission:
|
||||
"""
|
||||
Class for an individual submission. Contains submission information such as
|
||||
guild id, message id, table, category, username, score and submission state.
|
||||
"""
|
||||
|
||||
def __init__(self, guild_id: int, table: str, username: str) -> None:
|
||||
def __init__(self, guild_id: int, group_id: int, username: str) -> None:
|
||||
"""
|
||||
Default constructor for Submission. Just need to know guild_id, table, and username.
|
||||
Score and category are defaulted at empty, message id is 0, and submission state
|
||||
is SubmissionState.CATEGORY.
|
||||
"""
|
||||
self._category: str = ""
|
||||
self._category_id: int = 0
|
||||
self._guild_id: int = guild_id
|
||||
self._message_id: int = 0
|
||||
self._score: str = ""
|
||||
self._submission_state: SubmissionState = SubmissionState.CATEGORY
|
||||
self._table: str = table
|
||||
self._group_id: int = group_id
|
||||
self._username: str = username
|
||||
|
||||
@property
|
||||
def category(self) -> str:
|
||||
def category_id(self) -> int:
|
||||
"""
|
||||
Getter for Submission's Category name.
|
||||
Getter for Submission's Category id.
|
||||
|
||||
Returns:
|
||||
str: Category name.
|
||||
int: Category id.
|
||||
"""
|
||||
return self._category
|
||||
return self._category_id
|
||||
|
||||
@category.setter
|
||||
def category(self, category: str) -> None:
|
||||
@category_id.setter
|
||||
def category_id(self, category: int) -> None:
|
||||
"""
|
||||
Setter for Submission's Category name.
|
||||
Setter for Submission's Category id.
|
||||
|
||||
Args:
|
||||
category (str): Category name
|
||||
category (int): Category id
|
||||
"""
|
||||
self._category = category
|
||||
self._category_id = category
|
||||
|
||||
@property
|
||||
def guild_id(self) -> int:
|
||||
@@ -132,24 +135,24 @@ class Submission:
|
||||
self._submission_state = state
|
||||
|
||||
@property
|
||||
def table(self) -> str:
|
||||
def group_id(self) -> str:
|
||||
"""
|
||||
Getter for table Submission is for.
|
||||
Getter for group Submission is for.
|
||||
|
||||
Returns:
|
||||
str: table name
|
||||
str: group id
|
||||
"""
|
||||
return self._table
|
||||
return self._group_id
|
||||
|
||||
@table.setter
|
||||
def table(self, table: str) -> None:
|
||||
@group_id.setter
|
||||
def group_id(self, table: str) -> None:
|
||||
"""
|
||||
Getter for table Submission is for.
|
||||
|
||||
Args:
|
||||
table (str): table name
|
||||
table (str): group id
|
||||
"""
|
||||
self._table = table
|
||||
self._group_id = table
|
||||
|
||||
@property
|
||||
def username(self) -> str:
|
||||
@@ -182,9 +185,7 @@ class Submission:
|
||||
elif state is SubmissionState.PROOF:
|
||||
description = "Step 3: Submit your proof!"
|
||||
elif state is SubmissionState.NAME:
|
||||
description = (
|
||||
"Step 4 (Optional): Change name on submission! (proceed to next if skipping)"
|
||||
)
|
||||
description = "Step 4 (Optional): Change name on submission! (proceed to next if skipping)"
|
||||
elif state is SubmissionState.SUBMIT:
|
||||
description = "Step 5: Submit if everything looks correct!"
|
||||
elif state is SubmissionState.VERIFY:
|
||||
@@ -192,9 +193,10 @@ class Submission:
|
||||
|
||||
embed = Embed(title="Highscores Submission", description=description)
|
||||
embed.add_field(name="User Name", value=self.username, inline=False)
|
||||
embed.add_field(name="Table", value=self.table, inline=False)
|
||||
if self.category:
|
||||
embed.add_field(name="Category", value=self.category, inline=False)
|
||||
embed.add_field(name="Table", value=self.group_id, inline=False)
|
||||
if self.category_id:
|
||||
stmt = select(Category.CategoryName).where(Category.CategoryId == self.category_id)
|
||||
embed.add_field(name="Category", value=session.scalar(stmt), inline=False)
|
||||
if self.score:
|
||||
embed.add_field(name="Score", value=self.score, inline=False)
|
||||
return embed
|
||||
|
||||
Reference in New Issue
Block a user