112 lines
3.3 KiB
Python
Executable File
112 lines
3.3 KiB
Python
Executable File
import logging
|
|
from random import choice as random_choice
|
|
import pickle
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# Redacted
|
|
ID_TO_NAME: dict[int, str] = {}
|
|
|
|
# Redacted
|
|
STUDENT_IDS: set = ()
|
|
|
|
try:
|
|
ASSIGNED_ESSAY: dict = pickle.load(open("./data/assigned_essay.pkl", "rb"))
|
|
except FileNotFoundError:
|
|
logger.warning("No assigned essays found/saved, creating new dictionary.")
|
|
ASSIGNED_ESSAY: dict[int, str] = {}
|
|
with open("./data/assigned_essay.pkl", "xb"):
|
|
pass
|
|
except EOFError:
|
|
logger.warning("Assigned essays file is empty, creating new dictionary.")
|
|
ASSIGNED_ESSAY: dict[int, str] = {}
|
|
finally:
|
|
logger.debug(f"Assigned essays: {ASSIGNED_ESSAY}")
|
|
|
|
# Redacted
|
|
STUDENTS: dict[int, str] = {}
|
|
|
|
ESSAY_TOPICS = (
|
|
"why to not throw rocks during a fire drill",
|
|
"how to sit in a chair properly",
|
|
"how to keep your hands to yourself",
|
|
"how to be on time",
|
|
"how to take accountability",
|
|
"why you shouldn't be wrong (be right!!!)",
|
|
"why picking cherries is healthy for mental health",
|
|
"why losing is bad, actually",
|
|
"why you should be responsable when the bell rings and GET OUT because i'm HUNGRY",
|
|
"why you shouldn't hitlerpost in the public discord chat",
|
|
"why having your professionalism packet is essential for your future career",
|
|
"why playing rock-paper-scissors over text is very productive",
|
|
"why steak is the best food for my lunch break",
|
|
)
|
|
|
|
|
|
def get_essay_topic() -> str:
|
|
return random_choice(ESSAY_TOPICS)
|
|
|
|
|
|
def assign_essay(student_id: int, essay: str = get_essay_topic()) -> str:
|
|
"""Assigns a student an essay
|
|
|
|
Args:
|
|
student_id (int): The Discord ID of the student getting the essay.
|
|
essay (str, optional): The topic of the essay being assigned. Defaults to get_essay_topic().
|
|
|
|
Raises:
|
|
ValueError: If the student ID is not in STUDENT_IDS.
|
|
|
|
Returns:
|
|
str: The topic of the essay assigned.
|
|
"""
|
|
if student_id in STUDENT_IDS:
|
|
ASSIGNED_ESSAY[student_id] = essay
|
|
pickle.dump(ASSIGNED_ESSAY, open("./data/assigned_essay.pkl", "wb"))
|
|
return essay
|
|
else:
|
|
raise ValueError(f"Student ID {student_id} is not a valid student ID.")
|
|
|
|
|
|
def get_essay(student_id: int = None) -> str:
|
|
"""Gets the assigned essay for a student
|
|
|
|
Args:
|
|
student_id (int): The Discord ID of the student to get the essay for.
|
|
|
|
Raises:
|
|
ValueError: If the student ID is not in STUDENT_IDS.
|
|
|
|
Returns:
|
|
str: The topic of the essay assigned to the student.
|
|
"""
|
|
if student_id:
|
|
if student_id in STUDENT_IDS:
|
|
return ASSIGNED_ESSAY.get(student_id, "No essay assigned.")
|
|
else:
|
|
essays: str = ""
|
|
for essay in ASSIGNED_ESSAY:
|
|
essays += f"<@{essay}>: {ASSIGNED_ESSAY[essay]}\n"
|
|
return essays if essays else "No essays assigned."
|
|
|
|
|
|
def clear_essay(student_id):
|
|
"""Clears an assigned essay from a student
|
|
|
|
Args:
|
|
student_id (int): The Discord ID of the student to clear the essay from.
|
|
|
|
Raises:
|
|
ValueError: If the student ID is not in STUDENT_IDS.
|
|
"""
|
|
if student_id in STUDENT_IDS:
|
|
ASSIGNED_ESSAY.pop(student_id)
|
|
pickle.dump(ASSIGNED_ESSAY, open("./data/assigned_essay.pkl", "wb"))
|
|
else:
|
|
raise ValueError(f"Student ID {student_id} is not a valid student ID.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print(get_essay())
|
|
|