Convert bot to use a submissions table.
This commit is contained in:
+15
-154
@@ -2,6 +2,7 @@
|
||||
Contains classes and enum for tracking data on submissions.
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum
|
||||
|
||||
from nextcord import Embed
|
||||
@@ -10,8 +11,10 @@ from sqlalchemy.orm import Session
|
||||
|
||||
# pylint: disable=import-error
|
||||
from utilities.sql_data_classes import Category, CategoryGroup, engine
|
||||
from utilities.utils import score_float_to_str
|
||||
|
||||
|
||||
# TODO use the fancy enums
|
||||
class SubmissionState(Enum):
|
||||
"""
|
||||
Enum for which state a submission is in
|
||||
@@ -25,158 +28,23 @@ class SubmissionState(Enum):
|
||||
VERIFY = 6
|
||||
|
||||
|
||||
# TODO remake into a data class
|
||||
@dataclass
|
||||
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, 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_id: int = 0
|
||||
self._guild_id: int = guild_id
|
||||
self._message_id: int = 0
|
||||
self._score: str = ""
|
||||
self._submission_state: SubmissionState = SubmissionState.CATEGORY
|
||||
self._group_id: int = group_id
|
||||
self._username: str = username
|
||||
category_id: int = field(init=False, default=0)
|
||||
group_id: int
|
||||
guild_id: int
|
||||
is_time_record: bool = field(init=False, default=False)
|
||||
message_id: int = field(init=False, default=0)
|
||||
score: float = field(init=False, default=0.0)
|
||||
submission_state: SubmissionState = field(init=False, default=SubmissionState.CATEGORY)
|
||||
username: str
|
||||
|
||||
@property
|
||||
def category_id(self) -> int:
|
||||
"""
|
||||
Getter for Submission's Category id.
|
||||
|
||||
Returns:
|
||||
int: Category id.
|
||||
"""
|
||||
return self._category_id
|
||||
|
||||
@category_id.setter
|
||||
def category_id(self, category: int) -> None:
|
||||
"""
|
||||
Setter for Submission's Category id.
|
||||
|
||||
Args:
|
||||
category (int): Category id
|
||||
"""
|
||||
self._category_id = category
|
||||
|
||||
@property
|
||||
def guild_id(self) -> int:
|
||||
"""
|
||||
Getter for guild id Submission is happening in. Will not change.
|
||||
|
||||
Returns:
|
||||
int: guild id
|
||||
"""
|
||||
return self._guild_id
|
||||
|
||||
@property
|
||||
def message_id(self) -> int:
|
||||
"""
|
||||
Getter for message id that Submission has a view on.
|
||||
|
||||
Returns:
|
||||
int: message id
|
||||
"""
|
||||
return self._message_id
|
||||
|
||||
@message_id.setter
|
||||
def message_id(self, m_id: int) -> None:
|
||||
"""
|
||||
Setter for message id that Submission has a view on.
|
||||
|
||||
Args:
|
||||
m_id (int): message id
|
||||
"""
|
||||
self._message_id = m_id
|
||||
|
||||
@property
|
||||
def score(self) -> str:
|
||||
"""
|
||||
Getter for score.
|
||||
|
||||
Returns:
|
||||
str: score
|
||||
"""
|
||||
return self._score
|
||||
|
||||
@score.setter
|
||||
def score(self, score: str) -> None:
|
||||
"""
|
||||
Setter for score.
|
||||
|
||||
Args:
|
||||
score (str): score
|
||||
"""
|
||||
self._score = score
|
||||
|
||||
@property
|
||||
def submission_state(self) -> SubmissionState:
|
||||
"""
|
||||
Getter for state Submission is in.
|
||||
|
||||
Returns:
|
||||
SubmissionState: State the Submission is in
|
||||
"""
|
||||
return self._submission_state
|
||||
|
||||
@submission_state.setter
|
||||
def submission_state(self, state: SubmissionState) -> None:
|
||||
"""
|
||||
Setter for state Submission is in.
|
||||
|
||||
Args:
|
||||
state (SubmissionState): State to change to
|
||||
"""
|
||||
self._submission_state = state
|
||||
|
||||
@property
|
||||
def group_id(self) -> str:
|
||||
"""
|
||||
Getter for group Submission is for.
|
||||
|
||||
Returns:
|
||||
str: group id
|
||||
"""
|
||||
return self._group_id
|
||||
|
||||
@group_id.setter
|
||||
def group_id(self, table: str) -> None:
|
||||
"""
|
||||
Getter for table Submission is for.
|
||||
|
||||
Args:
|
||||
table (str): group id
|
||||
"""
|
||||
self._group_id = table
|
||||
|
||||
@property
|
||||
def username(self) -> str:
|
||||
"""
|
||||
Getter for Submission owner's username.
|
||||
|
||||
Returns:
|
||||
str: Submission owner's username
|
||||
"""
|
||||
return self._username
|
||||
|
||||
@username.setter
|
||||
def username(self, username: str) -> None:
|
||||
"""
|
||||
Setter for Submission owner's username.
|
||||
|
||||
Args:
|
||||
username (str): Submission owner's username
|
||||
"""
|
||||
self._username = username
|
||||
|
||||
def get_embeds(self) -> "list[Embed]":
|
||||
def get_embed(self) -> Embed:
|
||||
"""Creates an embed based off of the submission state and fields filled out."""
|
||||
state: SubmissionState = self.submission_state
|
||||
|
||||
@@ -210,16 +78,9 @@ class Submission:
|
||||
)
|
||||
embed.add_field(name="Category", value=session.scalar(stmt), inline=False)
|
||||
if self.score:
|
||||
embed.add_field(name="Score", value=self.score, inline=False)
|
||||
embed.add_field(name="Score", value=score_float_to_str(self.score, self.is_time_record), inline=False)
|
||||
|
||||
embeds = [embed]
|
||||
|
||||
if state is SubmissionState.VERIFY:
|
||||
embed = Embed(title="Bot Information", description="Please disregard.")
|
||||
embed.add_field(name="GroupId", value=self.group_id)
|
||||
embed.add_field(name="CategoryId", value=self.category_id)
|
||||
embeds.append(embed)
|
||||
return embeds
|
||||
return embed
|
||||
|
||||
|
||||
class SubmissionMap:
|
||||
|
||||
Reference in New Issue
Block a user