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

Refactor help command outputs

This commit is contained in:
wlinator 2024-08-05 05:53:34 -04:00
parent 94d7320e25
commit b511b6900f
5 changed files with 54 additions and 127 deletions

View file

@ -187,5 +187,6 @@
"xp_lb_field_value": "level: **{0}**\nxp: `{1}/{2}`",
"xp_level": "Level {0}",
"xp_progress": "Progress to next level",
"xp_server_rank": "Server Rank: #{0}"
"xp_server_rank": "Server Rank: #{0}",
"error_command_not_found": "No command called \"{0}\" found."
}

View file

@ -21,14 +21,18 @@ class EmbedBuilder:
image_url=None,
thumbnail_url=None,
timestamp=None,
hide_author=False,
hide_author_icon=False,
):
if not author_text:
author_text = ctx.author.name
elif show_name:
description = f"**{ctx.author.name}** {description}"
if not hide_author:
if not author_text:
author_text = ctx.author.name
elif show_name:
description = f"**{ctx.author.name}** {description}"
if not hide_author_icon and not author_icon_url:
author_icon_url = ctx.author.display_avatar.url
if not author_icon_url:
author_icon_url = ctx.author.display_avatar.url
if not footer_text:
footer_text = "Luminara"
if not footer_icon_url:
@ -39,7 +43,12 @@ class EmbedBuilder:
description=description,
color=color or CONST.COLOR_DEFAULT,
)
embed.set_author(name=author_text, icon_url=author_icon_url, url=author_url)
if not hide_author:
embed.set_author(
name=author_text,
icon_url=None if hide_author_icon else author_icon_url,
url=author_url,
)
embed.set_footer(text=footer_text, icon_url=footer_icon_url)
embed.timestamp = timestamp or datetime.datetime.now()
@ -63,6 +72,8 @@ class EmbedBuilder:
image_url=None,
thumbnail_url=None,
timestamp=None,
hide_author=False,
hide_author_icon=False,
):
return EmbedBuilder.create_embed(
ctx,
@ -78,6 +89,8 @@ class EmbedBuilder:
image_url=image_url,
thumbnail_url=thumbnail_url,
timestamp=timestamp,
hide_author=hide_author,
hide_author_icon=hide_author_icon,
)
@staticmethod
@ -93,6 +106,8 @@ class EmbedBuilder:
image_url=None,
thumbnail_url=None,
timestamp=None,
hide_author=False,
hide_author_icon=False,
):
return EmbedBuilder.create_embed(
ctx,
@ -108,6 +123,8 @@ class EmbedBuilder:
image_url=image_url,
thumbnail_url=thumbnail_url,
timestamp=timestamp,
hide_author=hide_author,
hide_author_icon=hide_author_icon,
)
@staticmethod
@ -123,6 +140,8 @@ class EmbedBuilder:
image_url=None,
thumbnail_url=None,
timestamp=None,
hide_author=False,
hide_author_icon=False,
):
return EmbedBuilder.create_embed(
ctx,
@ -138,6 +157,8 @@ class EmbedBuilder:
image_url=image_url,
thumbnail_url=thumbnail_url,
timestamp=timestamp,
hide_author=hide_author,
hide_author_icon=hide_author_icon,
)
@staticmethod
@ -153,6 +174,8 @@ class EmbedBuilder:
image_url=None,
thumbnail_url=None,
timestamp=None,
hide_author=False,
hide_author_icon=False,
):
return EmbedBuilder.create_embed(
ctx,
@ -168,4 +191,6 @@ class EmbedBuilder:
image_url=image_url,
thumbnail_url=thumbnail_url,
timestamp=timestamp,
hide_author=hide_author,
hide_author_icon=hide_author_icon,
)

View file

