2021-01-09 09:58:56 -05:00
|
|
|
import logging
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
from aprsd import plugin
|
|
|
|
|
|
|
|
LOG = logging.getLogger("APRSD")
|
|
|
|
|
|
|
|
|
|
|
|
class FortunePlugin(plugin.APRSDPluginBase):
|
|
|
|
"""Fortune."""
|
|
|
|
|
|
|
|
version = "1.0"
|
|
|
|
command_regex = "^[fF]"
|
|
|
|
command_name = "fortune"
|
|
|
|
|
|
|
|
def command(self, fromcall, message, ack):
|
|
|
|
LOG.info("FortunePlugin")
|
|
|
|
reply = None
|
|
|
|
|
|
|
|
fortune_path = shutil.which("fortune")
|
|
|
|
if not fortune_path:
|
|
|
|
reply = "Fortune command not installed"
|
|
|
|
return reply
|
|
|
|
|
|
|
|
try:
|
2021-01-11 14:13:20 -05:00
|
|
|
cmnd = [fortune_path, "-s", "-n 60"]
|
|
|
|
command = " ".join(cmnd)
|
|
|
|
output = subprocess.check_output(
|
|
|
|
command,
|
|
|
|
shell=True,
|
|
|
|
timeout=3,
|
|
|
|
universal_newlines=True,
|
2021-01-09 09:58:56 -05:00
|
|
|
)
|
2021-01-11 14:13:20 -05:00
|
|
|
except subprocess.CalledProcessError as ex:
|
|
|
|
reply = "Fortune command failed '{}'".format(ex.output)
|
|
|
|
else:
|
|
|
|
reply = output
|
2021-01-09 09:58:56 -05:00
|
|
|
|
|
|
|
return reply
|