maubot_figlet/figlet.py

27 lines
872 B
Python
Raw Normal View History

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)
msg += '```'
await evt.respond(msg)