53 lines
2.0 KiB
Python
53 lines
2.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
from irc3.plugins.command import command
|
|
import irc3
|
|
import pyfiglet
|
|
import random
|
|
fig = pyfiglet.Figlet(width=100)
|
|
@irc3.plugin
|
|
class Plugin:
|
|
def __init__(self, bot):
|
|
self.bot = bot
|
|
self.fig_fonts = set(self.bot.db.getlist("fig_font_list", []))
|
|
if not self.fig_fonts:
|
|
self.fig_fonts = fig.getFonts()
|
|
self.bot.db.setlist("fig_font_list", self.fig_fonts)
|
|
@irc3.extend
|
|
def fig(self, text, font=None):
|
|
if font in self.fig_fonts:
|
|
fig.setFont(font=font)
|
|
else:
|
|
font = random.choice(list(self.fig_fonts))
|
|
return fig.renderText(text)
|
|
@command(permission='view', name="fig", public=True, show_in_help_list=True)
|
|
def figcmd(self, mask, target, args):
|
|
"""Print figlet Text
|
|
%%fig <cmdmsg>...
|
|
"""
|
|
cmdmsg = ' '.join(args['<cmdmsg>'])
|
|
cmd = ' '.join(cmdmsg.split()[:1])
|
|
msg = ' '.join(cmdmsg.split()[1:])
|
|
font = cmd
|
|
text = msg
|
|
if font == "list":
|
|
font_list = self.bot.db.getlist("fig_font_list")
|
|
self.bot.privmsg(target, "Current Fig Fonts {}".format(",".join(font_list)))
|
|
return
|
|
if font == "ignore":
|
|
ignored_font = args.get("<text>")
|
|
self.fig_fonts.remove(ignored_font)
|
|
self.bot.db.setlist("fig_font_list", self.fig_fonts)
|
|
self.bot.privmsg(target, "Ignoring {}".format(ignored_font))
|
|
return
|
|
if text is not None and font in self.fig_fonts:
|
|
msg = self.bot.emo(font)
|
|
self.bot.privmsg(target, msg)
|
|
fig_text = self.fig(text=text, font=font)
|
|
else:
|
|
newfont = random.choice(list(self.fig_fonts))
|
|
msg = self.bot.emo(newfont)
|
|
self.bot.privmsg(target, msg)
|
|
fig_text = self.fig(text=font, font=newfont) # Cause weird command format
|
|
for line in fig_text.split("\n"):
|
|
self.bot.privmsg(target, line)
|