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

Make birthdays slash-only

This commit is contained in:
wlinator 2024-03-19 08:34:29 +01:00
parent cf21878d6e
commit 8966e7afba
5 changed files with 47 additions and 10 deletions

View file

@ -65,6 +65,15 @@ class GenericErrors:
return embed
@staticmethod
def guild_only(ctx):
embed = clean_error_embed(ctx)
embed.description += f"this command can only be used in a server."
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 EconErrors:
@staticmethod
@ -160,6 +169,15 @@ class BdayErrors:
return embed
@staticmethod
def slash_command_only(ctx):
embed = clean_error_embed(ctx)
embed.description += "you can use only slash commands for the birthday system."
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 HelpErrors:
@staticmethod

18
main.py
View file

@ -21,7 +21,10 @@ instance = os.getenv("INSTANCE")
def get_prefix(bot, message):
return GuildConfig.get_prefix(message.guild.id)
try:
return GuildConfig.get_prefix(message.guild.id)
except AttributeError:
return "."
client = bridge.Bot(
@ -52,7 +55,12 @@ async def on_ready():
@client.listen()
async def on_message(message):
if message.author.bot or instance.lower() != "main":
if (
message.author.bot or
message.guild is None or
instance.lower() != "main"
):
return
try:
@ -129,6 +137,12 @@ async def on_command_error(ctx, error) -> None:
elif isinstance(error, commands.BotMissingPermissions):
await ctx.respond(embed=GenericErrors.bot_missing_permissions(ctx))
elif isinstance(error, commands.PrivateMessageOnly):
await ctx.respond(embed=GenericErrors.private_message_only(ctx))
elif isinstance(error, commands.NoPrivateMessage):
await ctx.respond(embed=GenericErrors.guild_only(ctx))
elif isinstance(error, (discord.CheckFailure, commands.CheckFailure)):
logs.info(f"[CommandHandler] {ctx.author.name} check failure: \"/{ctx.command.qualified_name}\"")

View file

@ -27,6 +27,18 @@ class Birthdays(commands.Cog):
self.client = client
self.daily_birthday_check.start()
@commands.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 set` to configure your birthday or `/birthday upcoming` "
"to see all upcoming birthdays in this server."
)
@commands.guild_only()
@commands.check(checks.channel)
async def birthday_command(self, ctx):
return await ctx.respond(embed=BdayErrors.slash_command_only(ctx))
birthday = SlashCommandGroup("birthday", "various birthday commands.", guild_only=True)
@birthday.command(

View file

@ -48,14 +48,6 @@ class Misc(commands.Cog):
async def intro_command(self, ctx):
return await introduction.cmd(self, ctx)
@intro_command.error
async def on_command_error(self, ctx, error):
if isinstance(error, commands.PrivateMessageOnly):
await ctx.respond(embed=GenericErrors.private_message_only(ctx))
else:
await ctx.respond(embed=GenericErrors.default_exception(ctx))
raise error
def setup(client):
client.add_cog(Misc(client))

View file

@ -17,6 +17,7 @@ class SayCog(commands.Cog):
description="Bot admin only.",
guild_only=True
)
@commands.guild_only()
@commands.check(checks.bot_owner)
async def say(self, ctx, *, txt: discord.Option(str)):
await ctx.respond(content="", ephemeral=True)