1
0
mirror of https://github.com/craigerl/aprsd.git synced 2024-12-24 02:36: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
def filter(self, packet):
if self.enabled:
result = None
message = packet.get("message_text", None)
@ -221,11 +220,12 @@ class APRSDRegexCommandPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
):
if re.search(self.command_regex, message):
self.rx_inc()
if self.enabled:
result = self.process(packet)
if result:
self.tx_inc()
else:
LOG.warning(f"{self.__class__} is not enabled.")
LOG.warning(f"{self.__class__} isn't enabled.")
return result

View File

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