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:
parent
3faf41b203
commit
1b9a9935fc
@ -205,27 +205,27 @@ 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)
|
||||||
msg_format = packet.get("format", None)
|
msg_format = packet.get("format", None)
|
||||||
tocall = packet.get("addresse", None)
|
tocall = packet.get("addresse", None)
|
||||||
|
|
||||||
# Only process messages destined for us
|
# Only process messages destined for us
|
||||||
# and is an APRS message format and has a message.
|
# and is an APRS message format and has a message.
|
||||||
if (
|
if (
|
||||||
tocall == self.config["aprs"]["login"]
|
tocall == self.config["aprs"]["login"]
|
||||||
and msg_format == "message"
|
and msg_format == "message"
|
||||||
and message
|
and message
|
||||||
):
|
):
|
||||||
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
|
||||||
|
|
||||||
|
@ -253,15 +253,21 @@ 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):
|
||||||
msg = messaging.TextMessage(
|
subreply.send()
|
||||||
self.config["aprs"]["login"],
|
else:
|
||||||
fromcall,
|
msg = messaging.TextMessage(
|
||||||
subreply,
|
self.config["aprs"]["login"],
|
||||||
transport=self.transport,
|
fromcall,
|
||||||
)
|
subreply,
|
||||||
msg.send()
|
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:
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user