From 349250685b5cdffa5d44deee7c58b8f3e384e905 Mon Sep 17 00:00:00 2001 From: Hemna Date: Fri, 13 Aug 2021 12:36:48 -0400 Subject: [PATCH] Enable multiple replies for plugins This patch adds the ability for plugins to send multiple messages back in response to a command/message. The plugin simple needs to return a list of messages (Strings). Each string in that list will result in a separate message being sent back to the originator of the message. --- aprsd/threads.py | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/aprsd/threads.py b/aprsd/threads.py index a776d69..e2d21ec 100644 --- a/aprsd/threads.py +++ b/aprsd/threads.py @@ -253,21 +253,35 @@ class APRSDRXThread(APRSDThread): try: results = pm.run(packet) for reply in results: - found_command = True - # A plugin can return a null message flag which signals - # us that they processed the message correctly, but have - # nothing to reply with, so we avoid replying with a usage string - if reply is not messaging.NULL_MESSAGE: - LOG.debug("Sending '{}'".format(reply)) + if isinstance(reply, list): + # one of the plugins wants to send multiple messages + found_command = True + for subreply in reply: + LOG.debug("Sending '{}'".format(subreply)) + + msg = messaging.TextMessage( + self.config["aprs"]["login"], + fromcall, + subreply, + ) + self.msg_queues["tx"].put(msg) - msg = messaging.TextMessage( - self.config["aprs"]["login"], - fromcall, - reply, - ) - self.msg_queues["tx"].put(msg) else: - LOG.debug("Got NULL MESSAGE from plugin") + found_command = True + # A plugin can return a null message flag which signals + # us that they processed the message correctly, but have + # nothing to reply with, so we avoid replying with a usage string + if reply is not messaging.NULL_MESSAGE: + LOG.debug("Sending '{}'".format(reply)) + + msg = messaging.TextMessage( + self.config["aprs"]["login"], + fromcall, + reply, + ) + self.msg_queues["tx"].put(msg) + else: + LOG.debug("Got NULL MESSAGE from plugin") if not found_command: plugins = pm.get_msg_plugins()