1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 20:23:12 +00:00

add config

This commit is contained in:
wlinator 2024-03-04 11:25:00 +01:00
parent e083dea9bb
commit 03dbc1abff
4 changed files with 36 additions and 35 deletions

View file

@ -3,10 +3,25 @@ import os
import discord
from dotenv import load_dotenv
from services.Birthday import Birthday
load_dotenv('.env')
async def birthday_module(ctx):
"""
Whether the Birthday module is enabled in a server depends on the field "birthday_channel_id" in racudb.server_config
NULL or INVALID: disabled
"""
birthday_channel_id = Birthday.get_birthday_channel_id(ctx.guild.id)
if not birthday_channel_id:
await ctx.respond(f"Birthdays are disabled in this server.", ephemeral=True)
return False
return True
async def channel(ctx):
desired_channel_id = 1118587309365940407 # bot-chat in RCU
owner_id = os.getenv("OWNER_ID")

View file

@ -143,6 +143,9 @@ async def on_application_command_error(ctx, error) -> None:
await ctx.respond(strings["error_bot_missing_permissions"].format(ctx.author.name), ephemeral=True)
logs.info(f"[CommandHandler] Racu is missing permissions: {ctx.command.qualified_name}")
elif isinstance(error, discord.CheckFailure) or isinstance(error, commands.CheckFailure):
logs.info(f"[CommandHandler] {ctx.author.name} tried to do \"/{ctx.command.qualified_name}\" but a check returned False.")
else:
logs.error(f"[CommandHandler] on_application_command_error: {error}", exc_info=True)

View file

@ -37,6 +37,7 @@ class BirthdayCog(commands.Cog):
description="Set your birthday."
)
@commands.cooldown(1, 10, commands.BucketType.user)
@commands.check(checks.birthday_module)
async def set_birthday(self, ctx, *,
month: discord.Option(choices=months),
day: discord.Option(int)):
@ -60,6 +61,7 @@ class BirthdayCog(commands.Cog):
description="See upcoming birthdays!"
)
@commands.cooldown(1, 10, commands.BucketType.user)
@commands.check(checks.birthday_module)
async def upcoming_birthdays(self, ctx):
upcoming_birthdays = Birthday.get_upcoming_birthdays()
icon = ctx.guild.icon if ctx.guild.icon else "https://i.imgur.com/79XfsbS.png"
@ -92,34 +94,6 @@ class BirthdayCog(commands.Cog):
await ctx.respond(embed=embed)
"""
TEMPORARILY DISABLED BECAUSE OF PERMISSIONS ISSUE
"""
# @birthday.command(
# name="override",
# description="Override a birthday - requires Manage Server."
# )
# @default_permissions(manage_guild=True)
# async def override_birthday(self, ctx, *,
# user: discord.Option(discord.Member),
# month: discord.Option(choices=months),
# day: discord.Option(int)):
# leap_year = 2020
# month_index = months.index(month) + 1
# max_days = calendar.monthrange(leap_year, month_index)[1]
# if not (1 <= day <= max_days):
# return await ctx.respond(strings["birthday_invalid_date"].format(ctx.author.name), ephemeral=True)
# date_str = f"{leap_year}-{month_index:02d}-{day:02d}"
# date_obj = datetime.datetime.strptime(date_str, '%Y-%m-%d')
# birthday = Birthday(user.id)
# birthday.set(date_obj)
# await ctx.respond(strings["birthday_override"].format(ctx.author.name, user.name, month, day))
@tasks.loop(hours=23, minutes=55)
async def daily_birthday_check(self):
@ -127,6 +101,13 @@ class BirthdayCog(commands.Cog):
logs.info(f"[BirthdayHandler] Waiting until 7 AM Eastern for daily check: {round(wait_time)}s")
await asyncio.sleep(wait_time)
for guild in self.client.guilds:
"""
Performs a birthday check for each server Racu is currently in with Birthdays enabled.
If a Birthday channel is not specified in racudb, the module is disabled.
"""
birthday_ids = Birthday.today()
if birthday_ids:

View file

@ -6,30 +6,32 @@ from db import database
class Birthday:
def __init__(self, user_id):
def __init__(self, user_id, guild_id):
self.user_id = user_id
self.guild_id = user_id
def set(self, birthday):
query = """
INSERT INTO birthdays (user_id, birthday)
VALUES (%s, %s)
INSERT INTO birthdays (user_id, guild_id, birthday)
VALUES (%s, %s, %s)
ON DUPLICATE KEY UPDATE birthday = VALUES(birthday);
"""
database.execute_query(query, (self.user_id, birthday))
database.execute_query(query, (self.user_id, self.guild_id, birthday))
@staticmethod
def today():
def today_from_guild(guild_id):
query = """
SELECT user_id
FROM birthdays
WHERE DATE_FORMAT(birthday, '%m-%d') = %s
AND guild_id = %s;
"""
tz = pytz.timezone('US/Eastern')
date = datetime.datetime.now(tz).strftime("%m-%d")
today = datetime.datetime.now(tz).strftime("%m-%d")
ids = database.select_query(query, (date,))
ids = database.select_query(query, (today,guild_id))
ids = [item[0] for item in ids]
return ids