@ -1,6 +1,5 @@
import discord
from lib import formatter
from lib.constants import CONST
@ -11,64 +10,6 @@ def clean_error_embed(ctx):
)
class GenericErrors:
@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 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,
)
return embed
@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,
)
return embed
@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(
text="This message will delete itself after 5s",
icon_url=CONST.EXCLAIM_ICON,
)
return embed
class EconErrors:
@staticmethod
def out_of_time(ctx):
@ -98,35 +39,3 @@ class EconErrors:
)
return embed
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,
)
return embed
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(
text=f"See '{formatter.get_prefix(ctx)}help'",
icon_url=CONST.EXCLAIM_ICON,
)
return embed

View file

@ -8,7 +8,7 @@ from loguru import logger
from config.parser import JsonCache
from lib import interaction
from lib.embeds.error import EconErrors, GenericErrors
from lib.embeds.error import EconErrors
from services.currency_service import Currency
from services.stats_service import BlackJackStats
@ -187,7 +187,7 @@ async def cmd(ctx, bet: int):
stats.push()
except Exception as e:
await ctx.respond(embed=GenericErrors.default_exception(ctx))
# await ctx.respond(embed=GenericErrors.default_exception(ctx))
logger.error("Something went wrong in the blackjack command: ", e)
finally:

View file

@ -1,10 +1,9 @@
import discord
from discord.ext import commands
from config.parser import JsonCache
from lib.embeds.error import HelpErrors
art = JsonCache.read_json("art")
from lib.embed_builder import EmbedBuilder
from lib.constants import CONST
from lib.exceptions.LumiExceptions import LumiException
class LumiHelp(commands.HelpCommand):
@ -22,10 +21,11 @@ class LumiHelp(commands.HelpCommand):
return "`{}{}`".format(self.context.clean_prefix, command.qualified_name)
async def send_bot_help(self, mapping):
embed = discord.Embed(color=discord.Color.blurple())
embed.set_author(name="Help Command", icon_url=art["logo"]["transparent"])
embed.description = "Full list of commands: https://wiki.wlinator.org/cmdlist"
embed = EmbedBuilder.create_info_embed(
ctx=self.context,
author_text="Help Command",
show_name=False,
)
for cog, lumi_commands in mapping.items():
filtered = await self.filter_commands(lumi_commands, sort=True)
@ -46,10 +46,11 @@ class LumiHelp(commands.HelpCommand):
await channel.send(embed=embed)
async def send_command_help(self, command):
embed = discord.Embed(
title=f"{self.context.clean_prefix}{command.qualified_name}",
color=discord.Color.blurple(),
embed = EmbedBuilder.create_success_embed(
ctx=self.context,
author_text=f"{self.context.clean_prefix}{command.qualified_name}",
description=command.help,
show_name=False,
)
usage_value = "`{}{} {}`".format(
@ -69,25 +70,16 @@ class LumiHelp(commands.HelpCommand):
await channel.send(embed=embed)
async def send_error_message(self, error):
channel = self.get_destination()
await channel.send(embed=HelpErrors.error_message(self.context, error))
raise LumiException(error)
async def send_group_help(self, group):
channel = self.get_destination()
await channel.send(
embed=HelpErrors.error_message(
self.context,
f'No command called "{group.qualified_name}" found.',
),
raise LumiException(
CONST.STRINGS["error_command_not_found"].format(group.qualified_name),
)
async def send_cog_help(self, cog):
channel = self.get_destination()
await channel.send(
embed=HelpErrors.error_message(
self.context,
f'No command called "{cog.qualified_name}" found.',
),
raise LumiException(
CONST.STRINGS["error_command_not_found"].format(cog.qualified_name),
)
async def command_callback(self, ctx, *, command=None):
@ -103,7 +95,7 @@ class LumiHelp(commands.HelpCommand):
if cog is not None:
return await self.send_cog_help(cog)
maybe_coro = discord.utils.maybe_coroutine
maybe_coro = discord.utils.maybe_coroutine # type: ignore
# If it's not a cog then it's a command.
# Since we want to have detailed errors when someone