maubot_figlet/figlet.py
Vincent Batts 9956f298f3
figlet: maybe that newline is needed
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2023-11-06 21:18:46 -05:00

26 lines
882 B
Python

import random
import pyfiglet
from maubot import Plugin, MessageEvent
from maubot.handlers import command
class FigletBot(Plugin):
@command.new("figlet", help="display text in large ascii fonts")
@command.argument("message", pass_raw=True)
async def figlet_handler(self, evt: MessageEvent, message: str) -> None:
message = message.strip()
fonts = pyfiglet.FigletFont.getFonts()
if message.lower() == 'star wars' and 'starwars' in fonts:
fontname = 'starwars'
elif message.lower() == 'star trek' and 'trek' in fonts:
fontname = 'trek'
else:
fontname = fonts[random.randint(0, len(fonts) - 1)]
fig = pyfiglet.Figlet(font=fontname)
msg = f'Rendering with: {fontname}\n\n```'
msg += fig.renderText(message).strip()
msg += '\n```'
await evt.respond(msg)