Compare commits

...
Author SHA1 Message Date
imcompiling afc4430b31 Typo fix
build
2023-05-26 17:15:44 -04:00
imcompiling 00580460c6 update to new dates.
build
2023-05-24 23:16:45 -04:00
imcompiling 512fa23387 unbuffer output stream to view print statements in docker logs.
build
2023-05-24 23:06:51 -04:00
imcompiling 8bbe7388c6 more print statements.
build
2023-05-24 23:00:36 -04:00
imcompiling 811317fc0a Add more debug information
build
2023-05-18 20:16:58 -04:00
imcompiling f357df807b Move away from match case, don't think it worked.
build
2023-05-18 12:55:55 -04:00
imcompiling 42cfbc78eb Merge branch '2-election-cycle-class' into election-class-test
build
2023-05-18 12:49:02 -04:00
imcompiling 17cd9c1f6d Need to add classes directory to docker image.
build
2023-05-18 12:46:06 -04:00
imcompiling 99ff3fc83a Merge branch 'main' into 2-election-cycle-class 2023-05-18 12:45:43 -04:00
imcompiling f85d1aafd0 adjust test timing
build
2023-05-18 12:35:48 -04:00
imcompiling 1eaa90e9cf Correct the build workflows
build
2023-05-15 11:52:44 -04:00
imcompiling 43414abb71 try different wording
build
2023-05-15 11:51:37 -04:00
imcompiling dfece4adf6 add empty list of branches for action 2023-05-15 11:50:49 -04:00
imcompiling 90c5fea67c Correct builds. 2023-05-15 11:36:11 -04:00
imcompiling 6c9de43e73 Set up bot to do initial test. Made changes in class to make test take less time. 2023-05-15 11:34:14 -04:00
imcompiling d3858a7ba1 Added discord bot to class. 2023-05-13 12:59:40 -04:00
imcompiling f62f88113d Create initial election cycle class. 2023-05-13 10:55:36 -04:00
imcompiling 9d2382bf1d Merge branch '5-create-pipeline'
build
2023-05-06 21:04:36 -04:00
imcompiling b8b10279cb Add gitea workflow files. 2023-05-06 21:02:58 -04:00
imcompiling 9b9420d2a4 Merge branch '1-daily-loop' 2023-05-06 20:49:24 -04:00
5 changed files with 150 additions and 5 deletions
+18
View File
@@ -0,0 +1,18 @@
name: build_develop
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Docker
uses: https://github.com/papodaca/install-docker-action@v1
- name: Build Docker Image
run: docker build -t viker.cheezers.net:5000/dakiny-bot:develop .
- name: Push Docker Image
run: docker push viker.cheezers.net:5000/dakiny-bot:develop
+20
View File
@@ -0,0 +1,20 @@
name: build_latest
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Docker
uses: https://github.com/papodaca/install-docker-action@v1
- name: Build Docker Image
run: docker build -t viker.cheezers.net:5000/dakiny-bot:latest .
- name: Push Docker Image
run: docker push viker.cheezers.net:5000/dakiny-bot:latest
+2 -1
View File
@@ -11,10 +11,11 @@ COPY cogs cogs/
COPY dakiny_bot.py dakiny_bot.py
COPY requirements.txt requirements.txt
COPY config.py config.py
COPY classes classes/
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"]
CMD ["python3", "-u", "./dakiny_bot.py"]
+102
View File
@@ -0,0 +1,102 @@
"""
Contains the election cycle class
"""
from datetime import datetime, timedelta
import nextcord
from nextcord.ext import commands
class ElectionCycle:
"""
This class represents all the dates required for an election cycle along with all the functions needed to operate
the cycle.
"""
def __init__(self, election_start: datetime, term_start: datetime, term_end: datetime, bot) -> None:
"""
Generates all dates relevant to the election cycle from input election start, term start and end dates.
Args:
election_start (datetime): Date the election cycle starts.
term_start (datetime): Date the term being elected starts.
term_end (datetime): Date the term being elected ends.
bot: the discord bot instance
"""
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=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
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
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)
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")
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")
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")
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)
+8 -4
View File
@@ -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()