Author SHA1 Message Date
imcompiling f79d63c78d Add timestamp to description.
build_develop / build (push) Successful in 22s
2025-03-20 09:27:36 -04:00
imcompiling 5a8119f5e4 Add the daily loop for open raid.
build_develop / build (push) Successful in 22s
2025-03-19 21:27:58 -04:00
imcompiling d5e6ffdedb Correct raid time.
build_develop / build (push) Successful in 21s
2025-03-19 19:36:21 -04:00
imcompiling 661c864ba2 Edit a docustring. 2025-03-19 19:19:34 -04:00
imcompiling 8d65d478cd Add function to open raid buttons. Load the view in app so that views function after bot restart.
build_develop / build (push) Successful in 22s
2025-03-19 19:16:17 -04:00
imcompiling 10e561b0e3 Update the button looks. 2025-03-19 18:04:49 -04:00
imcompiling 842a385d7d Add test cog to commands init. 2025-03-19 17:49:34 -04:00
imcompiling e9c8336124 Add module that will support open raid. Add test command.
build_develop / build (push) Successful in 21s
2025-03-19 11:39:26 -04:00
imcompiling ef92902932 Add utils to define guild ids that will use this bot. 2025-03-19 11:39:08 -04:00
imcompiling 5c6fa4386e Correct database ignore.
build_latest / build (push) Successful in 17s
build_develop / build (push) Successful in 17s
2025-03-19 09:51:13 -04:00
imcompiling 590cb9abe4 Don't need to build latest in release workflow.
build_latest / build (push) Successful in 17s
2025-03-19 09:35:00 -04:00
imcompiling 46f518c1c4 Update uv command to not install dev dependencies and to use the already existing venv.
build_latest / build (push) Successful in 18s
2025-03-19 08:42:50 -04:00
imcompiling 30ecdab8a5 Ignore the database directory.
build_develop / build (push) Successful in 18s
build_latest / build (push) Successful in 17s
2025-03-18 22:44:21 -04:00
imcompiling 565ea73792 Convert to be more consistant like python package.
build_develop / build (push) Successful in 20s
2025-03-18 22:43:20 -04:00
imcompiling bfef75870f Change directory in dockerfile.
build_develop / build (push) Successful in 17s
2025-03-18 22:09:13 -04:00
imcompiling 56289e7038 Use home directory.
build_develop / build (push) Successful in 21s
2025-03-18 22:00:38 -04:00
imcompiling 54a011337a Fix debugger module and imports.
build_develop / build (push) Successful in 21s
2025-03-18 21:45:12 -04:00
imcompiling b3905fa15c Update uv lock. 2025-03-18 21:32:00 -04:00
imcompiling a09845dfb8 Fix import paths.
build_develop / build (push) Successful in 22s
2025-03-18 13:03:56 -04:00
imcompiling a86b01292f Add an editor config file. 2025-03-18 11:10:02 -04:00
imcompiling 1ad68f4014 Remove outdated comment.
build_develop / build (push) Successful in 22s
2025-03-18 11:07:23 -04:00
imcompiling 3aa0bf291f Remove python dotenv. 2025-03-18 11:06:10 -04:00
imcompiling b727a80e4f Fix smells in main.py.
build_develop / build (push) Successful in 26s
2025-03-18 10:11:52 -04:00
imcompiling 857b5f1669 Update module name in dockerfile. 2025-03-18 10:10:38 -04:00
imcompiling 34cd2f9975 Rename module and add init file to conform to ruff.
build_develop / build (push) Successful in 21s
2025-03-18 10:03:51 -04:00
imcompiling 6af2476339 Update settings to fix a smell. Add some spelling words.
build_develop / build (push) Successful in 22s
2025-03-18 09:50:49 -04:00
imcompiling 4a3f356b23 Update imports. 2025-03-18 09:50:36 -04:00
imcompiling 4fe2339ac1 Update launch command to launch in new location. 2025-03-18 09:49:01 -04:00
imcompiling 2069b2544f Remove old config file. Update docker file for directory change. 2025-03-18 09:37:33 -04:00
imcompiling 901bcf3c62 Move all files into off-cooldown-bot dir. 2025-03-18 09:15:22 -04:00
imcompiling 8e8f84a42e Add more to dockerignore.
build_latest / build (push) Successful in 25s
2025-03-18 08:21:14 -04:00
imcompiling cd241e6f5e Remove extra $ on accident.
build_latest / build (push) Successful in 22s
2025-03-17 21:49:13 -04:00
imcompiling 93d9b565c0 Also update in latest.
build_latest / build (push) Failing after 19s
2025-03-17 21:45:00 -04:00
imcompiling c816d3b5b8 Update docker login action.
build_latest / build (push) Failing after 16s
2025-03-17 21:44:05 -04:00
imcompiling 91900f2b00 Update docker file, add a docker ignore.
build_latest / build (push) Failing after 16s
2025-03-17 21:36:09 -04:00
30 changed files with 321 additions and 103 deletions
+4
View File
@@ -0,0 +1,4 @@
.*
Dockerfile
renovate.json
README.md
+16
View File
@@ -0,0 +1,16 @@
# see https://editorconfig.org/
root = true
[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_size = 2
+1 -1
View File
@@ -19,7 +19,7 @@ jobs:
- name: Install Docker
uses: https://github.com/papodaca/install-docker-action@v1
- name: Log into container registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: gitea.cheezers.org
username: imcompiling
+2 -2
View File
@@ -17,11 +17,11 @@ jobs:
- name: Install Docker
uses: https://github.com/papodaca/install-docker-action@v1
- name: Log into container registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: gitea.cheezers.org
username: imcompiling
password: $${{ secrets.PASSWORD }}
password: ${{ secrets.PASSWORD }}
- name: Build Docker Image
run: docker build -t gitea.cheezers.org/imcompiling/off-cooldown-bot:latest .
- name: Push Docker Image
+1 -3
View File
@@ -23,8 +23,6 @@ jobs:
- name: Set env
run: echo "GIT_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Build Docker Images
run: docker build -t gitea.cheezers.org/imcompiling/off-cooldown-bot:latest -t gitea.cheezers.org/imcompiling/off-cooldown-bot:${{env.GIT_TAG}} .
- name: Push Latest Image
run: docker push gitea.cheezers.org/imcompiling/off-cooldown-bot:latest
run: docker build -t gitea.cheezers.org/imcompiling/off-cooldown-bot:${{env.GIT_TAG}} .
- name: Push Tagged Image
run: docker push gitea.cheezers.org/imcompiling/off-cooldown-bot:${{env.GIT_TAG}}
+1 -1
View File
@@ -129,4 +129,4 @@ dmypy.json
nextcord.log
outputs/
database.db
/database
+2 -1
View File
@@ -3,6 +3,7 @@
"ms-python.vscode-pylance",
"ms-python.python",
"ms-python.debugpy",
"charliermarsh.ruff"
"charliermarsh.ruff",
"editorconfig.editorconfig"
]
}
+2 -2
View File
@@ -8,8 +8,8 @@
"name": "Python: Module",
"type": "debugpy",
"request": "launch",
"module": "main",
"justMyCode": true
"module": "off_cooldown_bot",
"justMyCode": true,
}
]
}
+4 -1
View File
@@ -5,7 +5,10 @@
"reportAttributeAccessIssue": "warning"
},
"cSpell.words": [
"blurple",
"cakeday",
"cakedays"
"cakedays",
"cooldown",
"nextcord"
]
}
+4 -8
View File
@@ -3,14 +3,10 @@ FROM python:3.12.3-slim
# install uv
COPY --from=ghcr.io/astral-sh/uv:0.6.5 /uv /uvx /bin/
COPY . /home
# Sync the project into a new environment, using the frozen lockfile
WORKDIR /home
COPY config.py config.py
COPY main.py main.py
COPY pyproject.toml pyproject.toml
COPY cogs cogs/
RUN uv sync --frozen --no-dev
CMD ["uv", "run", "./main.py"]
CMD ["uv", "run", "--frozen", "--no-dev", "-m", "off_cooldown_bot"]
-22
View File
@@ -1,22 +0,0 @@
"""
File contains classes defining the Hydra configuraton structure.
"""
from dataclasses import dataclass
@dataclass
class Params:
"""
Class defines the various configuration parameters.
"""
discord_token: str
@dataclass
class BotConfig:
"""
Class defines all configs required for Dakiny Bot.
"""
params: Params
+1
View File
@@ -0,0 +1 @@
"""Empty init file for off_cooldown_bot module."""
+14
View File
@@ -0,0 +1,14 @@
"""Starts the app for off_cooldown_bot."""
import logging
from .app import run
nextcord_logger = logging.getLogger("nextcord")
nextcord_logger.setLevel(logging.DEBUG)
nextcord_handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8", mode="w")
nextcord_handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
nextcord_logger.addHandler(nextcord_handler)
if __name__ == "__main__":
run()
+9 -17
View File
@@ -2,25 +2,20 @@
from __future__ import annotations
import logging
import pathlib
import nextcord
from nextcord.ext import commands
from logger import ocd_logger
from settings import settings
from off_cooldown_bot.open_raid import OpenRaid
nextcord_logger = logging.getLogger("nextcord")
nextcord_logger.setLevel(logging.DEBUG)
nextcord_handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8", mode="w")
nextcord_handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
nextcord_logger.addHandler(nextcord_handler)
from .logger import ocd_logger
from .settings import settings
birthday_list: list[int] = []
def main() -> None:
def run() -> None:
"""Set config, intents, then connects the bot to discord."""
# Allows privileged intents for monitoring members joining, roles editing, and role assignments
# These need to be enabled in the developer portal as well
@@ -30,7 +25,7 @@ def main() -> None:
intents.message_content = True
# To enable the guilds privileged intent:
# intents.guilds = True
# intents.guilds = True # noqa: ERA001
# To enable the members privileged intent:
intents.members = True
@@ -38,8 +33,8 @@ def main() -> None:
bot = commands.Bot(intents=intents)
# Get the modules of all cogs whose directory structure is ./cogs/<module_name>
for folder in pathlib.Path("cogs").iterdir():
bot.load_extension(f"cogs.{folder.name}")
for folder in pathlib.Path("./off_cooldown_bot/cogs").iterdir():
bot.load_extension(f"off_cooldown_bot.cogs.{folder.name}")
@bot.listen()
async def on_ready() -> None:
@@ -47,11 +42,8 @@ def main() -> None:
if bot.user is None:
ocd_logger.critical("Discord connection failed.")
return
ocd_logger.info(f"{bot.user.name} has connected to Discord!")
bot.add_view(OpenRaid())
ocd_logger.info("%s has connected to Discord!", bot.user.name)
# Run Discord bot
bot.run(settings.params.discord_token)
if __name__ == "__main__":
main()
@@ -2,7 +2,9 @@
from nextcord.ext import commands
from cogs.commands.birthday import BirthdayCog
from off_cooldown_bot.cogs.commands.test import TestCog
from .birthday import BirthdayCog
# This function will be called when this extension is loaded.
@@ -10,3 +12,4 @@ from cogs.commands.birthday import BirthdayCog
def setup(bot: commands.Bot) -> None:
"""Add all command classes to bot."""
bot.add_cog(BirthdayCog())
bot.add_cog(TestCog(bot))
@@ -7,15 +7,16 @@ from nextcord.ext import commands
from pytz import UTC
from sqlmodel import Session, col, select
from database.db import engine
from database.models import UserBirthday
from main import birthday_list
from off_cooldown_bot.app import birthday_list
from off_cooldown_bot.database.db import engine
from off_cooldown_bot.database.models import UserBirthday
from off_cooldown_bot.utils import GUILDS
class BirthdayCog(commands.Cog, name="Birthday Commands"):
"""Class holds birthday commands."""
@nextcord.slash_command(guild_ids=[1000247361639030804, 822199658306076672])
@nextcord.slash_command(guild_ids=GUILDS)
async def birthday(self, interaction: nextcord.Interaction) -> None:
"""Parent slash command for birthday. Never called."""
+43
View File
@@ -0,0 +1,43 @@
"""Commands for testing."""
import nextcord
from nextcord.ext import application_checks, commands
from off_cooldown_bot.open_raid import OpenRaid, build_raid_embed
from off_cooldown_bot.utils import GUILDS
ME = 206602713511886849
def is_me(): # noqa: ANN201
"""Predicate that makes sure only I can run the test commands."""
def predicate(interaction: nextcord.Interaction) -> bool:
if interaction.user is None:
return False
return interaction.user.id == ME
return application_checks.check(predicate)
class TestCog(commands.Cog, name="Test commands."):
"""Class holds commands for testing."""
def __init__(self, bot: commands.Bot) -> None:
self.bot: commands.Bot = bot
@nextcord.slash_command(guild_ids=GUILDS)
async def test(self, interaction: nextcord.Interaction) -> None:
"""Parent slash command for help. Never called."""
@test.subcommand()
@is_me()
async def open_raid(self, interaction: nextcord.Interaction) -> None:
"""
Force starts election.
Args:
interaction (nextcord.Interaction): Interaction with the message.
"""
await interaction.response.send_message("Starting an open raid.", embed=build_raid_embed(), view=OpenRaid())
@@ -2,8 +2,8 @@
from nextcord.ext import commands
from cogs.loops.bot_presence import BotPresence
from cogs.loops.daily_loop import DailyLoop
from .bot_presence import BotPresence
from .daily_loop import DailyLoop
def setup(bot: commands.Bot) -> None:
@@ -9,11 +9,12 @@ from sqlalchemy import select
from sqlalchemy.orm import Session
from sqlmodel import col
from database.db import engine
from database.models import UserBirthday
from logger import ocd_logger
from main import birthday_list
from settings import settings
from off_cooldown_bot.app import birthday_list
from off_cooldown_bot.database.db import engine
from off_cooldown_bot.database.models import UserBirthday
from off_cooldown_bot.logger import ocd_logger
from off_cooldown_bot.open_raid import OpenRaid, build_raid_embed
from off_cooldown_bot.settings import settings
class DailyLoop(commands.Cog, name="Daily Loop"):
@@ -25,14 +26,35 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
self.update_birthdays()
self.daily_loop.start()
@tasks.loop(time=time(hour=0, tzinfo=timezone("UTC")))
@tasks.loop(time=time(hour=0, tzinfo=UTC))
async def daily_loop(self) -> None:
"""Run daily repeated functions."""
self.update_birthdays()
await self.cakedays()
@tasks.loop(time=time(hour=20, tzinfo=timezone("CST")))
async def open_raid(self) -> None:
"""
Define the open raid loop.
Checks daily if it is Thursday and then posts the open raid sign up.
"""
today = datetime.now(timezone("CST"))
if today.day + 2 == 5:
# open raid is on Saturday, post 2 days before
if (guild := self.bot.get_guild(settings.params.guild_id)) is None:
ocd_logger.error("Guild id not correct.")
return
if (channel := guild.get_channel(settings.channel_ids.raid)) is None or not isinstance(
channel, nextcord.TextChannel
):
ocd_logger.error("Raid channel is not defined or is not a text channel.")
return
await channel.send(embed=build_raid_embed(), view=OpenRaid())
@daily_loop.before_loop
@open_raid.before_loop
async def before_loop(self) -> None:
"""Actions run before the loop starts. Want to wait for bot to be ready and get the current cycle."""
await self.bot.wait_until_ready()
@@ -3,7 +3,7 @@
import nextcord
from nextcord.ext import commands
from main import birthday_list
from off_cooldown_bot.app import birthday_list
class SubmissionListener(commands.Cog, name="Message Listener"):
@@ -4,8 +4,7 @@ from sqlmodel import SQLModel, create_engine
from . import models # noqa: F401 - Need this import for creating the models.
url = "sqlite:///database.db"
url = "sqlite:///database/database.db"
engine = create_engine(url)
# Don't need to create all when connected to prod.
SQLModel.metadata.create_all(engine)
+1 -1
View File
@@ -1,4 +1,4 @@
"""Creates logger for Agon bot."""
"""Creates logger for Off Cooldown bot."""
import logging
import sys
+151
View File
@@ -0,0 +1,151 @@
"""Contains functions for open raid sign-ups."""
import datetime
import nextcord
from off_cooldown_bot.logger import ocd_logger
MAX_TANKS = 2
MAX_HEALERS = 2
MAX_DPS = 25
class OpenRaid(nextcord.ui.View):
"""Class defines view for buttons on an open raid schedule message."""
def __init__(self) -> None:
super().__init__(timeout=None, auto_defer=True)
@nextcord.ui.button(label="Tank", style=nextcord.ButtonStyle.blurple, emoji="🛡️", custom_id="open_raid_tank")
async def tank(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
"""
Signs a user up as a tank.
Removes them if they are already signed up.
Args:
button (nextcord.ui.Button): Un-used.
interaction (nextcord.Interaction): Interaction with command.
"""
if interaction.message is None or interaction.user is None:
ocd_logger.warning("Command was called without a message or user.")
return
embed = interaction.message.embeds[0]
user_str = f"<@{interaction.user.id}>"
for index, field in enumerate(embed.fields):
if field.name == "Tanks":
values = [] if field.value is None else field.value.split("\n")
if user_str in values:
values.remove(user_str)
else:
if len(values) >= MAX_TANKS:
await interaction.response.send_message(
"Enough tanks have signed up, please choose another role.", ephemeral=True
)
return
values.append(user_str)
embed.set_field_at(index, name=field.name, value="\n".join(values), inline=False)
break
await interaction.edit(embed=embed)
@nextcord.ui.button(label="Healer", style=nextcord.ButtonStyle.green, emoji="❤️", custom_id="open_raid_healer")
async def healer(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
"""
Signs a user up as a healer.
Removes them if they are already signed up.
Args:
button (nextcord.ui.Button): Un-used.
interaction (nextcord.Interaction): Interaction with command.
"""
if interaction.message is None or interaction.user is None:
ocd_logger.warning("Command was called without a message or user.")
return
embed = interaction.message.embeds[0]
user_str = f"<@{interaction.user.id}>"
for index, field in enumerate(embed.fields):
if field.name == "Healers":
values = [] if field.value is None else field.value.split("\n")
if user_str in values:
values.remove(user_str)
else:
if len(values) >= MAX_HEALERS:
await interaction.response.send_message(
"Enough healers have signed up, please choose another role.", ephemeral=True
)
return
values.append(user_str)
embed.set_field_at(index, name=field.name, value="\n".join(values), inline=False)
break
await interaction.edit(embed=embed)
@nextcord.ui.button(label="DPS", style=nextcord.ButtonStyle.red, emoji="⚔️", custom_id="open_raid_dps")
async def dps(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
"""
Signs a user up as dps.
Removes them if they are already signed up.
Args:
button (nextcord.ui.Button): Un-used.
interaction (nextcord.Interaction): Interaction with command.
"""
if interaction.message is None or interaction.user is None:
ocd_logger.warning("Command was called without a message or user.")
return
embed = interaction.message.embeds[0]
user_str = f"<@{interaction.user.id}>"
for index, field in enumerate(embed.fields):
if field.name == "DPS":
values = [] if field.value is None else field.value.split("\n")
if user_str in values:
values.remove(user_str)
else:
if len(values) >= MAX_DPS:
await interaction.response.send_message(
"Enough dps have signed up, please choose another role.", ephemeral=True
)
return
values.append(user_str)
embed.set_field_at(index, name=field.name, value="\n".join(values), inline=False)
break
await interaction.edit(embed=embed)
def build_raid_embed() -> nextcord.Embed:
"""
Build the open raid embed.
Returns:
nextcord.Embed: Embed that shows the raid's sign-ups.
"""
today = datetime.datetime.now(tz=datetime.UTC).replace(hour=20)
saturday_idx = 5
days_delta = saturday_idx - today.weekday()
if days_delta < 0:
days_delta += 7
raid_time = today + datetime.timedelta(days_delta)
embed = nextcord.Embed(
title="Off Cooldown Open Raid", description=f"Raid time: t:{int(raid_time.timestamp())}:F", timestamp=raid_time
)
embed.add_field(name="Tanks", value="", inline=False)
embed.add_field(name="Healers", value="", inline=False)
embed.add_field(name="DPS", value="", inline=False)
return embed
@@ -12,6 +12,7 @@ class ChannelIds:
"""Class holds all channel ids needed by bot."""
general: int
raid: int
@dataclass
@@ -35,3 +36,7 @@ class Settings(YAMLWizard):
settings = Settings.from_yaml_file(CONFIG_LOCATION)
# I'm not expecting a list to be returned.
if isinstance(settings, list):
settings = settings[0]
+3
View File
@@ -0,0 +1,3 @@
"""File contains functions and variables used widely."""
GUILDS = [1000247361639030804, 822199658306076672]
-1
View File
@@ -6,7 +6,6 @@ authors = [{ name = "imcompiling", email = "[email protected]" }]
readme = "README.md"
dependencies = [
"nextcord>=2.6.0",
"python-dotenv>=1.0.1",
"sqlmodel>=0.0.22",
"dataclass-wizard[yaml]>=0.22.3,<1.0.0",
"pytz>=2025.1",
Generated
-11
View File
@@ -306,7 +306,6 @@ source = { virtual = "." }
dependencies = [
{ name = "dataclass-wizard", extra = ["yaml"] },
{ name = "nextcord" },
{ name = "python-dotenv" },
{ name = "pytz" },
{ name = "sqlmodel" },
]
@@ -320,7 +319,6 @@ dev = [
requires-dist = [
{ name = "dataclass-wizard", extras = ["yaml"], specifier = ">=0.22.3,<1.0.0" },
{ name = "nextcord", specifier = ">=2.6.0" },
{ name = "python-dotenv", specifier = ">=1.0.1" },
{ name = "pytz", specifier = ">=2025.1" },
{ name = "sqlmodel", specifier = ">=0.0.22" },
]
@@ -438,15 +436,6 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/51/b2/b2b50d5ecf21acf870190ae5d093602d95f66c9c31f9d5de6062eb329ad1/pydantic_core-2.27.2-cp313-cp313-win_arm64.whl", hash = "sha256:ac4dbfd1691affb8f48c2c13241a2e3b60ff23247cbcf981759c768b6633cf8b", size = 1885186 },
]
[[package]]
name = "python-dotenv"
version = "1.0.1"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/bc/57/e84d88dfe0aec03b7a2d4327012c1627ab5f03652216c63d49846d7a6c58/python-dotenv-1.0.1.tar.gz", hash = "sha256:e324ee90a023d808f1959c46bcbc04446a10ced277783dc6ee09987c37ec10ca", size = 39115 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/6a/3e/b68c118422ec867fa7ab88444e1274aa40681c606d59ac27de5a5588f082/python_dotenv-1.0.1-py3-none-any.whl", hash = "sha256:f7b63ef50f1b690dddf550d03497b66d609393b40b564ed0d674909a68ebf16a", size = 19863 },
]
[[package]]
name = "pytz"
version = "2025.1"