diff --git a/aprsd/plugins/fortune.py b/aprsd/plugins/fortune.py index d0f44ca..fb5a2dd 100644 --- a/aprsd/plugins/fortune.py +++ b/aprsd/plugins/fortune.py @@ -5,32 +5,38 @@ import subprocess from aprsd import packets, plugin from aprsd.utils import trace +LOG = logging.getLogger('APRSD') -LOG = logging.getLogger("APRSD") - -DEFAULT_FORTUNE_PATH = "/usr/games/fortune" +FORTUNE_PATHS = [ + '/usr/games/fortune', + '/usr/local/bin/fortune', + '/usr/bin/fortune', +] class FortunePlugin(plugin.APRSDRegexCommandPluginBase): """Fortune.""" - command_regex = r"^([f]|[f]\s|fortune)" - command_name = "fortune" - short_description = "Give me a fortune" + command_regex = r'^([f]|[f]\s|fortune)' + command_name = 'fortune' + short_description = 'Give me a fortune' fortune_path = None def setup(self): - self.fortune_path = shutil.which(DEFAULT_FORTUNE_PATH) - LOG.info(f"Fortune path {self.fortune_path}") + for path in FORTUNE_PATHS: + if shutil.which(path): + self.fortune_path = path + break if not self.fortune_path: self.enabled = False else: self.enabled = True + LOG.info(f'Fortune path {self.fortune_path}') @trace.trace def process(self, packet: packets.MessagePacket): - LOG.info("FortunePlugin") + LOG.info('FortunePlugin') # fromcall = packet.get("from") # message = packet.get("message_text", None) @@ -39,8 +45,8 @@ class FortunePlugin(plugin.APRSDRegexCommandPluginBase): reply = None try: - cmnd = [self.fortune_path, "-s", "-n 60"] - command = " ".join(cmnd) + cmnd = [self.fortune_path, '-s', '-n 60'] + command = ' '.join(cmnd) output = subprocess.check_output( command, shell=True, @@ -48,10 +54,10 @@ class FortunePlugin(plugin.APRSDRegexCommandPluginBase): text=True, ) output = ( - output.replace("\r", "") - .replace("\n", "") - .replace(" ", "") - .replace("\t", " ") + output.replace('\r', '') + .replace('\n', '') + .replace(' ', '') + .replace('\t', ' ') ) except subprocess.CalledProcessError as ex: reply = f"Fortune command failed '{ex.output}'"