2023-11-07 01:44:52 +00:00
|
|
|
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)
|
2023-11-07 02:03:49 +00:00
|
|
|
msg += '```'
|
2023-11-07 01:44:52 +00:00
|
|
|
await evt.respond(msg)
|