poezio/plugins/figlet.py

49 lines
1.2 KiB
Python
Raw Permalink Normal View History

"""
This plugin uses figlet to transform every message into a big ascii-art
message.
Usage
-----
Say something in a Chat tab.
.. note:: Can create fun things when used with :ref:`The rainbow plugin <rainbow-plugin>`.
"""
2011-11-06 22:46:35 +00:00
import subprocess
from poezio.plugin import BasePlugin
def is_figlet() -> bool:
"""Ensure figlet exists"""
process = subprocess.Popen(
['which', 'figlet'],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
return process.wait() == 0
2011-11-06 22:46:35 +00:00
2018-08-15 11:13:17 +00:00
2011-11-06 22:46:35 +00:00
class Plugin(BasePlugin):
def init(self):
if not is_figlet():
self.api.information(
'Couldn\'t find the figlet program. '
'Please install it and reload the plugin.',
'Error',
)
return None
self.api.add_event_handler('muc_say', self.figletize)
self.api.add_event_handler('conversation_say', self.figletize)
self.api.add_event_handler('private_say', self.figletize)
return None
2011-11-06 22:46:35 +00:00
2011-11-09 13:29:13 +00:00
def figletize(self, msg, tab):
2018-08-15 11:13:17 +00:00
process = subprocess.Popen(
['figlet', '--', msg['body']], stdout=subprocess.PIPE)
2011-11-06 22:46:35 +00:00
result = process.communicate()[0].decode('utf-8')
msg['body'] = result