Compare commits

..
Author SHA1 Message Date
renovate-bot 9f6dc80009 Update dependency pandas to v3 2026-07-26 00:01:53 +00:00
renovate-bot aaef1f249f Update ghcr.io/astral-sh/uv Docker tag to v0.9.28
build_latest / build (push) Successful in 47s
2026-02-01 00:01:18 +00:00
renovate-bot 4936013697 Update dependency setuptools to <80.10.3,>=80.10.2
build_latest / build (push) Has been cancelled
2026-02-01 00:01:11 +00:00
renovate-bot 945f5766d5 Update dependency setuptools to <80.10.2,>=80.10.1
build_latest / build (push) Successful in 1m25s
2026-01-25 00:01:57 +00:00
renovate-bot 8727c0d6f6 Update ghcr.io/astral-sh/uv Docker tag to v0.9.26
build_latest / build (push) Successful in 48s
2026-01-18 00:00:53 +00:00
renovate-bot 64e2c10b39 Update ghcr.io/astral-sh/uv Docker tag to v0.9.24
build_latest / build (push) Successful in 42s
2026-01-11 00:00:50 +00:00
renovate-bot 3d44c5c905 Update ghcr.io/astral-sh/uv Docker tag to v0.9.21
build_latest / build (push) Successful in 1m4s
2026-01-04 00:01:02 +00:00
renovate-bot 6653bb9bdd Update ghcr.io/astral-sh/uv Docker tag to v0.9.18
build_latest / build (push) Successful in 43s
2025-12-21 00:00:56 +00:00
renovate-bot f5b45b8cab Update ghcr.io/astral-sh/uv Docker tag to v0.9.17
build_latest / build (push) Successful in 45s
2025-12-14 00:00:58 +00:00
renovate-bot 412a81db6e Update ghcr.io/astral-sh/uv Docker tag to v0.9.16
build_latest / build (push) Successful in 49s
2025-12-07 00:00:58 +00:00
renovate-bot 8069176128 Update ghcr.io/astral-sh/uv Docker tag to v0.9.13
build_latest / build (push) Successful in 46s
2025-11-30 00:00:56 +00:00
renovate-bot 5b5e699f7a Update ghcr.io/astral-sh/uv Docker tag to v0.9.11
build_latest / build (push) Successful in 36s
2025-11-23 00:00:46 +00:00
renovate-bot 3b0535663a Update ghcr.io/astral-sh/uv Docker tag to v0.9.9
build_latest / build (push) Successful in 40s
2025-11-16 00:00:45 +00:00
renovate-bot 6fd61c79cc Update ghcr.io/astral-sh/uv Docker tag to v0.9.8
build_latest / build (push) Successful in 40s
2025-11-09 00:00:46 +00:00
imcompiling c2c2b132e1 Merge pull request 'Update ghcr.io/astral-sh/uv Docker tag to v0.9.5' (#107) from renovate/ghcr.io-astral-sh-uv-0.x into main
build_latest / build (push) Successful in 42s
Reviewed-on: #107
2025-11-01 17:01:06 -04:00
renovate-bot 66f3d797fd Update ghcr.io/astral-sh/uv Docker tag to v0.9.5 2025-10-26 00:00:38 +00:00
renovate-bot ccc489dbaf Update ghcr.io/astral-sh/uv Docker tag to v0.8.23
build_latest / build (push) Successful in 55s
2025-10-05 04:01:27 +00:00
renovate-bot d0961bb9f0 Update ghcr.io/astral-sh/uv Docker tag to v0.8.22
build_latest / build (push) Successful in 36s
2025-09-28 04:01:28 +00:00
renovate-bot 83b11206da Update ghcr.io/astral-sh/uv Docker tag to v0.8.19
build_latest / build (push) Successful in 41s
2025-09-21 04:01:29 +00:00
renovate-bot 6f28f09b66 Update ghcr.io/astral-sh/uv Docker tag to v0.8.17
build_latest / build (push) Successful in 1m1s
2025-09-14 04:01:27 +00:00
renovate-bot e1508e6f31 Update ghcr.io/astral-sh/uv Docker tag to v0.8.15
build_latest / build (push) Successful in 42s
2025-09-07 04:01:27 +00:00
renovate-bot be88f1e179 Update ghcr.io/astral-sh/uv Docker tag to v0.8.14
build_latest / build (push) Successful in 1m28s
2025-08-31 04:02:06 +00:00
renovate-bot ae64ab6dde Update python Docker tag to v3.13.7
build_latest / build (push) Successful in 59s
2025-08-17 04:00:55 +00:00
renovate-bot a76df955ec Update ghcr.io/astral-sh/uv Docker tag to v0.8.11
build_latest / build (push) Waiting to run
2025-08-17 04:00:49 +00:00
renovate-bot 2473d258ff Update python Docker tag to v3.13.6
build_latest / build (push) Successful in 58s
2025-08-10 04:01:01 +00:00
renovate-bot 9c94704fbd Update ghcr.io/astral-sh/uv Docker tag to v0.8.8
build_latest / build (push) Waiting to run
2025-08-10 04:00:54 +00:00
renovate-bot 0c62678797 Update ghcr.io/astral-sh/uv Docker tag to v0.8.4
build_latest / build (push) Successful in 40s
2025-08-03 04:01:12 +00:00
renovate-bot 0528eea5cd Update ghcr.io/astral-sh/uv Docker tag to v0.8.3
build_latest / build (push) Successful in 40s
2025-07-27 04:00:44 +00:00
imcompiling 2836237b76 Merge pull request 'Update ghcr.io/astral-sh/uv Docker tag to v0.8.0' (#104) from renovate/ghcr.io-astral-sh-uv-0.x into main
build_latest / build (push) Successful in 37s
Reviewed-on: #104
Reviewed-by: imcompiling <[email protected]>
2025-07-21 09:15:20 -04:00
renovate-bot 4c741136cc Update ghcr.io/astral-sh/uv Docker tag to v0.8.0 2025-07-20 04:00:49 +00:00
imcompiling b221f1e438 Feat: Update the ban message.
build_develop / build (push) Successful in 37s
build_latest / build (push) Successful in 21s
build_release / build (push) Successful in 22s
For some reason, the user's name was None. I'm guessing because they were
banned and are no longer a member or something. Don't need to record the member's
name anyway though, as its already a part of the audit log.
2025-07-16 21:24:03 -04:00
imcompiling 1b08ba1355 Feat: Set delete messages to 30 minutes.
build_develop / build (push) Successful in 32s
2025-07-16 16:03:26 -04:00
imcompiling e191df1a38 Fix: spelling and ignore pylance warning.
build_develop / build (push) Successful in 32s
2025-07-16 15:57:31 -04:00
imcompiling e35a2a8c8d Feat: Add autoban
build_develop / build (push) Successful in 38s
2025-07-16 15:55:09 -04:00
imcompiling d7046e4595 Add: config for ban channel id. 2025-07-16 15:45:35 -04:00
imcompiling 70037fb47a Update renovate.json
build_latest / build (push) Successful in 19s
Don't automerge major versions, don't automerge docker minor versions.
2025-07-15 09:05:24 -04:00
renovate-bot 4ae3866e44 Update ghcr.io/astral-sh/uv Docker tag to v0.7.20
build_latest / build (push) Successful in 40s
2025-07-13 04:00:48 +00:00
renovate-bot 1349813f0d Update ghcr.io/astral-sh/uv Docker tag to v0.7.19
build_latest / build (push) Successful in 1m0s
2025-07-06 04:00:49 +00:00
renovate-bot 294b672fe2 Update ghcr.io/astral-sh/uv Docker tag to v0.7.16
build_latest / build (push) Successful in 45s
2025-06-29 04:00:48 +00:00
renovate-bot 72349a4cae Update python Docker tag to v3.13.5
build_latest / build (push) Successful in 1m4s
2025-06-15 04:01:25 +00:00
renovate-bot f6e9d3c32e Update ghcr.io/astral-sh/uv Docker tag to v0.7.13
build_latest / build (push) Waiting to run
2025-06-15 04:01:19 +00:00
renovate-bot 7c8455bf29 Update python Docker tag to v3.13.4
build_latest / build (push) Successful in 51s
2025-06-08 04:01:23 +00:00
renovate-bot f4c4a0435b Update ghcr.io/astral-sh/uv Docker tag to v0.7.12
build_latest / build (push) Waiting to run
2025-06-08 04:01:18 +00:00
renovate-bot bbc63dd77a Update dependency setuptools to <80.9.1,>=80.9.0
build_latest / build (push) Successful in 39s
2025-06-01 04:01:50 +00:00
renovate-bot 7ed3f0d613 Update ghcr.io/astral-sh/uv Docker tag to v0.7.9
build_latest / build (push) Waiting to run
2025-06-01 04:01:17 +00:00
imcompiling eb6a8c7479 Feat: Add logging to tell when refresh happens.
build_latest / build (push) Successful in 44s
build_release / build (push) Successful in 22s
2025-05-27 23:33:19 -04:00
imcompiling 58b230afe6 Fix: Catch git error and refresh connection.
build_latest / build (push) Successful in 39s
build_release / build (push) Successful in 23s
I think that the git error is just happening from timing out. Trying to fix by
refreshing the connection when it happens.
2025-05-27 23:31:02 -04:00
imcompiling fb8dfef55e Fix: daily test runs daily loop.
build_develop / build (push) Successful in 42s
build_latest / build (push) Successful in 19s
build_release / build (push) Successful in 20s
2025-05-27 23:13:39 -04:00
imcompiling 487d174b6d Fix: Remove name clobber. Add a try except.
build_develop / build (push) Successful in 40s
Also add environment variable to launch settings.
2025-05-26 21:15:15 -04:00
imcompiling abb50d71b4 Feat: Update logging.
build_develop / build (push) Successful in 36s
Narrowing down where the issue is. Active cycle is being obtained, but
nothing was happening with it. No more debug messages either.
2025-05-26 20:40:12 -04:00
imcompiling 7409e2fd2d Feat: Add filename, lineno, and function name to logging. 2025-05-26 20:34:45 -04:00
imcompiling 6a67804937 Fix: Import logger correctly.
build_develop / build (push) Successful in 42s
2025-05-25 22:31:50 -04:00
imcompiling 4f4d76d151 Feat: Add some logging.
build_develop / build (push) Successful in 43s
Trying to figure out why the elections are not starting.
2025-05-25 22:24:26 -04:00
imcompiling f3985b5d21 Feat: Set debug if env var is true. 2025-05-25 22:15:12 -04:00
imcompiling 142cc337a0 Feat: Add dakiny_bot logger. 2025-05-25 22:11:37 -04:00
imcompiling fd1d1c075e Feat: Remove logger from app.py. It existed it main.j 2025-05-25 22:11:18 -04:00
imcompiling e3ffafcff2 Update to python 3.13
build_latest / build (push) Successful in 40s
build_develop / build (push) Successful in 28s
2025-05-25 16:23:41 -04:00
imcompiling 855f3c1df8 Merge pull request 'Update dependency setuptools to v80' (#96) from renovate/setuptools-80.x into main
build_latest / build (push) Successful in 42s
Reviewed-on: #96
Reviewed-by: imcompiling <[email protected]>
2025-05-25 15:42:28 -04:00
renovate-bot a3371e9e8c Update dependency setuptools to v80 2025-05-25 04:01:54 +00:00
renovate-bot a158248a35 Update ghcr.io/astral-sh/uv Docker tag to v0.7.8
build_latest / build (push) Successful in 56s
2025-05-25 04:01:18 +00:00
renovate-bot 886ac2f7ee Update ghcr.io/astral-sh/uv Docker tag to v0.7.5
build_latest / build (push) Successful in 47s
2025-05-18 04:01:21 +00:00
renovate-bot f06033d2ec Update ghcr.io/astral-sh/uv Docker tag to v0.7.3
build_latest / build (push) Successful in 52s
2025-05-11 04:01:29 +00:00
renovate-bot 2ffc4126d2 Update ghcr.io/astral-sh/uv Docker tag to v0.7.2
build_latest / build (push) Successful in 52s
2025-05-04 04:01:47 +00:00
renovate-bot 4280ddd841 Update ghcr.io/astral-sh/uv Docker tag to v0.6.17
build_latest / build (push) Successful in 39s
2025-04-27 04:01:16 +00:00
27 changed files with 514 additions and 603 deletions
+4 -1
View File
@@ -9,7 +9,10 @@
"type": "debugpy",
"request": "launch",
"module": "dakiny_bot",
"justMyCode": true
"justMyCode": true,
"env": {
"DEBUG": "true"
}
}
]
}
+2 -2
View File
@@ -1,10 +1,10 @@
FROM python:3.13.3-slim
FROM python:3.13.7-slim
# install dependencies
RUN apt-get update && apt-get -y upgrade && apt-get -y install git sqlite3
# install uv
COPY --from=ghcr.io/astral-sh/uv:0.6.14 /uv /uvx /bin/
COPY --from=ghcr.io/astral-sh/uv:0.9.28 /uv /uvx /bin/
COPY . /home
@@ -17,6 +17,7 @@ class ChannelIds:
event_post: int
general: int
voting: int
ban: int
@dataclass
@@ -83,4 +84,4 @@ class DakinySettings(YAMLWizard):
self.to_yaml_file(CONFIG_LOCATION)
settings: DakinySettings | None = None
settings = DakinySettings.from_yaml_file(CONFIG_LOCATION)
-6
View File
@@ -1,7 +1 @@
"""Empty init file for dakiny_bot module."""
from dakiny_bot.dakiny_settings import CONFIG_LOCATION, DakinySettings, settings
if settings is None:
tmp = DakinySettings.from_yaml_file(CONFIG_LOCATION)
settings = tmp[0] if isinstance(tmp, list) else tmp
+1 -8
View File
@@ -1,6 +1,5 @@
"""Main file for bot."""
import logging
import os
import nextcord
@@ -12,16 +11,10 @@ from dakiny_bot.classes.voting_highcouncil_views import VoteHighcouncilView
from dakiny_bot.classes.voting_views import VoteView
from dakiny_bot.database import create_database
from .dakiny_settings import settings
from .DakinySettings import settings
birthday_list: list[int] = []
logger = logging.getLogger("nextcord")
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8", mode="w")
handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
logger.addHandler(handler)
def run() -> None:
"""Builds and runs bot."""
+16 -6
View File
@@ -9,20 +9,21 @@ from dakiny_bot.classes.nominate_highcouncil_views import NominateHighCouncilVie
from dakiny_bot.classes.nominate_views import NominateView
from dakiny_bot.classes.voting_highcouncil_views import VoteHighcouncilView
from dakiny_bot.classes.voting_views import VoteView
from dakiny_bot.dakiny_settings import settings
from dakiny_bot.DakinySettings import settings
from dakiny_bot.database.sql_data_classes import (
CouncilMembers,
ElectionInformation,
Votes,
engine,
)
from dakiny_bot.election_utils import get_datetime
from dakiny_bot.logger import dakiny_logger
from dakiny_bot.utils import (
TEMPLATES_DIR,
VoteType,
build_highcouncil_votes_str,
build_votes_str,
edit_clan_council_info,
get_datetime,
get_election_name,
)
from sqlalchemy import select, true, update
@@ -69,7 +70,7 @@ class Election:
list[str]: A list of message contents in the correct order. Must be a string because the message is too
long.
"""
with Path(f"{TEMPLATES_DIR}/election_announcement.txt").open() as file:
with Path(f"{TEMPLATES_DIR}/election_announcement.txt", encoding="utf8").open() as file:
message = file.read()
next_election = get_datetime(
@@ -97,7 +98,7 @@ class Election:
Returns:
str: Message to send.
"""
with Path(f"{TEMPLATES_DIR}/highcouncil_election.txt").open() as file:
with Path(f"{TEMPLATES_DIR}/highcouncil_election.txt", encoding="utf8").open() as file:
message = file.read()
return message.format(
@@ -115,7 +116,7 @@ class Election:
Returns:
str: Message to send.
"""
with Path(f"{TEMPLATES_DIR}/highcouncil_vote.txt").open() as file:
with Path(f"{TEMPLATES_DIR}/highcouncil_vote.txt", encoding="utf8").open() as file:
message = file.read()
return message.format(
@@ -130,7 +131,7 @@ class Election:
Returns:
str: Message to send
"""
with Path(f"{TEMPLATES_DIR}/vote_start.txt").open() as file:
with Path(f"{TEMPLATES_DIR}/vote_start.txt", encoding="utf8").open() as file:
message = file.read()
vote_end: datetime = get_datetime(settings.election_cycles[self.cycle].voting_end)
@@ -143,20 +144,29 @@ class Election:
async def check_date(self) -> None:
"""Function checks current date to see if something needs to be run."""
today = datetime.now(tz=UTC)
dakiny_logger.debug("Checking date.")
# check all dates if action is needed
if today.date() == self.election_start.date():
dakiny_logger.debug("Election start.")
await self.election_start_action()
elif today.date() == self.voting_start.date():
dakiny_logger.debug("Voting start.")
await self.voting_start_action()
elif (self.voting_end - timedelta(3)).date() <= today.date() < self.voting_end.date():
dakiny_logger.debug("Election reminder.")
await self.election_reminder()
elif today.date() == self.voting_end.date():
dakiny_logger.debug("Voting end.")
await self.voting_end_action()
elif today.date() == self.highcouncil_election_start.date():
dakiny_logger.debug("Highcouncil election start.")
await self.highcouncil_election_start_action()
elif today.date() == self.term_start.date():
dakiny_logger.debug("Term start")
await self.term_start_action()
else:
dakiny_logger.warning("Check date didn't do anything. This should never happen.")
async def election_start_action(self) -> None:
"""Performs required actions for when the election cycle starts."""
@@ -1,7 +1,11 @@
"""Contains various views to be used in the high council nomination process."""
import nextcord
from dakiny_bot.dakiny_settings import settings
from nextcord.interactions import Interaction
from sqlalchemy import select
from sqlalchemy.orm import Session
from dakiny_bot.DakinySettings import settings
from dakiny_bot.database.sql_data_classes import CouncilMembers, engine
from dakiny_bot.utils import (
NOMINEE_SPLITTER,
@@ -9,9 +13,6 @@ from dakiny_bot.utils import (
decorate_dm_nomination,
get_election_name,
)
from nextcord.interactions import Interaction
from sqlalchemy import select
from sqlalchemy.orm import Session
class NominateDMModal(nextcord.ui.Modal):
+4 -3
View File
@@ -1,13 +1,14 @@
"""Contains various views to be used in the nomination process."""
import nextcord
from dakiny_bot.dakiny_settings import settings
from dakiny_bot.database.sql_data_classes import CouncilMembers, engine
from dakiny_bot.utils import NOMINEE_SPLITTER, decorate_nomination, get_election_name
from nextcord.interactions import Interaction
from sqlalchemy import select
from sqlalchemy.orm import Session
from dakiny_bot.DakinySettings import settings
from dakiny_bot.database.sql_data_classes import CouncilMembers, engine
from dakiny_bot.utils import NOMINEE_SPLITTER, decorate_nomination, get_election_name
class NominateModal(nextcord.ui.Modal):
"""
@@ -1,7 +1,12 @@
"""Contains various views to be used while voting for high council. Controls the logic when performing the vote."""
import nextcord
from dakiny_bot.dakiny_settings import settings
from nextcord import SelectOption
from nextcord.interactions import Interaction
from sqlalchemy import exc, select, update
from sqlalchemy.orm import Session
from dakiny_bot.DakinySettings import settings
from dakiny_bot.database.sql_data_classes import (
CouncilMembers,
ElectionInformation,
@@ -9,10 +14,6 @@ from dakiny_bot.database.sql_data_classes import (
engine,
)
from dakiny_bot.utils import VoteType, build_highcouncil_votes_str, get_election_name
from nextcord import SelectOption
from nextcord.interactions import Interaction
from sqlalchemy import exc, select, update
from sqlalchemy.orm import Session
class VoteSelect(nextcord.ui.StringSelect):
+6 -5
View File
@@ -1,7 +1,12 @@
"""Contains various views to be used while voting. Controls the logic when performing the vote."""
import nextcord
from dakiny_bot.dakiny_settings import settings
from nextcord import SelectOption
from nextcord.interactions import Interaction
from sqlalchemy import exc, select, update
from sqlalchemy.orm import Session
from dakiny_bot.DakinySettings import settings
from dakiny_bot.database.sql_data_classes import (
CouncilMembers,
ElectionInformation,
@@ -9,10 +14,6 @@ from dakiny_bot.database.sql_data_classes import (
engine,
)
from dakiny_bot.utils import VoteType, build_votes_str, get_election_name
from nextcord import SelectOption
from nextcord.interactions import Interaction
from sqlalchemy import exc, select, update
from sqlalchemy.orm import Session
class VoteSelect(nextcord.ui.StringSelect):
+8 -1
View File
@@ -6,10 +6,12 @@ from typing import TYPE_CHECKING
import uvicorn
from fastapi import FastAPI
from git import Repo
from git.exc import GitCommandError
from nextcord.ext import commands
from dakiny_bot.classes.gitea_webhook import GiteaWebhook
from dakiny_bot.dakiny_settings import settings
from dakiny_bot.DakinySettings import settings
from dakiny_bot.logger import dakiny_logger
from dakiny_bot.utils import REPO_DIR, edit_clan_council_info, update_clan_messages
if TYPE_CHECKING:
@@ -55,7 +57,12 @@ class ClanMessages(commands.Cog, name="Clan Messages"):
template_updates = {file.split("/")[1] for file in modified_files if "message_templates" in file}
channel_updates = {file.split("/")[1] for file in modified_files if file.split("/")[1] not in template_updates}
try:
self.origin.pull()
except GitCommandError:
# I think the git connection timed out. Get a new one.
dakiny_logger.info("Refreshing git connection.")
self.repo_setup()
guild: nextcord.Guild = self.bot.get_guild(settings.params.guild_id)
await update_clan_messages(guild, channel_updates)
+1 -1
View File
@@ -4,7 +4,7 @@ import nextcord
from discord import TextInputStyle
from nextcord.ext import commands
from dakiny_bot.dakiny_settings import settings
from dakiny_bot.DakinySettings import settings
from dakiny_bot.utils import GUILDS, MAX_DISCORD_MESSAGE_LENGTH, PointType, record_points
+1 -1
View File
@@ -4,7 +4,7 @@ import nextcord
from nextcord.ext import commands
from sqlalchemy.orm import Session
from dakiny_bot.dakiny_settings import settings
from dakiny_bot.DakinySettings import settings
from dakiny_bot.database.sql_data_classes import Presences, engine
+1 -1
View File
@@ -3,7 +3,7 @@
import nextcord
from nextcord.ext import commands
from dakiny_bot.dakiny_settings import settings
from dakiny_bot.DakinySettings import settings
from dakiny_bot.utils import GUILDS
+4 -6
View File
@@ -4,7 +4,8 @@ import nextcord
from nextcord.ext import application_checks, commands
from dakiny_bot.classes.election import Election
from dakiny_bot.dakiny_settings import settings
from dakiny_bot.cogs.loops import daily_loop
from dakiny_bot.DakinySettings import settings
from dakiny_bot.utils import GUILDS, get_active_election_cycle, get_quarter_name
ME = 206602713511886849
@@ -119,11 +120,8 @@ class TestCog(commands.Cog, name="Test commands."):
Args:
interaction (nextcord.Interaction): Interaction with the message.
"""
cycle = Election(
get_active_election_cycle(),
self.bot.get_guild(settings.params.guild_id),
)
await cycle.check_date()
dl = daily_loop.DailyLoop(self.bot)
await dl.daily_loop()
await interaction.send("Test command sent.", ephemeral=True)
@test.subcommand()
+8 -1
View File
@@ -11,8 +11,9 @@ from sqlalchemy.orm import Session
from dakiny_bot.app import birthday_list
from dakiny_bot.classes.election import Election
from dakiny_bot.dakiny_settings import settings
from dakiny_bot.DakinySettings import settings
from dakiny_bot.database.sql_data_classes import UserBirthday, engine
from dakiny_bot.logger import dakiny_logger
from dakiny_bot.utils import get_active_election_cycle
if TYPE_CHECKING:
@@ -43,8 +44,10 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
an active election, runs the check_date() function for the election to perform actions. Finally checks if the
election is over to delete the current election object.
"""
dakiny_logger.debug("Daily loop. Current election: %s.", self.current_election)
if self.current_election is None:
self.current_election = self.get_election()
dakiny_logger.debug("Current election: %s.", self.current_election)
if self.current_election is not None:
await self.current_election.check_date()
@@ -78,13 +81,17 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
Election: Current election cycle, None if there is no election happening.
"""
cycle = get_active_election_cycle()
dakiny_logger.debug("Current cycle: %s.", cycle)
# prevent exception from using cycle as an Int in an array
if cycle is None:
dakiny_logger.info("Cycle was None. Returning without an election.")
return None
election = Election(cycle, self.bot.get_guild(settings.params.guild_id))
dakiny_logger.debug("Election active: %s", election.active)
return election if election.active else None
def update_birthdays(self) -> None:
+11 -2
View File
@@ -4,6 +4,7 @@ import nextcord
from nextcord.ext import commands
from dakiny_bot.app import birthday_list
from dakiny_bot.DakinySettings import settings
class SubmissionListener(commands.Cog, name="Message Listener"):
@@ -16,7 +17,15 @@ class SubmissionListener(commands.Cog, name="Message Listener"):
async def on_message(self, message: nextcord.Message) -> None:
"""Listener for message creation. Adds score and attachments to submission."""
# don't want to process any messages from bot.
if message.author.id == self.bot.user.id:
if message.author.id == self.bot.user.id: # pyright: ignore[reportOptionalMemberAccess]
return
# Ban all members who message in this channel. Everyone in guild is a member, so shouldn't miss a ban
# due to message.author not being a nextcord.Member object.
if message.channel.id == settings.channel_ids.ban and isinstance(message.author, nextcord.Member):
await message.author.ban(
delete_message_seconds=30 * 60, reason="Probable spam. The ban channel was messaged."
)
return
await birthday_action(message)
@@ -31,7 +40,7 @@ def setup(bot: commands.Bot) -> None:
async def birthday_action(message: nextcord.Message) -> None:
"""
Checks a message's auther and mentions to see if they are in the birthday list.
Checks a message's author and mentions to see if they are in the birthday list.
Args:
message (nextcord.Message): The message to check for a birthday person.
-51
View File
@@ -1,51 +0,0 @@
"""Broken out util functions to avoid importing sql during testing."""
import calendar
from datetime import UTC, datetime
from dakiny_bot.dakiny_settings import settings
def get_datetime(month_day: str) -> datetime:
"""
Takes in a string month and day and returns a datetime object of that Month/Day this year.
Args:
month_day (str): Month/Day in that format.
Returns:
datetime: Datetime representation of Month/Day.
"""
today = datetime.now(tz=UTC).date()
year = today.year
month = int(month_day.split("/")[0])
day = int(month_day.split("/")[1])
# ensure that year rolls over if current month is December and the next month is less than 12.
if today.month == calendar.DECEMBER and month < calendar.OCTOBER:
year += 1
if today.month == calendar.JANUARY and month > calendar.MARCH:
year -= 1
return datetime(year, month, day, tzinfo=UTC)
def get_quarter_cycle() -> int | None:
"""
Returns the index for the current cycle/quarter. Defined as between term start and end.
Can return None if entire year isn't covered by cycles.
Returns:
int: cycle index for current cycle.
"""
today = datetime.now(tz=UTC)
for cycle, election in enumerate(settings.election_cycles):
if (
today.date() >= get_datetime(election.term_start).date()
and today.date() <= get_datetime(election.term_end).date()
):
return cycle
return None
+13
View File
@@ -0,0 +1,13 @@
"""Creates logger for Dakiny bot."""
import logging
import os
import sys
dakiny_logger = logging.getLogger("default")
dakiny_logger.setLevel(logging.DEBUG if os.getenv("DEBUG") == "true" else logging.INFO)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(
logging.Formatter("%(asctime)s:%(levelname)s [%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s")
)
dakiny_logger.addHandler(handler)
-1
View File
@@ -1 +0,0 @@
"""Empty init for testing util functions."""
-1
View File
@@ -1 +0,0 @@
"""Empty init for testing util functions."""
@@ -1,41 +0,0 @@
"""Tests for get_datetime function."""
import datetime
from freezegun import freeze_time
from dakiny_bot.election_utils import get_datetime
@freeze_time("2025-6-16")
def test_regular_get_datetime() -> None:
"""
Test a regular get_datetime.
Expect the returned datetime to be the frozen date.
Have two different days to ensure that the date is being returned correctly.
"""
date_time = get_datetime("6/15")
assert date_time == datetime.datetime(2025, 6, 15, tzinfo=datetime.UTC)
@freeze_time("2025-1-16")
def test_jan_get_datetime() -> None:
"""
Test previous year get_datetime.
Frozen day is in January 2025, datetime string is in December. Expect datetime to be from 2024.
"""
date_time = get_datetime("12/15")
assert date_time == datetime.datetime(2024, 12, 15, tzinfo=datetime.UTC)
@freeze_time("2025-12-16")
def test_dec_get_datetime() -> None:
"""
Test next year get_datetime.
Frozen day is in December 2025, datetime string is in January. Expect datetime to be from 2026.
"""
date_time = get_datetime("1/15")
assert date_time == datetime.datetime(2026, 1, 15, tzinfo=datetime.UTC)
@@ -1,31 +0,0 @@
"""Test functions for get_quarter_cycle."""
from unittest.mock import mock_open, patch
from freezegun import freeze_time
from dakiny_bot.dakiny_settings import ChannelIds, DakinySettings, Election, Params, PointSettings, RoleIds
from dakiny_bot.election_utils import get_quarter_cycle
# I only care about term start and term end for this test
q1 = Election(True, "", "", "", "", "q1", "4/30", "2/1", "", "") # noqa: FBT003
q2 = Election(True, "", "", "", "", "q2", "7/31", "5/1", "", "") # noqa: FBT003
q3 = Election(True, "", "", "", "", "q3", "10/31", "8/1", "", "") # noqa: FBT003
q4 = Election(True, "", "", "", "", "q4", "1/31", "11/1", "", "") # noqa: FBT003
# Dummy all the values I don't care about.
settings = DakinySettings(
ChannelIds(1, 1, 1, 1, 1, 1),
[q1, q2, q3, q4],
Params("", "", 1),
PointSettings(1, 1, 1, 1, 1, True, True), # noqa: FBT003
RoleIds(1, 1, 1, 1, 1),
)
@patch("election_utils.get_quarter_cycle.settings", settings)
@patch("builtins.open", new_callable=mock_open)
class TestGetQuarterCycle:
@freeze_time("2025-2-25")
def test_regular_q1(self) -> None:
assert get_quarter_cycle() == 0
+58 -11
View File
@@ -1,5 +1,6 @@
"""File contains util functions."""
import calendar
import os
from collections.abc import Sequence
from datetime import UTC, datetime
@@ -19,9 +20,9 @@ from dakiny_bot.database.sql_data_classes import (
Votes,
engine,
)
from dakiny_bot.logger import dakiny_logger
from .dakiny_settings import settings
from .election_utils import get_datetime, get_quarter_cycle
from .DakinySettings import settings
NOMINEE_SPLITTER = "========================================\n\n"
REPO_DIR = "./dakiny-messages"
@@ -34,6 +35,33 @@ VoteType = StrEnum("VoteType", ["COUNCIL", "DISCORDMANAGER", "CLANLEADER"])
PointType = StrEnum("PointType", ["CLAN", "EVENT"])
def get_datetime(month_day: str) -> datetime:
"""
Takes in a string month and day and returns a datetime object of that Month/Day this year.
Args:
month_day (str): Month/Day in that format.
Returns:
datetime: Datetime representation of Month/Day.
"""
today = datetime.now(tz=UTC).date()
year = today.year
month = int(month_day.split("/")[0])
day = int(month_day.split("/")[1])
# ensure that year rolls over if current month is December and the next month is less than 12.
if today.month == calendar.DECEMBER and month < calendar.OCTOBER:
year += 1
if today.month == calendar.JANUARY and month > calendar.MARCH:
year -= 1
try:
return datetime(year, month, day, tzinfo=UTC)
except ValueError:
dakiny_logger.warning("Invalid month day: %s.", month_day)
def get_election_name() -> str:
"""
Builds the unique name of the current election cycle.
@@ -41,10 +69,7 @@ def get_election_name() -> str:
Returns:
str: the name of the election cycle
"""
if cycle := get_active_election_cycle() is None:
# undefined behavior
print("Did not find an active election cycle. Undefined behavior with return string.") # noqa: T201
return "No-active-election-cycle"
cycle = get_active_election_cycle()
current_cycle = settings.election_cycles[cycle]
return f"vote-{get_datetime(current_cycle.term_start).year}-{current_cycle.name}"
@@ -56,16 +81,13 @@ def get_quarter_name() -> str:
Returns:
str: the name of the cycle.
"""
if cycle := get_quarter_cycle() is None:
# undefined behavior
print("Did not find a quarter cycle. Undefined behavior with return string.") # noqa: T201
return "no-quarter-cycle"
cycle = get_quarter_cycle()
current_cycle = settings.election_cycles[cycle]
return f"{get_datetime(current_cycle.term_start).year}-{current_cycle.name}"
def get_active_election_cycle() -> int | None:
def get_active_election_cycle() -> int:
"""
Returns index for active election. An election is considered active between the election start and the term start.
@@ -73,18 +95,43 @@ def get_active_election_cycle() -> int | None:
int: cycle index for active election. None for no active cycle
"""
today = datetime.now(tz=UTC)
dakiny_logger.debug("Today is %s", today)
for cycle, election in enumerate(settings.election_cycles):
if (
today.date() >= get_datetime(election.election_start).date()
and today.date() <= get_datetime(election.term_start).date()
):
dakiny_logger.debug("Cycle is %d", cycle)
return cycle
# It isn't a current election, get the quarter
return get_quarter_cycle()
def get_quarter_cycle() -> int:
"""
Returns the index for the current cycle/quarter. Defined as between term start and end.
Can return None if entire year isn't covered by cycles.
Returns:
int: cycle index for current cycle.
"""
today = datetime.now(tz=UTC)
dakiny_logger.debug("Today is %s", today)
for cycle, election in enumerate(settings.election_cycles):
if (
today.date() >= get_datetime(election.term_start).date()
and today.date() <= get_datetime(election.term_end).date()
):
dakiny_logger.debug("Cycle is %d", cycle)
return cycle
dakiny_logger.debug("Quarter cycle is None.")
return None
def build_votes_str(guild: nextcord.Guild) -> str:
"""
Creates a string that contains all nominees and their votes to be sent as a discord message.
+5 -12
View File
@@ -1,17 +1,18 @@
[project]
authors = [{ name = "imcompiling", email = "[email protected]" }]
requires-python = "<4.0,>=3.12"
requires-python = "<4.0,>=3.13"
dependencies = [
"gitpython<4.0.0,>=3.1.43",
"fastapi<1.0.0,>=0.111.0",
"nextcord<3.0.0,>=2.6.0",
"pandas<3.0.0,>=2.2.2",
"pandas<3.1.0,>=3.0.5",
"pytz<2025.3,>=2025.2",
"sqlalchemy<3.0.0,>=2.0.30",
"aiofiles<24.0.0,>=23.2.1",
"setuptools<71.0.0,>=70.0.0",
"setuptools<80.10.3,>=80.10.2",
"dataclass-wizard[yaml]>=0.22.3,<1.0.0",
"uvicorn>=0.34.0",
"audioop-lts>=0.2.1",
]
name = "dakiny-bot"
version = "0.1.0"
@@ -19,12 +20,7 @@ description = "Dakiny's Discord Bot."
readme = "README.md"
[dependency-groups]
dev = [
"freezegun>=1.5.1",
"pytest>=8.3.5",
"pytest-cov>=6.1.1",
"ruff<1.0.0,>=0.6.9",
]
dev = ["ruff<1.0.0,>=0.6.9"]
[tool.ruff]
# Exclude a variety of commonly ignored directories.
@@ -131,6 +127,3 @@ docstring-code-format = true
# This only has an effect when the `docstring-code-format` setting is
# enabled.
docstring-code-line-length = "dynamic"
[tool.ruff.lint.per-file-ignores]
"**/{tests}/*" = ["ANN001", "ANN201", "S101", "PLR2004"]
+12 -3
View File
@@ -1,8 +1,11 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"lockFileMaintenance": {
"automerge": true,
"enabled": true
"automerge": true
},
"major": {
"automerge": false,
"automergeType": "pr"
},
"minor": {
"automerge": true,
@@ -16,5 +19,11 @@
"automerge": true,
"automergeType": "branch"
},
"ignoreTests": true
"ignoreTests": true,
"dockerfile": {
"minor": {
"automerge": false,
"automergeType": "pr"
}
}
}
Generated
+345 -397
View File
File diff suppressed because it is too large Load Diff