1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-03 04:23:14 +00:00
Lumi/lib/embeds/error.py

145 lines
4.3 KiB
Python
Raw Normal View History

import discord
from lib import formatter
2024-07-17 12:01:12 +00:00
from lib.constants import CONST
2024-03-17 19:24:54 +00:00
def clean_error_embed(ctx):
embed = discord.Embed(
2024-07-17 11:47:26 +00:00
color=discord.Color.red(),
description=f"**{ctx.author.name}** ",
)
return embed
class GenericErrors:
2024-03-29 11:14:41 +00:00
@staticmethod
def bad_arg(ctx, error):
embed = clean_error_embed(ctx)
if embed.description is None:
embed.description = formatter.shorten(str(error), 100)
else:
embed.description += formatter.shorten(str(error), 100)
embed.set_footer(
text=f"For more info do {formatter.get_prefix(ctx)}help {formatter.get_invoked_name(ctx)}",
icon_url=CONST.QUESTION_ICON,
)
return embed
@staticmethod
def bad_url(ctx, error="the image URL must end with `.jpg` or `.png`."):
embed = clean_error_embed(ctx)
if embed.description is None:
embed.description = formatter.shorten(str(error), 100)
else:
embed.description += formatter.shorten(str(error), 100)
return embed
2024-03-18 17:48:12 +00:00
@staticmethod
def private_message_only(ctx):
embed = clean_error_embed(ctx)
if embed.description is None:
embed.description = "this command can only be used in private messages."
else:
embed.description += "this command can only be used in private messages."
embed.set_footer(
text=f"For more info do '{formatter.get_prefix(ctx)}help {formatter.get_invoked_name(ctx)}'",
icon_url=CONST.QUESTION_ICON,
)
2024-03-18 17:48:12 +00:00
return embed
2024-03-19 07:34:29 +00:00
@staticmethod
def guild_only(ctx):
embed = clean_error_embed(ctx)
if embed.description is None:
embed.description = "this command can only be used in a server."
else:
embed.description += "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=CONST.QUESTION_ICON,
)
2024-03-19 07:34:29 +00:00
return embed
2024-03-19 12:13:17 +00:00
@staticmethod
def channel_not_allowed(ctx, channel):
embed = clean_error_embed(ctx)
if embed.description is None:
embed.description = f"you can only do that command in {channel.mention}."
else:
embed.description += f"you can only do that command in {channel.mention}."
embed.set_footer(
2024-07-17 11:47:26 +00:00
text="This message will delete itself after 5s",
icon_url=CONST.EXCLAIM_ICON,
)
2024-03-19 12:13:17 +00:00
return embed
class EconErrors:
2024-03-17 19:24:54 +00:00
@staticmethod
def out_of_time(ctx):
embed = clean_error_embed(ctx)
if embed.description is None:
embed.description = "you ran out of time."
else:
embed.description += "you ran out of time."
embed.set_footer(text="Your bet was forfeited", icon_url=CONST.EXCLAIM_ICON)
2024-03-17 19:24:54 +00:00
return embed
@staticmethod
def already_playing(ctx):
embed = clean_error_embed(ctx)
if embed.description is None:
embed.description = (
f"you already have a game of {ctx.command.name} running."
)
else:
embed.description += (
f"you already have a game of {ctx.command.name} running."
)
embed.set_footer(
2024-07-17 11:47:26 +00:00
text="Please finish this game first",
icon_url=CONST.EXCLAIM_ICON,
)
2024-03-17 19:24:54 +00:00
return embed
2024-03-17 20:44:21 +00:00
2024-03-19 17:35:51 +00:00
class MiscErrors:
@staticmethod
def prefix_too_long(ctx):
embed = clean_error_embed(ctx)
if embed.description is None:
embed.description = "this prefix is too long."
else:
embed.description += "this prefix is too long."
embed.set_footer(
text=f"For more info do '{formatter.get_prefix(ctx)}help {formatter.get_invoked_name(ctx)}'",
icon_url=CONST.QUESTION_ICON,
)
2024-03-19 17:35:51 +00:00
return embed
2024-03-18 14:40:58 +00:00
class HelpErrors:
@staticmethod
def error_message(ctx, error):
"""
See discord.ext.commands.HelpCommand.send_error_message
"""
embed = clean_error_embed(ctx)
embed.description += error
embed.set_footer(
2024-07-17 11:47:26 +00:00
text=f"See '{formatter.get_prefix(ctx)}help'",
icon_url=CONST.EXCLAIM_ICON,
)
2024-03-18 14:40:58 +00:00
2024-03-25 14:48:00 +00:00
return embed