Files
dakiny-bot/classes/message_builder.py
T

60 lines
2.0 KiB
Python

"""
Contains the MessageBuilder class.
"""
from datetime import datetime
from config import DakinyConfig
from utils import get_datetime
class MessageBuilder:
"""
Contains all the announcements that the bot will send regarding elections.
"""
def __init__(self, config: DakinyConfig, cycle: int) -> None:
self.config = config
self.cycle = cycle
def build_election_announcement(self) -> list[str]:
"""
Builds the messages to announce the election is starting.
Returns:
list[str]: A list of message contents in the correct order.
"""
with open("bot_messages/election_announcement.txt", mode="r", encoding="utf8") as file:
message = file.read()
election_start: datetime = get_datetime(self.config.election_cycles[self.cycle].election_start)
term_start: datetime = get_datetime(self.config.election_cycles[self.cycle].term_start)
message = message.format(
clan_council_id=self.config.params.clan_council_role_id,
high_council_id=self.config.params.high_council_role_id,
election_start_date=election_start.strftime("%B %d"),
term_start_date=term_start.strftime("%B %d"),
)
# TODO make sure to split the message on message break.
def build_vote_start(self) -> str:
"""
Builds the voting start message out of template and configurations.
Returns:
str: Message to send
"""
with open("bot_messages/vote_start.txt", mode="r", encoding="utf8") as file:
message = file.read()
vote_end: datetime = get_datetime(self.config.election_cycles[self.cycle].voting_end)
return message.format(
clan_member_id=self.config.params.clan_member_role_id,
voting_emote_id=self.config.params.voting_emote_id,
voting_end_date=vote_end.strftime("%B %d"),
voting_end_day=vote_end.strftime("%A"),
)