Skip to content

Commit

Permalink
Merge branch 'main' into fortune
Browse files Browse the repository at this point in the history
  • Loading branch information
wizzdom authored Oct 29, 2024
2 parents a329e04 + e96d95c commit 0d736ac
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ hikari-arc==1.1.0
ruff==0.2.0
pre-commit==3.6.0
python-dotenv==1.0.1
pyfiglet==1.0.2
fortune-python==1.1.1
75 changes: 75 additions & 0 deletions src/extensions/figlet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import arc
import hikari

from pyfiglet import Figlet

plugin = arc.GatewayPlugin(name="figlet")

fonts = [
"standard",
"slant",
"stanpatello",
"usaflag",
"cybermedium",
"wideterm",
"lean",
"3-d",
"larry3d",
"letters",
"poison",
"doh",
"epic",
"fraktur",
"graffiti",
"katakana",
]


@plugin.include
@arc.slash_command("figlet", "ASCIIify your words!")
async def figlet_command(
ctx: arc.GatewayContext,
text: arc.Option[str, arc.StrParams("Your words to ASCIIify.")],
font: arc.Option[
str,
arc.StrParams(
"The style of your ASCII text",
choices=[
hikari.CommandChoice(name=font.capitalize(), value=font)
for font in fonts
],
),
] = "standard",
) -> None:
"""ASCIIify words"""

# create Figlet object with the selected font
figlet = Figlet(font=font)

# generate ASCII art
ascii_art = figlet.renderText(text)
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,
)
return

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


@arc.loader
def loader(client: arc.GatewayClient) -> None:
client.add_plugin(plugin)

0 comments on commit 0d736ac

Please sign in to comment.