1
0
mirror of https://github.com/craigerl/aprsd.git synced 2025-03-08 12:28:55 -05:00

Enable plugins to return message object

This patch enables the ability for plugins to return:
* string
* list of strings
* message object
* list of strings and message ojects

Each string will be encapsulated in a message object prior being sent.
each message object will be sent directly.
Each list will be iterated over and processed according to the above 2
options.
This commit is contained in:
Hemna 2021-09-08 14:45:15 -04:00
parent 3faf41b203
commit 1b9a9935fc
2 changed files with 31 additions and 25 deletions

View File

@ -205,7 +205,6 @@ class APRSDRegexCommandPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
@hookimpl @hookimpl
def filter(self, packet): def filter(self, packet):
if self.enabled:
result = None result = None
message = packet.get("message_text", None) message = packet.get("message_text", None)
@ -221,11 +220,12 @@ class APRSDRegexCommandPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
): ):
if re.search(self.command_regex, message): if re.search(self.command_regex, message):
self.rx_inc() self.rx_inc()
if self.enabled:
result = self.process(packet) result = self.process(packet)
if result: if result:
self.tx_inc() self.tx_inc()
else: else:
LOG.warning(f"{self.__class__} is not enabled.") LOG.warning(f"{self.__class__} isn't enabled.")
return result return result

View File

@ -253,7 +253,9 @@ class APRSDProcessPacketThread(APRSDThread):
replied = True replied = True
for subreply in reply: for subreply in reply:
LOG.debug(f"Sending '{subreply}'") LOG.debug(f"Sending '{subreply}'")
if isinstance(subreply, messaging.Message):
subreply.send()
else:
msg = messaging.TextMessage( msg = messaging.TextMessage(
self.config["aprs"]["login"], self.config["aprs"]["login"],
fromcall, fromcall,
@ -261,7 +263,11 @@ class APRSDProcessPacketThread(APRSDThread):
transport=self.transport, transport=self.transport,
) )
msg.send() msg.send()
elif isinstance(reply, messaging.Message):
# We have a message based object.
LOG.debug(f"Sending '{reply}'")
reply.send()
replied = True
else: else:
replied = True replied = True
# A plugin can return a null message flag which signals # A plugin can return a null message flag which signals