2021-01-15 11:12:43 -05:00
|
|
|
import datetime
|
2021-01-09 09:58:56 -05:00
|
|
|
import logging
|
|
|
|
import re
|
|
|
|
|
2021-01-29 10:07:49 -05:00
|
|
|
from aprsd import messaging, plugin, trace
|
2021-01-09 09:58:56 -05:00
|
|
|
|
2021-08-23 12:14:19 -04:00
|
|
|
|
2021-01-09 09:58:56 -05:00
|
|
|
LOG = logging.getLogger("APRSD")
|
|
|
|
|
|
|
|
|
2021-07-14 20:50:41 -04:00
|
|
|
class QueryPlugin(plugin.APRSDMessagePluginBase):
|
2021-01-09 09:58:56 -05:00
|
|
|
"""Query command."""
|
|
|
|
|
|
|
|
version = "1.0"
|
2021-01-17 10:55:59 -05:00
|
|
|
command_regex = r"^\!.*"
|
2021-01-09 09:58:56 -05:00
|
|
|
command_name = "query"
|
|
|
|
|
2021-01-29 10:07:49 -05:00
|
|
|
@trace.trace
|
2021-07-14 20:50:41 -04:00
|
|
|
def command(self, packet):
|
2021-01-09 09:58:56 -05:00
|
|
|
LOG.info("Query COMMAND")
|
|
|
|
|
2021-07-14 20:50:41 -04:00
|
|
|
fromcall = packet.get("from")
|
|
|
|
message = packet.get("message_text", None)
|
|
|
|
# ack = packet.get("msgNo", "0")
|
|
|
|
|
2021-01-09 09:58:56 -05:00
|
|
|
tracker = messaging.MsgTrack()
|
2021-01-15 11:12:43 -05:00
|
|
|
now = datetime.datetime.now()
|
|
|
|
reply = "Pending messages ({}) {}".format(
|
|
|
|
len(tracker),
|
|
|
|
now.strftime("%H:%M:%S"),
|
|
|
|
)
|
2021-01-09 09:58:56 -05:00
|
|
|
|
|
|
|
searchstring = "^" + self.config["ham"]["callsign"] + ".*"
|
|
|
|
# only I can do admin commands
|
|
|
|
if re.search(searchstring, fromcall):
|
2021-01-11 12:13:37 -05:00
|
|
|
|
2021-01-17 10:55:59 -05:00
|
|
|
# resend last N most recent: "!3"
|
|
|
|
r = re.search(r"^\!([0-9]).*", message)
|
2021-01-11 12:13:37 -05:00
|
|
|
if r is not None:
|
|
|
|
if len(tracker) > 0:
|
|
|
|
last_n = r.group(1)
|
|
|
|
reply = messaging.NULL_MESSAGE
|
|
|
|
LOG.debug(reply)
|
|
|
|
tracker.restart_delayed(count=int(last_n))
|
|
|
|
else:
|
2021-01-14 14:21:26 -05:00
|
|
|
reply = "No pending msgs to resend"
|
2021-01-11 12:13:37 -05:00
|
|
|
LOG.debug(reply)
|
|
|
|
return reply
|
|
|
|
|
2021-01-17 10:55:59 -05:00
|
|
|
# resend all: "!a"
|
|
|
|
r = re.search(r"^\![aA].*", message)
|
2021-01-09 09:58:56 -05:00
|
|
|
if r is not None:
|
|
|
|
if len(tracker) > 0:
|
2021-01-10 17:44:40 -05:00
|
|
|
reply = messaging.NULL_MESSAGE
|
2021-01-09 09:58:56 -05:00
|
|
|
LOG.debug(reply)
|
|
|
|
tracker.restart_delayed()
|
|
|
|
else:
|
2021-01-14 14:21:26 -05:00
|
|
|
reply = "No pending msgs"
|
2021-01-09 09:58:56 -05:00
|
|
|
LOG.debug(reply)
|
|
|
|
return reply
|
|
|
|
|
2021-01-17 10:55:59 -05:00
|
|
|
# delete all: "!d"
|
|
|
|
r = re.search(r"^\![dD].*", message)
|
2021-01-09 09:58:56 -05:00
|
|
|
if r is not None:
|
2021-01-14 14:21:26 -05:00
|
|
|
reply = "Deleted ALL pending msgs."
|
2021-01-09 09:58:56 -05:00
|
|
|
LOG.debug(reply)
|
|
|
|
tracker.flush()
|
|
|
|
return reply
|
|
|
|
|
|
|
|
return reply
|