Compare commits
23
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e243b40be7 | ||
|
|
7a91cd37ec | ||
|
|
efadcb30c7 | ||
|
|
5668e4be7e | ||
|
|
1a8c5616ef | ||
|
|
43c1a5c6cd | ||
|
|
c278bae498 | ||
|
|
8b831fb6aa | ||
|
|
e7cfe8bd4c | ||
|
|
2640ebdad1 | ||
|
|
c5c242de21 | ||
|
|
0710db0654 | ||
|
|
369ea0dd55 | ||
|
|
077119acdd | ||
|
|
ac8d1bc681 | ||
|
|
df8cb3dd49 | ||
|
|
25833364d7 | ||
|
|
d73b671257 | ||
|
|
f6e827fba5 | ||
|
|
2991f81e04 | ||
|
|
b1c0b7013d | ||
|
|
22ea29e8ea | ||
|
|
f9d6227db1 |
@@ -0,0 +1,28 @@
|
|||||||
|
name: build_release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags: ["v[0-9].[0-9].[0-9]"]
|
||||||
|
|
||||||
|
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: Log into container registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: gitea.cheezers.org
|
||||||
|
username: imcompiling
|
||||||
|
password: ${{ secrets.PASSWORD }}
|
||||||
|
- name: Set env
|
||||||
|
run: echo "GIT_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||||
|
- name: Build Docker Image
|
||||||
|
run: docker build -t gitea.cheezers.org/imcompiling/dakiny-bot:${{env.GIT_TAG}} .
|
||||||
|
- name: Push Tagged Image
|
||||||
|
run: docker push gitea.cheezers.org/imcompiling/dakiny-bot:${{env.GIT_TAG}}
|
||||||
+1
-1
@@ -139,4 +139,4 @@ TODO.txt
|
|||||||
sql_tester.py
|
sql_tester.py
|
||||||
conf
|
conf
|
||||||
outputs
|
outputs
|
||||||
dakiny.db
|
database
|
||||||
+8
-3
@@ -1,4 +1,4 @@
|
|||||||
FROM python:3.8.10-slim
|
FROM python:3.10.6-slim
|
||||||
|
|
||||||
# install dependencies for mysqlclient
|
# install dependencies for mysqlclient
|
||||||
# RUN apt-get update && apt-get -y upgrade && apt-get -y install python3-dev default-libmysqlclient-dev build-essential
|
# RUN apt-get update && apt-get -y upgrade && apt-get -y install python3-dev default-libmysqlclient-dev build-essential
|
||||||
@@ -7,11 +7,16 @@ RUN pip install --upgrade pip
|
|||||||
|
|
||||||
WORKDIR /home
|
WORKDIR /home
|
||||||
|
|
||||||
COPY cogs cogs/
|
|
||||||
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 dakiny_bot.py dakiny_bot.py
|
||||||
|
COPY utils.py utils.py
|
||||||
|
|
||||||
|
COPY bot_messages bot_messages/
|
||||||
COPY classes classes/
|
COPY classes classes/
|
||||||
|
COPY cogs cogs/
|
||||||
|
COPY database_setup database_setup/
|
||||||
|
|
||||||
RUN pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from sqlalchemy import select
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from config import DakinyConfig
|
from config import DakinyConfig
|
||||||
from database.sql_data_classes import ElectionInformation, engine
|
from database_setup.sql_data_classes import ElectionInformation, engine
|
||||||
from utils import get_datetime
|
from utils import get_datetime
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ Cog loader. Adds all command cogs to the bot.
|
|||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
from cogs.commands.request import RequestCog
|
from cogs.commands.request import RequestCog
|
||||||
|
from cogs.commands.set import setCog
|
||||||
from cogs.commands.test import TestCog
|
from cogs.commands.test import TestCog
|
||||||
|
|
||||||
|
|
||||||
@@ -14,5 +15,7 @@ def setup(bot: commands.Bot):
|
|||||||
"""
|
"""
|
||||||
Adds all command classes to bot.
|
Adds all command classes to bot.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
bot.add_cog(RequestCog(bot))
|
bot.add_cog(RequestCog(bot))
|
||||||
bot.add_cog(TestCog(bot))
|
bot.add_cog(TestCog(bot))
|
||||||
|
bot.add_cog(setCog())
|
||||||
|
|||||||
@@ -99,5 +99,5 @@ class UsernameRequest(nextcord.ui.View):
|
|||||||
button (nextcord.ui.Button): Unused.
|
button (nextcord.ui.Button): Unused.
|
||||||
interaction (nextcord.Interaction): The interaction of the user clicking the button.
|
interaction (nextcord.Interaction): The interaction of the user clicking the button.
|
||||||
"""
|
"""
|
||||||
content = interaction.message.content + f"\nDenied by <@{interaction.user.id}.>"
|
content = interaction.message.content + f"\nDenied by <@{interaction.user.id}>."
|
||||||
await interaction.response.edit_message(content=content, view=None)
|
await interaction.response.edit_message(content=content, view=None)
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
"""
|
||||||
|
Contains commands and views for set commands.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
import nextcord
|
||||||
|
from nextcord.ext import commands
|
||||||
|
from sqlalchemy import delete, select
|
||||||
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from dakiny_bot import birthday_list
|
||||||
|
from database_setup.sql_data_classes import UserBirthday, engine
|
||||||
|
|
||||||
|
|
||||||
|
class setCog(commands.Cog, name="Set Commands"):
|
||||||
|
"""
|
||||||
|
Class holds set commands.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
"""
|
||||||
|
Default constructor for SetCog class. Does nothing.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@nextcord.slash_command()
|
||||||
|
async def set(self, interaction: nextcord.Interaction):
|
||||||
|
"""
|
||||||
|
Parent slash command for set. Never called.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@set.subcommand(description="Sets your birth month and day for the Birthday Fun. Use 0/0 to remove yourself.")
|
||||||
|
async def birthday(
|
||||||
|
self,
|
||||||
|
interaction: nextcord.Interaction,
|
||||||
|
month: int = nextcord.SlashOption(required=True, min_value=0, max_value=12, description="Your birth month."),
|
||||||
|
day: int = nextcord.SlashOption(required=True, min_value=0, max_value=31, description="Your birth day."),
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Sets a user's birthday in the database. Removes on input 0/0. If birthday is today, adds to the birthday_list.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
|
month (int, optional): The month a user was born. Is SlashOption.
|
||||||
|
day (int, optional): The day a user was born. Is SlashOption.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Must be deferred, apparently datetime takes a little bit on invalid dates.
|
||||||
|
await interaction.response.defer(ephemeral=True)
|
||||||
|
|
||||||
|
if month == 0 and day == 0:
|
||||||
|
stmt = delete(UserBirthday).where(UserBirthday.UserId == interaction.user.id)
|
||||||
|
with Session(engine) as session:
|
||||||
|
session.execute(stmt)
|
||||||
|
session.commit()
|
||||||
|
await interaction.followup.send("Removed birthday.", ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
# check if valid day
|
||||||
|
today = datetime.today()
|
||||||
|
try:
|
||||||
|
birthday = datetime(today.year, month, day)
|
||||||
|
except ValueError:
|
||||||
|
await interaction.followup.send(f"Invalid date: {month}/{day}.", ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
# If the birthday is today, add to birthday_list
|
||||||
|
if today.date() == birthday.date():
|
||||||
|
birthday_list.append(interaction.user.id)
|
||||||
|
|
||||||
|
new_birthday = UserBirthday(UserId=interaction.user.id, Birthday=f"{month}/{day}")
|
||||||
|
with Session(engine) as session:
|
||||||
|
try:
|
||||||
|
session.add(new_birthday)
|
||||||
|
session.commit()
|
||||||
|
except IntegrityError:
|
||||||
|
# User already has birthday, change it instead.
|
||||||
|
session.rollback()
|
||||||
|
stmt = select(UserBirthday).where(UserBirthday.UserId == interaction.user.id)
|
||||||
|
new_birthday = session.scalar(stmt)
|
||||||
|
new_birthday.Birthday = f"{month}/{day}"
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
await interaction.followup.send(f"Birthday set to {month}/{day}.", ephemeral=True)
|
||||||
+41
-10
@@ -2,13 +2,18 @@
|
|||||||
Defines the daily loop that runs the Dakiny bot functions.
|
Defines the daily loop that runs the Dakiny bot functions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import random
|
||||||
from datetime import datetime, time
|
from datetime import datetime, time
|
||||||
|
|
||||||
from nextcord.ext import commands, tasks
|
from nextcord.ext import commands, tasks
|
||||||
from pytz import timezone
|
from pytz import timezone
|
||||||
|
from sqlalchemy import select
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from classes.election_cycle import ElectionCycle
|
from classes.election_cycle import ElectionCycle
|
||||||
from config import DakinyConfig
|
from config import DakinyConfig
|
||||||
|
from dakiny_bot import birthday_list
|
||||||
|
from database_setup.sql_data_classes import UserBirthday, engine
|
||||||
from utils import get_datetime
|
from utils import get_datetime
|
||||||
|
|
||||||
|
|
||||||
@@ -19,16 +24,11 @@ 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.current_election = self.get_current_cycle()
|
self.current_election = None
|
||||||
|
self.update_birthdays()
|
||||||
|
|
||||||
@commands.Cog.listener()
|
# pylint doesn't recognize that daily_loop is subclassed from tasks.loop.
|
||||||
async def on_ready(self):
|
self.daily_loop.start() # pylint: disable=no-member
|
||||||
"""
|
|
||||||
Starts the loop when bot is ready.
|
|
||||||
"""
|
|
||||||
await self.bot.wait_until_ready()
|
|
||||||
# pylint doesn't recognize that periodic_update_guild_data is subclassed from tasks.loop.
|
|
||||||
await self.daily_loop.start() # pylint: disable=no-member
|
|
||||||
|
|
||||||
@tasks.loop(time=time(hour=0, tzinfo=timezone("GMT")))
|
@tasks.loop(time=time(hour=0, tzinfo=timezone("GMT")))
|
||||||
async def daily_loop(self):
|
async def daily_loop(self):
|
||||||
@@ -46,6 +46,19 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
|||||||
if self.current_election.election_over:
|
if self.current_election.election_over:
|
||||||
self.current_election = None
|
self.current_election = None
|
||||||
|
|
||||||
|
self.update_birthdays()
|
||||||
|
|
||||||
|
@daily_loop.before_loop
|
||||||
|
async def before_loop(self):
|
||||||
|
"""
|
||||||
|
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()
|
||||||
|
|
||||||
|
# Bot needs to know guilds to get the current cycle.
|
||||||
|
self.current_election = self.get_current_cycle()
|
||||||
|
|
||||||
def get_current_cycle(self) -> ElectionCycle:
|
def get_current_cycle(self) -> ElectionCycle:
|
||||||
"""
|
"""
|
||||||
Creates an object for the current election cycle if one is active. An election is considered active
|
Creates an object for the current election cycle if one is active. An election is considered active
|
||||||
@@ -61,9 +74,27 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
|||||||
|
|
||||||
for cycle, election in enumerate(config.election_cycles):
|
for cycle, election in enumerate(config.election_cycles):
|
||||||
if (
|
if (
|
||||||
today.date() > get_datetime(election.election_start).date()
|
today.date() >= get_datetime(election.election_start).date()
|
||||||
and today.date() < get_datetime(election.term_start).date()
|
and today.date() < get_datetime(election.term_start).date()
|
||||||
):
|
):
|
||||||
current_election = ElectionCycle(cycle, config, self.bot.get_guild(config.params.guild_id))
|
current_election = ElectionCycle(cycle, config, self.bot.get_guild(config.params.guild_id))
|
||||||
|
|
||||||
return current_election
|
return current_election
|
||||||
|
|
||||||
|
def update_birthdays(self) -> None:
|
||||||
|
"""
|
||||||
|
Goes through database to collect all birthdays that are today. Adds user's id to birthday list.
|
||||||
|
"""
|
||||||
|
birthday_list.clear()
|
||||||
|
|
||||||
|
# kandy's 1% chance
|
||||||
|
if random.randint(0, 99) == 0:
|
||||||
|
birthday_list.append(239547993106284544)
|
||||||
|
|
||||||
|
today = datetime.today()
|
||||||
|
birthday = f"{today.month}/{today.day}"
|
||||||
|
|
||||||
|
stmt = select(UserBirthday.UserId).where(UserBirthday.Birthday == birthday)
|
||||||
|
with Session(engine) as session:
|
||||||
|
to_add = session.scalars(stmt)
|
||||||
|
birthday_list.extend(to_add.all())
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
"""
|
||||||
|
Defines cog for on message listener.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import nextcord
|
||||||
|
from nextcord.ext import commands
|
||||||
|
|
||||||
|
from dakiny_bot import birthday_list
|
||||||
|
|
||||||
|
|
||||||
|
class SubmissionListener(commands.Cog, name="Message Listener"):
|
||||||
|
"""Sets up message listener."""
|
||||||
|
|
||||||
|
def __init__(self, bot: commands.Bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_message(self, message: nextcord.Message):
|
||||||
|
"""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:
|
||||||
|
return
|
||||||
|
|
||||||
|
await birthday_action(message)
|
||||||
|
|
||||||
|
|
||||||
|
# This function will be called when this extension is loaded.
|
||||||
|
# It is necessary to add these functions to the bot.
|
||||||
|
def setup(bot: commands.Bot):
|
||||||
|
"""Adds function to bot"""
|
||||||
|
bot.add_cog(SubmissionListener(bot))
|
||||||
|
|
||||||
|
|
||||||
|
async def birthday_action(message: nextcord.Message) -> None:
|
||||||
|
"""
|
||||||
|
Checks a message's auther and mentions to see if they are in the birthday list.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
message (nextcord.Message): The message to check for a birthday person.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if message.author.id in birthday_list or bool(set(message.raw_mentions) & set(birthday_list)):
|
||||||
|
await message.add_reaction("🎂")
|
||||||
@@ -11,7 +11,7 @@ class Params:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
active_category_id: int
|
active_category_id: int
|
||||||
admin_channel_id: int
|
admin_channel_id: int # might want to rename this...
|
||||||
annoucement_category_id: int
|
annoucement_category_id: int
|
||||||
archive_channel_group_id: int
|
archive_channel_group_id: int
|
||||||
clan_council_elect_role_id: int
|
clan_council_elect_role_id: int
|
||||||
|
|||||||
+13
-2
@@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@@ -6,12 +7,20 @@ import nextcord
|
|||||||
from hydra.core.config_store import ConfigStore
|
from hydra.core.config_store import ConfigStore
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
import database.create_database as create_database
|
import database_setup.create_database as create_database
|
||||||
from config import DakinyConfig
|
from config import DakinyConfig
|
||||||
|
|
||||||
cs = ConfigStore.instance()
|
cs = ConfigStore.instance()
|
||||||
cs.store(name="dakiny_config", node=DakinyConfig)
|
cs.store(name="dakiny_config", node=DakinyConfig)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
@hydra.main(config_path="conf", config_name="config")
|
@hydra.main(config_path="conf", config_name="config")
|
||||||
def main(cfg: DakinyConfig):
|
def main(cfg: DakinyConfig):
|
||||||
@@ -48,4 +57,6 @@ def main(cfg: DakinyConfig):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.argv.append("hydra.job.chdir=False")
|
sys.argv.append("hydra.job.chdir=False")
|
||||||
main()
|
sys.argv.append("hydra/job_logging=none")
|
||||||
|
sys.argv.append("hydra/hydra_logging=none")
|
||||||
|
main() # pylint: disable=no-value-for-parameter
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ Small script to create the database if it doesn't already exist.
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
|
|
||||||
if not exists("dakiny.db"):
|
if not exists("database/dakiny.db"):
|
||||||
with sqlite3.connect("dakiny.db") as con:
|
with sqlite3.connect("database/dakiny.db") as con:
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
|
|
||||||
with open("database/database.sql", mode="r", encoding="utf-8") as file:
|
with open("database_setup/database.sql", mode="r", encoding="utf-8") as file:
|
||||||
database_script = file.read()
|
database_script = file.read()
|
||||||
cur.executescript(database_script)
|
cur.executescript(database_script)
|
||||||
con.commit()
|
con.commit()
|
||||||
@@ -1,6 +1,3 @@
|
|||||||
-- CREATE DATABASE dakiny;
|
|
||||||
-- use dakiny;
|
|
||||||
|
|
||||||
CREATE TABLE ElectionInformation(
|
CREATE TABLE ElectionInformation(
|
||||||
ElectionCycle varchar(30) not null unique,
|
ElectionCycle varchar(30) not null unique,
|
||||||
ElectionChannel bigint unsigned not null,
|
ElectionChannel bigint unsigned not null,
|
||||||
@@ -24,4 +21,10 @@ CREATE TABLE Votes(
|
|||||||
VotedForId bigint unsigned not null,
|
VotedForId bigint unsigned not null,
|
||||||
FOREIGN KEY (ElectionCycle) REFERENCES ElectionInformation(ElectionCycle),
|
FOREIGN KEY (ElectionCycle) REFERENCES ElectionInformation(ElectionCycle),
|
||||||
PRIMARY KEY (ElectionCycle, VoterId)
|
PRIMARY KEY (ElectionCycle, VoterId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE UserBirthday (
|
||||||
|
UserId bigint unsigned not null,
|
||||||
|
Birthday varchar(5) not null,
|
||||||
|
PRIMARY KEY (UserId)
|
||||||
);
|
);
|
||||||
@@ -5,7 +5,7 @@ from sqlalchemy import create_engine
|
|||||||
from sqlalchemy.ext.automap import automap_base
|
from sqlalchemy.ext.automap import automap_base
|
||||||
|
|
||||||
# connect with sql alchemy and autoload schema
|
# connect with sql alchemy and autoload schema
|
||||||
URL = "sqlite+pysqlite:///dakiny.db"
|
URL = "sqlite+pysqlite:///database/dakiny.db"
|
||||||
engine = create_engine(URL)
|
engine = create_engine(URL)
|
||||||
Base = automap_base()
|
Base = automap_base()
|
||||||
Base.prepare(autoload_with=engine)
|
Base.prepare(autoload_with=engine)
|
||||||
@@ -14,3 +14,4 @@ Base.prepare(autoload_with=engine)
|
|||||||
ElectionInformation = Base.classes.ElectionInformation
|
ElectionInformation = Base.classes.ElectionInformation
|
||||||
CouncilMembers = Base.classes.CouncilMembers
|
CouncilMembers = Base.classes.CouncilMembers
|
||||||
Votes = Base.classes.Votes
|
Votes = Base.classes.Votes
|
||||||
|
UserBirthday = Base.classes.UserBirthday
|
||||||
Reference in New Issue
Block a user