diff --git a/.gitea/workflows/build_latest.yml b/.gitea/workflows/build_latest.yml index 34d54b4..9e06f62 100644 --- a/.gitea/workflows/build_latest.yml +++ b/.gitea/workflows/build_latest.yml @@ -1,4 +1,4 @@ -name: build_develop +name: build_latest on: push: diff --git a/Dockerfile b/Dockerfile index 7055d98..b545f5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,4 +18,4 @@ RUN pip install -r requirements.txt # remove build deps that aren't needed to run # RUN apt-get -y remove python3-dev build-essential && apt-get -y autoremove -CMD ["python3", "./dakiny_bot.py"] \ No newline at end of file +CMD ["python3", "-u", "./dakiny_bot.py"] \ No newline at end of file diff --git a/classes/election_cycle.py b/classes/election_cycle.py index 97769d1..48d412f 100644 --- a/classes/election_cycle.py +++ b/classes/election_cycle.py @@ -4,6 +4,7 @@ Contains the election cycle class from datetime import datetime, timedelta +import nextcord from nextcord.ext import commands @@ -26,48 +27,76 @@ class ElectionCycle: self._election_start: datetime = election_start self._term_start: datetime = term_start self._term_end: datetime = term_end # might not be needed - self._voting_start: datetime = self._election_start + timedelta(days=7) - self._voting_end: datetime = self._voting_start + timedelta(days=7) + self._voting_start: datetime = self._election_start + timedelta(days=1) + self._voting_end: datetime = self._voting_start + timedelta(days=1) self._highcouncil_election: datetime = self._voting_end + timedelta(days=1) self._bot: commands.Bot = bot - def check_date(self) -> None: + async def check_date(self) -> None: """ Function checks current date to see if something needs to be run. """ today = datetime.today() + print("checking the date") # check all dates if action is needed - match today.date(): - case self._election_start.date(): - self.election_start_action() - case self._voting_start.date(): - self.voting_end_action() - case self._voting_end.date(): - self.voting_end_action() - case self._highcouncil_election.date(): - self.highcouncil_election_action() + if today.date() == self._election_start.date(): + await self.election_start_action() + elif today.date() == self._voting_start.date(): + await self.voting_end_action() + elif today.date() == self._voting_end.date(): + await self.voting_end_action() + elif today.date() == self._highcouncil_election.date(): + await self.highcouncil_election_action() + elif today.date() == self._term_start.date(): + await self.term_start_action() + elif today.date() == self._term_end.date(): + await self.term_end_action() + else: + print("today was not a special date") + print(today) - def election_start_action(self) -> None: + async def election_start_action(self) -> None: """ Performs required actions for when the election cycle starts. """ print("election cycle has started") + await self.message_me("election cycle has started") - def voting_start_action(self) -> None: + async def voting_start_action(self) -> None: """ Performs required actions for when voting for candidates starts. """ print("Voting has started") + await self.message_me("Voting has started") - def voting_end_action(self) -> None: + async def voting_end_action(self) -> None: """ Performs required actions for when voting time has ended. """ print("voting has ended") + await self.message_me("voting has ended") - def highcouncil_election_action(self) -> None: + async def highcouncil_election_action(self) -> None: """ Performs required actions for when the highcouncil is elected. """ print("Highcouncil election has started.") + await self.message_me("Highcouncil election has started.") + + async def term_start_action(self) -> None: + msg: str = "the term has started" + print(msg) + self.message_me(msg) + + async def term_end_action(self): + msg: str = "the term has ended" + print(msg) + self.message_me(msg) + + async def message_me(self, msg: str): + """ + message a string to me + """ + imcompiling: nextcord.User = await self._bot.fetch_user(206602713511886849) + await imcompiling.send(msg) diff --git a/cogs/loops/daily_loop.py b/cogs/loops/daily_loop.py index 2bec4ce..486c355 100644 --- a/cogs/loops/daily_loop.py +++ b/cogs/loops/daily_loop.py @@ -2,11 +2,13 @@ _summary_ """ -import nextcord +from datetime import datetime, time + from nextcord.ext import commands, tasks -from datetime import time from pytz import timezone +from classes.election_cycle import ElectionCycle + class DailyLoop(commands.Cog, name="Daily Loop"): """ @@ -15,12 +17,14 @@ class DailyLoop(commands.Cog, name="Daily Loop"): def __init__(self, bot: commands.Bot) -> None: self.bot = bot + self.election = ElectionCycle(datetime(2023, 5, 25), datetime(2023, 5, 29), datetime(2023, 5, 30), self.bot) @commands.Cog.listener() async def on_ready(self): """ Starts the loop when bot is ready. """ + print("on ready") await self.bot.wait_until_ready() # pylint doesn't recognize that periodic_update_guild_data is subclassed from tasks.loop. await self.do_thing.start() # pylint: disable=no-member @@ -28,5 +32,5 @@ class DailyLoop(commands.Cog, name="Daily Loop"): @tasks.loop(time=time(hour=0, tzinfo=timezone("GMT"))) async def do_thing(self): """ """ - imcompiling: nextcord.User = await self.bot.fetch_user(206602713511886849) - await imcompiling.send("its reset in runescape") + print("loop") + await self.election.check_date()