Skip to content

Commit

Permalink
remove error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
wizzdom committed Oct 29, 2024
1 parent a9a113d commit a233191
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions src/extensions/figlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,26 @@ async def figlet_command(

# generate ASCII art
ascii_art = figlet.renderText(text)
assert len(ascii_art) > 0
if not ascii_art:
await ctx.respond(
"❌ Failed to generate ASCII art. Please try again.",
flags=hikari.MessageFlag.EPHEMERAL,
)
return

# wrap ASCII art in a codeblock
message = f"```{ascii_art}```"

# do not exceed Discord's 2000 character limit
if len(message) > 2000:
await ctx.respond(
"The generated ASCII art is too long to send. Please try a shorter text.",
flags=hikari.MessageFlag.EPHEMERAL,
)

else:
# send ASCII art in a codeblock
await ctx.respond(message)


@plugin.set_error_handler
async def figlet_error_handler(ctx: arc.GatewayContext, exc: Exception) -> None:
text = ctx.get_option("text", arc.OptionType.STRING)
assert text is not None

if isinstance(exc, AssertionError):
await ctx.respond(
f"❌ Failed to generate ASCII art for: {text}",
"❌ The generated ASCII art is too long to send. Please try a shorter text.",
flags=hikari.MessageFlag.EPHEMERAL,
)
return

raise exc
# send ASCII art in a codeblock
await ctx.respond(message)


@arc.loader
Expand Down

0 comments on commit a233191

Please sign in to comment.