2021-01-09 09:58:56 -05:00
|
|
|
import logging
|
|
|
|
import re
|
|
|
|
|
|
|
|
from aprsd import messaging, plugin
|
|
|
|
|
|
|
|
LOG = logging.getLogger("APRSD")
|
|
|
|
|
|
|
|
|
|
|
|
class QueryPlugin(plugin.APRSDPluginBase):
|
|
|
|
"""Query command."""
|
|
|
|
|
|
|
|
version = "1.0"
|
|
|
|
command_regex = r"^\?.*"
|
|
|
|
command_name = "query"
|
|
|
|
|
|
|
|
def command(self, fromcall, message, ack):
|
|
|
|
LOG.info("Query COMMAND")
|
|
|
|
|
|
|
|
tracker = messaging.MsgTrack()
|
|
|
|
reply = "Pending Messages ({})".format(len(tracker))
|
|
|
|
|
|
|
|
searchstring = "^" + self.config["ham"]["callsign"] + ".*"
|
|
|
|
# only I can do admin commands
|
|
|
|
if re.search(searchstring, fromcall):
|
2021-01-11 12:13:37 -05:00
|
|
|
|
|
|
|
# resend last N most recent
|
|
|
|
r = re.search(r"^\?[rR]([0-9]).*", message)
|
|
|
|
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:
|
|
|
|
reply = "No delayed msgs to resend"
|
|
|
|
LOG.debug(reply)
|
|
|
|
return reply
|
|
|
|
|
|
|
|
# resend all
|
2021-01-09 18:50:04 -05:00
|
|
|
r = re.search(r"^\?[rR].*", 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-11 12:13:37 -05:00
|
|
|
reply = "No delayed msgs"
|
2021-01-09 09:58:56 -05:00
|
|
|
LOG.debug(reply)
|
|
|
|
return reply
|
|
|
|
|
2021-01-10 17:44:40 -05:00
|
|
|
r = re.search(r"^\?[dD].*", message)
|
2021-01-09 09:58:56 -05:00
|
|
|
if r is not None:
|
2021-01-10 17:44:40 -05:00
|
|
|
reply = "Deleted ALL delayed msgs."
|
2021-01-09 09:58:56 -05:00
|
|
|
LOG.debug(reply)
|
|
|
|
tracker.flush()
|
|
|
|
return reply
|
|
|
|
|
|
|
|
return reply
|