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

Add /birthday command

This commit is contained in:
wlinator 2023-07-31 11:16:04 -04:00
parent ed8c7edeb7
commit 8843a0b7d5
6 changed files with 102 additions and 3 deletions

View file

@ -48,5 +48,7 @@
"level_up": "\uD83D\uDCC8 | **{0}** you have reached **Level {1}**",
"level_up_prefix": "\uD83D\uDCC8 | **{0}** ",
"level_up_reward": "\uD83C\uDD99 | **{0}** congratulations! You've reached **Level {1}** and earned a new level role!",
"bet_limit": "❌ | **{0}** you cannot place any bets above **${1}**."
"bet_limit": "❌ | **{0}** you cannot place any bets above **${1}**.",
"birthday_invalid_date": "❌ | **{0}** the date you entered is invalid.",
"birthday_set": "✅ | **{0}** your birthday was set to **{1} {2}**."
}

35
data/Birthday.py Normal file
View file

@ -0,0 +1,35 @@
import datetime
import pytz
from db import database
class Birthday:
def __init__(self, user_id):
self.user_id = user_id
def set(self, birthday):
query = """
INSERT OR REPLACE INTO birthdays
(user_id, birthday)
VALUES (?, ?)
"""
database.execute_query(query, (self.user_id, birthday))
@staticmethod
def today():
query = """
SELECT user_id
FROM birthdays
WHERE strftime('%m-%d', birthday) = ?
"""
tz = pytz.timezone('US/Eastern')
date = datetime.datetime.now(tz).strftime("%m-%d")
ids = database.select_query(query, (date,))
ids = [item[0] for item in ids]
return ids

View file

@ -25,7 +25,6 @@ class Dailies:
else:
# set date as yesterday to pretend as a valid claimed_at.
self.claimed_at = datetime.now(tz=self.tz) - timedelta(days=2)
print(self.claimed_at)
self.streak = int(data[1])

View file

@ -98,6 +98,13 @@ CREATE TABLE IF NOT EXISTS stats_duel (
)
"""
birthdays_table = """
CREATE TABLE IF NOT EXISTS birthdays (
user_id INTEGER PRIMARY KEY,
birthday REAL
)
"""
def sync_database():
database.execute_query(xp_table)
@ -109,5 +116,6 @@ def sync_database():
database.execute_query(stats_bj)
database.execute_query(stats_slots)
database.execute_query(stats_duel)
database.execute_query(birthdays_table)
racu_logs.info("Database was synced.")

View file

@ -220,7 +220,8 @@ async def on_application_command_error(ctx, error) -> None:
await ctx.respond(
f"⏳ | **{ctx.author.name}** you are on cooldown. "
f"You can use this command again in **{cooldown}**.")
f"You can use this command again in **{cooldown}**.",
ephemeral=True)
racu_logs.info(f"commands.CommandOnCooldown | {ctx.author.name}")

54
modules/birthday.py Normal file
View file

@ -0,0 +1,54 @@
import calendar
import datetime
import logging
import discord
from discord.ext import commands
from data.Birthday import Birthday
from main import strings
racu_logs = logging.getLogger('Racu.Core')
months = [
"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
]
class BirthdayCog(commands.Cog):
def __init__(self, sbbot):
self.bot = sbbot
@commands.slash_command(
name="birthday",
description="Set your birthday.",
guild_only=True
)
@commands.cooldown(1, 10, commands.BucketType.user)
async def set_birthday(self, ctx, *,
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(ctx.author.id)
birthday.set(date_obj)
await ctx.respond(strings["birthday_set"].format(ctx.author.name, month, day), ephemeral=True)
def daily_birthday_check(self):
# check if someone's birthday is today
pass
def setup(sbbot):
sbbot.add_cog(BirthdayCog(sbbot))