mirror of
https://github.com/wlinator/luminara.git
synced 2024-10-02 20:23:12 +00:00
Make birthdays a bridge command and fix info/errors
This commit is contained in:
parent
a5ca8ad97c
commit
6d540771f5
5 changed files with 78 additions and 21 deletions
|
@ -4,6 +4,20 @@
|
|||
"May", "June", "July", "August",
|
||||
"September", "October", "November", "December"
|
||||
],
|
||||
"month_mapping": {
|
||||
"jan": "January",
|
||||
"feb": "February",
|
||||
"mar": "March",
|
||||
"apr": "April",
|
||||
"may": "May",
|
||||
"jun": "June",
|
||||
"jul": "July",
|
||||
"aug": "August",
|
||||
"sep": "September",
|
||||
"oct": "October",
|
||||
"nov": "November",
|
||||
"dec": "December"
|
||||
},
|
||||
"birthday_messages": [
|
||||
"🎂 Happy Birthday, **{0}**! 🎉 Wishing you a day filled with joy and laughter.",
|
||||
"🎈 It's party time! Happy Birthday, **{0}**! 🎉",
|
||||
|
|
|
@ -186,6 +186,24 @@ class BdayErrors:
|
|||
|
||||
return embed
|
||||
|
||||
@staticmethod
|
||||
def bad_month(ctx):
|
||||
embed = clean_error_embed(ctx)
|
||||
embed.description += "I couldn't recognize that month."
|
||||
embed.set_footer(text=f"For more info do '{formatter.get_prefix(ctx)}help {formatter.get_invoked_name(ctx)}'",
|
||||
icon_url=question_icon)
|
||||
|
||||
return embed
|
||||
|
||||
@staticmethod
|
||||
def missing_arg(ctx):
|
||||
embed = clean_error_embed(ctx)
|
||||
embed.description += "please enter a month and a day, in that order."
|
||||
embed.set_footer(text=f"For more info do '{formatter.get_prefix(ctx)}help {formatter.get_invoked_name(ctx)}'",
|
||||
icon_url=question_icon)
|
||||
|
||||
return embed
|
||||
|
||||
|
||||
class MiscErrors:
|
||||
@staticmethod
|
||||
|
|
|
@ -60,9 +60,18 @@ class MiscInfo:
|
|||
|
||||
@staticmethod
|
||||
def get_prefix(ctx, prefix):
|
||||
embed= clean_info_embed(ctx)
|
||||
embed = clean_info_embed(ctx)
|
||||
embed.description += f"my prefix is `{prefix}`"
|
||||
embed.set_footer(text=f"You can change this with '{formatter.get_prefix(ctx)}setprefix'",
|
||||
icon_url=question_icon)
|
||||
|
||||
return embed
|
||||
|
||||
|
||||
class BdayInfo:
|
||||
@staticmethod
|
||||
def set_month(ctx, month, day):
|
||||
embed = clean_info_embed(ctx)
|
||||
embed.description += f"your birthday was set to {month} {day}."
|
||||
|
||||
return embed
|
||||
|
|
|
@ -8,13 +8,13 @@ from discord.ext import commands, tasks, bridge
|
|||
from services.Birthday import Birthday
|
||||
from services.GuildConfig import GuildConfig
|
||||
from lib import time, checks
|
||||
from lib.embeds.error import BdayErrors
|
||||
from lib.embeds.error import BdayErrors, GenericErrors
|
||||
from modules.birthdays import upcoming, birthday
|
||||
from config import json_loader
|
||||
|
||||
logs = logging.getLogger('Racu.Core')
|
||||
data = json_loader.load_birthday()
|
||||
months = data["months"]
|
||||
month_mapping = data["month_mapping"]
|
||||
messages = data["birthday_messages"]
|
||||
|
||||
|
||||
|
@ -23,31 +23,30 @@ class Birthdays(commands.Cog):
|
|||
self.client = client
|
||||
self.daily_birthday_check.start()
|
||||
|
||||
@commands.command(
|
||||
@bridge.bridge_command(
|
||||
name="birthday",
|
||||
aliases=["bday"],
|
||||
help="Due to the complexity of the birthday system, you can only use Slash Commands "
|
||||
"to set your birthday. Please use `/birthday` to configure your birthday."
|
||||
)
|
||||
@commands.guild_only()
|
||||
@commands.check(checks.channel)
|
||||
async def birthday_command(self, ctx):
|
||||
return await ctx.respond(embed=BdayErrors.slash_command_only(ctx))
|
||||
|
||||
@commands.slash_command(
|
||||
name="birthday",
|
||||
description="Set your birthday.",
|
||||
guild_only=True
|
||||
)
|
||||
@commands.cooldown(1, 30, commands.BucketType.user)
|
||||
@commands.check(checks.birthday_module)
|
||||
@commands.check(checks.channel)
|
||||
async def set_birthday(self, ctx, *,
|
||||
month: discord.Option(choices=months),
|
||||
day: discord.Option(int, max_value=31)):
|
||||
async def set_birthday(self, ctx, month: str, *, day: int):
|
||||
"""
|
||||
Set your birthday. You can use abbreviations for months, like "jan" and "nov".
|
||||
Racu reads only the first three characters to decide the month.
|
||||
"""
|
||||
|
||||
month_index = months.index(month) + 1
|
||||
await birthday.cmd(ctx, month, month_index, day)
|
||||
month_name = await birthday.get_month_name(month, month_mapping)
|
||||
month_index = await birthday.get_month_index(month_name, month_mapping)
|
||||
await birthday.cmd(ctx, month_name, month_index, day)
|
||||
|
||||
@set_birthday.error
|
||||
async def on_command_error(self, ctx, error):
|
||||
if isinstance(error, commands.MissingRequiredArgument):
|
||||
await ctx.respond(embed=BdayErrors.missing_arg(ctx))
|
||||
elif isinstance(error, commands.BadArgument):
|
||||
await ctx.respond(embed=BdayErrors.bad_month(ctx))
|
||||
|
||||
@bridge.bridge_command(
|
||||
name="upcoming",
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import datetime
|
||||
import calendar
|
||||
|
||||
from discord.ext import commands
|
||||
from services.Birthday import Birthday
|
||||
from lib.embeds.error import BdayErrors
|
||||
from lib.embeds.info import BdayInfo
|
||||
|
||||
from main import strings
|
||||
|
||||
|
@ -21,4 +23,19 @@ async def cmd(ctx, month, month_index, day):
|
|||
birthday = Birthday(ctx.author.id, ctx.guild.id)
|
||||
birthday.set(date_obj)
|
||||
|
||||
await ctx.respond(strings["birthday_set"].format(ctx.author.name, month, day), ephemeral=True)
|
||||
await ctx.respond(embed=BdayInfo.set_month(ctx, month, day))
|
||||
|
||||
|
||||
async def get_month_name(string, mapping):
|
||||
string = string.lower()
|
||||
|
||||
for month in mapping:
|
||||
if string.startswith(month):
|
||||
return mapping[month]
|
||||
|
||||
raise commands.BadArgument
|
||||
|
||||
|
||||
async def get_month_index(string, mapping):
|
||||
values = list(mapping.values())
|
||||
return values.index(string) + 1
|
||||
|
|
Loading…
Reference in a new issue