mirror of
https://github.com/craigerl/aprsd.git
synced 2024-12-20 00:26:04 -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:
parent
3faf41b203
commit
1b9a9935fc
@ -205,27 +205,27 @@ class APRSDRegexCommandPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
|
||||
|
||||
@hookimpl
|
||||
def filter(self, packet):
|
||||
if self.enabled:
|
||||
result = None
|
||||
result = None
|
||||
|
||||
message = packet.get("message_text", None)
|
||||
msg_format = packet.get("format", None)
|
||||
tocall = packet.get("addresse", None)
|
||||
message = packet.get("message_text", None)
|
||||
msg_format = packet.get("format", None)
|
||||
tocall = packet.get("addresse", None)
|
||||
|
||||
# Only process messages destined for us
|
||||
# and is an APRS message format and has a message.
|
||||
if (
|
||||
tocall == self.config["aprs"]["login"]
|
||||
and msg_format == "message"
|
||||
and message
|
||||
):
|
||||
if re.search(self.command_regex, message):
|
||||
self.rx_inc()
|
||||
# Only process messages destined for us
|
||||
# and is an APRS message format and has a message.
|
||||
if (
|
||||
tocall == self.config["aprs"]["login"]
|
||||
and msg_format == "message"
|
||||
and message
|
||||
):
|
||||
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.")
|
||||
else:
|
||||
LOG.warning(f"{self.__class__} isn't enabled.")
|
||||
|
||||
return result
|
||||
|
||||
|
@ -253,15 +253,21 @@ class APRSDProcessPacketThread(APRSDThread):
|
||||
replied = True
|
||||
for subreply in reply:
|
||||
LOG.debug(f"Sending '{subreply}'")
|
||||
|
||||
msg = messaging.TextMessage(
|
||||
self.config["aprs"]["login"],
|
||||
fromcall,
|
||||
subreply,
|
||||
transport=self.transport,
|
||||
)
|
||||
msg.send()
|
||||
|
||||
if isinstance(subreply, messaging.Message):
|
||||
subreply.send()
|
||||
else:
|
||||
msg = messaging.TextMessage(
|
||||
self.config["aprs"]["login"],
|
||||
fromcall,
|
||||
subreply,
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user