diff --git a/src/anonymous.py b/src/anonymous.py index c591893..85b6793 100644 --- a/src/anonymous.py +++ b/src/anonymous.py @@ -1,10 +1,12 @@ from __future__ import annotations +from dataclasses import dataclass from typing import TYPE_CHECKING, Literal import discord -from .email import send_email +from .constants import SCHWARTZ_EMAIL +from .email import Email from .views import MILBotModal, MILBotView if TYPE_CHECKING: @@ -14,6 +16,27 @@ IntendedTargets = Literal["schwartz", "operations", "leaders"] +@dataclass +class SchwartzAnonymousEmail(Email): + def __init__(self, report: str): + html = f"""A new anonymous report has been submitted. The report is as follows: + +
{report}
+ + Replies to this email will not be received. Please address any concerns with the appropriate leadership team.""" + text = f"""A new anonymous report has been submitted. The report is as follows: + + {report} + + Replies to this email will not be received. Please address any concerns with the appropriate leadership team.""" + super().__init__( + receiver_emails=[SCHWARTZ_EMAIL], + subject="New Anonymous Report Received", + html=html, + text=text, + ) + + class AnonymousReportModal(MILBotModal): report = discord.ui.TextInput( @@ -36,22 +59,7 @@ async def on_submit(self, interaction: discord.Interaction): ) embed.set_footer(text="Submitted by an anonymous user") if self.target == "schwartz": - html = f"""A new anonymous report has been submitted. The report is as follows: - -
{self.report.value}
- - Replies to this email will not be received. Please address any concerns with the appropriate leadership team.""" - text = f"""A new anonymous report has been submitted. The report is as follows: - - {self.report.value} - - Replies to this email will not be received. Please address any concerns with the appropriate leadership team.""" - await send_email( - "ems@ufl.edu", - "New Anonymous Report Received", - html, - text, - ) + await SchwartzAnonymousEmail(self.report.value).send() elif self.target == "operations": await self.bot.operations_leaders_channel.send(embed=embed) elif self.target == "leaders": diff --git a/src/email.py b/src/email.py index 1d9aaf4..41941d5 100644 --- a/src/email.py +++ b/src/email.py @@ -77,14 +77,3 @@ async def send(self) -> None: message.as_string(), ) await smtp_server.quit() - - -async def send_email(receiver_email, subject, html, text) -> bool: - email = Email( - receiver_emails=[receiver_email], - subject=subject, - html=html, - text=text, - ) - await email.send() - return True diff --git a/src/verification.py b/src/verification.py index 647bbfa..1c9e047 100644 --- a/src/verification.py +++ b/src/verification.py @@ -9,7 +9,7 @@ import discord -from .email import send_email +from .email import Email from .roles import TeamRolesView from .views import MILBotModal, MILBotView @@ -26,6 +26,36 @@ class VerificationCandidate: code: int +@dataclass +class VerificationEmail(Email): + def _generate_message(self, code: int) -> tuple[str, str]: + return ( + f""" + + + + Welcome to the Machine Intelligence Laboratory Discord server!

+ Your verification code is: {code}

+ Thanks,
Machine Intelligence Laboratory + + """, + f"""Welcome to the Machine Intelligence Laboratory Discord server! + Your verification code is: {code} + Thanks, + Machine Intelligence Laboratory + """, + ) + + def __init__(self, email: str, code: int): + html, text = self._generate_message(code) + super().__init__( + receiver_emails=[email], + subject="MIL Discord Verification Code", + html=html, + text=text, + ) + + class Verifier: def _generate_new_code(self) -> int: """ @@ -49,30 +79,8 @@ async def send_verification_email(self, candidate: VerificationCandidate): """ Sends a verification email to the candidate. """ - messages = self._generate_message(candidate.code) - await send_email( - candidate.email, - "MIL Discord Verification Code", - *messages, - ) - - def _generate_message(self, code: int) -> tuple[str, str]: - return ( - f""" - - - - Welcome to the Machine Intelligence Laboratory Discord server!

- Your verification code is: {code}

- Thanks,
Machine Intelligence Laboratory - - """, - f"""Welcome to the Machine Intelligence Laboratory Discord server! - Your verification code is: {code} - Thanks, - Machine Intelligence Laboratory - """, - ) + email = VerificationEmail(candidate.email, candidate.code) + await email.send() class VerificationCodeModal(MILBotModal):