From 91eabbd17d6ef85c92ac3d9711cf9fc92b22d5be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Fri, 7 Jun 2019 16:09:06 +0200 Subject: plugins/figlet: error out when figlet doesn't exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- plugins/figlet.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/plugins/figlet.py b/plugins/figlet.py index b8fcb813..4d4c7577 100644 --- a/plugins/figlet.py +++ b/plugins/figlet.py @@ -11,15 +11,35 @@ Say something in a Chat tab. .. note:: Can create fun things when used with :ref:`The 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( -- cgit v1.2.3