plugins/figlet: error out when figlet doesn't exist

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2019-06-07 16:09:06 +02:00
parent b7fc562c88
commit 91eabbd17d
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -11,15 +11,35 @@ Say something in a Chat tab.
.. note:: Can create fun things when used with :ref:`The rainbow plugin <rainbow-plugin>`.
"""
from poezio.plugin import BasePlugin
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
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
def figletize(self, msg, tab):
process = subprocess.Popen(