Compare commits
16
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
afc4430b31 | ||
|
|
00580460c6 | ||
|
|
512fa23387 | ||
|
|
8bbe7388c6 | ||
|
|
811317fc0a | ||
|
|
f357df807b | ||
|
|
42cfbc78eb | ||
|
|
17cd9c1f6d | ||
|
|
99ff3fc83a | ||
|
|
f85d1aafd0 | ||
|
|
43414abb71 | ||
|
|
dfece4adf6 | ||
|
|
90c5fea67c | ||
|
|
6c9de43e73 | ||
|
|
d3858a7ba1 | ||
|
|
f62f88113d |
@@ -1,4 +1,4 @@
|
|||||||
name: build_develop
|
name: build_latest
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
|||||||
@@ -137,5 +137,3 @@ deleted_backups/
|
|||||||
highscores_data/
|
highscores_data/
|
||||||
TODO.txt
|
TODO.txt
|
||||||
sql_tester.py
|
sql_tester.py
|
||||||
conf
|
|
||||||
outputs
|
|
||||||
|
|||||||
+2
-2
@@ -11,11 +11,11 @@ COPY cogs cogs/
|
|||||||
COPY dakiny_bot.py dakiny_bot.py
|
COPY dakiny_bot.py dakiny_bot.py
|
||||||
COPY requirements.txt requirements.txt
|
COPY requirements.txt requirements.txt
|
||||||
COPY config.py config.py
|
COPY config.py config.py
|
||||||
COPY config.yml config.yml
|
COPY classes classes/
|
||||||
|
|
||||||
RUN pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
# remove build deps that aren't needed to run
|
# remove build deps that aren't needed to run
|
||||||
# RUN apt-get -y remove python3-dev build-essential && apt-get -y autoremove
|
# RUN apt-get -y remove python3-dev build-essential && apt-get -y autoremove
|
||||||
|
|
||||||
CMD ["python3", "./dakiny_bot.py"]
|
CMD ["python3", "-u", "./dakiny_bot.py"]
|
||||||
@@ -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)
|
||||||
@@ -2,11 +2,13 @@
|
|||||||
_summary_
|
_summary_
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import nextcord
|
from datetime import datetime, time
|
||||||
|
|
||||||
from nextcord.ext import commands, tasks
|
from nextcord.ext import commands, tasks
|
||||||
from datetime import time
|
|
||||||
from pytz import timezone
|
from pytz import timezone
|
||||||
|
|
||||||
|
from classes.election_cycle import ElectionCycle
|
||||||
|
|
||||||
|
|
||||||
class DailyLoop(commands.Cog, name="Daily Loop"):
|
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:
|
def __init__(self, bot: commands.Bot) -> None:
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
self.election = ElectionCycle(datetime(2023, 5, 25), datetime(2023, 5, 29), datetime(2023, 5, 30), self.bot)
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
"""
|
"""
|
||||||
Starts the loop when bot is ready.
|
Starts the loop when bot is ready.
|
||||||
"""
|
"""
|
||||||
|
print("on ready")
|
||||||
await self.bot.wait_until_ready()
|
await self.bot.wait_until_ready()
|
||||||
# pylint doesn't recognize that periodic_update_guild_data is subclassed from tasks.loop.
|
# pylint doesn't recognize that periodic_update_guild_data is subclassed from tasks.loop.
|
||||||
await self.do_thing.start() # pylint: disable=no-member
|
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")))
|
@tasks.loop(time=time(hour=0, tzinfo=timezone("GMT")))
|
||||||
async def do_thing(self):
|
async def do_thing(self):
|
||||||
""" """
|
""" """
|
||||||
imcompiling: nextcord.User = await self.bot.fetch_user(206602713511886849)
|
print("loop")
|
||||||
await imcompiling.send("its reset in runescape")
|
await self.election.check_date()
|
||||||
|
|||||||
@@ -1,28 +1,8 @@
|
|||||||
from dataclasses import dataclass
|
import os
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
|
from dotenv.main import load_dotenv
|
||||||
|
|
||||||
@dataclass
|
load_dotenv()
|
||||||
class Params:
|
|
||||||
voting_emote_id: int
|
|
||||||
annoucement_channel_id: int
|
|
||||||
archive_channel_group_id: int
|
|
||||||
clan_council_role_id: int
|
|
||||||
clan_council_elect_role_id: int
|
|
||||||
discord_token: str
|
|
||||||
|
|
||||||
|
# Discord config
|
||||||
@dataclass
|
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN", "")
|
||||||
class ElectionCycle:
|
|
||||||
election_start: datetime
|
|
||||||
voting_start: datetime
|
|
||||||
voting_end: datetime
|
|
||||||
term_start: datetime
|
|
||||||
term_end: datetime
|
|
||||||
name: str
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class DakinyConfig:
|
|
||||||
params: Params
|
|
||||||
cycles: list[ElectionCycle]
|
|
||||||
|
|||||||
+3
-11
@@ -1,19 +1,12 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
|
|
||||||
import hydra
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from hydra.core.config_store import ConfigStore
|
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
from config import DakinyConfig
|
import config
|
||||||
|
|
||||||
cs = ConfigStore.instance()
|
|
||||||
cs.store(name="dakiny_config", node=DakinyConfig)
|
|
||||||
|
|
||||||
|
|
||||||
@hydra.main(config_path="conf", config_name="config")
|
def main():
|
||||||
def main(cfg: DakinyConfig):
|
|
||||||
# Allows privledged intents for monitoring members joining, roles editing, and role assignments
|
# Allows privledged intents for monitoring members joining, roles editing, and role assignments
|
||||||
# These need to be enabled in the developer portal as well
|
# These need to be enabled in the developer portal as well
|
||||||
intents = nextcord.Intents.default()
|
intents = nextcord.Intents.default()
|
||||||
@@ -40,9 +33,8 @@ def main(cfg: DakinyConfig):
|
|||||||
print(f"{bot.user.name} has connected to Discord!")
|
print(f"{bot.user.name} has connected to Discord!")
|
||||||
|
|
||||||
# Run Discord bot
|
# Run Discord bot
|
||||||
bot.run(cfg.params.discord_token)
|
bot.run(config.DISCORD_TOKEN)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.argv.append("hydra.job.chdir=False")
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
nextcord==2.4.2
|
nextcord==2.4.2
|
||||||
python-dotenv==1.0.0
|
python-dotenv==1.0.0
|
||||||
pytz==2022.7.1
|
pytz==2022.7.1
|
||||||
hydra-core==1.3.2
|
|
||||||
Reference in New Issue
Block a user