From 3d0bb8ae8e92c7a23352f06aa951c6b18a0c2da0 Mon Sep 17 00:00:00 2001 From: Hemna Date: Thu, 29 Dec 2022 14:18:38 -0500 Subject: [PATCH] Update regex processing and regex for plugins The regex search is now by default case insensitive. Also update each core plugin to better match the command. ping plugin can now match on p p foo ping pIng Weather plugins can now match on w wx wX Wx KM6LYW weather WeaTher --- aprsd/cmds/server.py | 1 - aprsd/flask.py | 2 +- aprsd/plugin.py | 3 +-- aprsd/plugins/email.py | 17 ++++++++++++++++- aprsd/plugins/fortune.py | 2 +- aprsd/plugins/location.py | 2 +- aprsd/plugins/ping.py | 2 +- aprsd/plugins/time.py | 5 +++-- aprsd/plugins/version.py | 2 +- aprsd/plugins/weather.py | 8 ++++---- 10 files changed, 29 insertions(+), 15 deletions(-) diff --git a/aprsd/cmds/server.py b/aprsd/cmds/server.py index 24be960..07c20e2 100644 --- a/aprsd/cmds/server.py +++ b/aprsd/cmds/server.py @@ -86,7 +86,6 @@ def server(ctx, flush): packets.WatchList().load() packets.SeenList().load() - rx_thread = rx.APRSDPluginRXThread( packet_queue=threads.packet_queue, ) diff --git a/aprsd/flask.py b/aprsd/flask.py index 58a2575..cbe955f 100644 --- a/aprsd/flask.py +++ b/aprsd/flask.py @@ -462,7 +462,7 @@ def init_flask(loglevel, quiet): socketio = SocketIO( flask_app, logger=False, engineio_logger=False, - async_mode="threading", + # async_mode="threading", ) # import eventlet # eventlet.monkey_patch() diff --git a/aprsd/plugin.py b/aprsd/plugin.py index 6181626..fd342cc 100644 --- a/aprsd/plugin.py +++ b/aprsd/plugin.py @@ -228,7 +228,7 @@ class APRSDRegexCommandPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta): and isinstance(packet, packets.core.MessagePacket) and message ): - if re.search(self.command_regex, message): + if re.search(self.command_regex, message, re.IGNORECASE): self.rx_inc() try: result = self.process(packet) @@ -262,7 +262,6 @@ class HelpPlugin(APRSDRegexCommandPluginBase): This plugin is in this file to prevent a circular import. """ - version = "1.0" command_regex = "^[hH]" command_name = "help" diff --git a/aprsd/plugins/email.py b/aprsd/plugins/email.py index 876cdbd..740ede9 100644 --- a/aprsd/plugins/email.py +++ b/aprsd/plugins/email.py @@ -76,9 +76,24 @@ class EmailPlugin(plugin.APRSDRegexCommandPluginBase): """Ensure that email is enabled and start the thread.""" if CONF.email_plugin.enabled: self.enabled = True + + if not CONF.email_plugin.callsign: + self.enabled = False + LOG.error("email_plugin.callsign is not set.") + return + + if not CONF.email_plugin.imap_login: + LOG.error("email_plugin.imap_login not set. Disabling Plugin") + self.enabled = False + return + + if not CONF.email_plugin.smtp_login: + LOG.error("email_plugin.smtp_login not set. Disabling Plugin") + self.enabled = False + return + shortcuts = _build_shortcuts_dict() LOG.info(f"Email shortcuts {shortcuts}") - else: LOG.info("Email services not enabled.") self.enabled = False diff --git a/aprsd/plugins/fortune.py b/aprsd/plugins/fortune.py index afb4247..bd952b8 100644 --- a/aprsd/plugins/fortune.py +++ b/aprsd/plugins/fortune.py @@ -12,7 +12,7 @@ LOG = logging.getLogger("APRSD") class FortunePlugin(plugin.APRSDRegexCommandPluginBase): """Fortune.""" - command_regex = "^[fF]" + command_regex = r"^([f]|[f]\s|fortune)" command_name = "fortune" short_description = "Give me a fortune" diff --git a/aprsd/plugins/location.py b/aprsd/plugins/location.py index 05b7f11..16ab55e 100644 --- a/aprsd/plugins/location.py +++ b/aprsd/plugins/location.py @@ -15,7 +15,7 @@ LOG = logging.getLogger("APRSD") class LocationPlugin(plugin.APRSDRegexCommandPluginBase, plugin.APRSFIKEYMixin): """Location!""" - command_regex = "^[lL]" + command_regex = r"^([l]|[l]\s|location)" command_name = "location" short_description = "Where in the world is a CALLSIGN's last GPS beacon?" diff --git a/aprsd/plugins/ping.py b/aprsd/plugins/ping.py index 6304a45..ac0b015 100644 --- a/aprsd/plugins/ping.py +++ b/aprsd/plugins/ping.py @@ -11,7 +11,7 @@ LOG = logging.getLogger("APRSD") class PingPlugin(plugin.APRSDRegexCommandPluginBase): """Ping.""" - command_regex = "^[pP]" + command_regex = r"^([p]|[p]\s|ping)" command_name = "ping" short_description = "reply with a Pong!" diff --git a/aprsd/plugins/time.py b/aprsd/plugins/time.py index f6261b9..4509022 100644 --- a/aprsd/plugins/time.py +++ b/aprsd/plugins/time.py @@ -16,7 +16,8 @@ LOG = logging.getLogger("APRSD") class TimePlugin(plugin.APRSDRegexCommandPluginBase): """Time command.""" - command_regex = "^[tT]" + # Look for t or t or T or time + command_regex = r"^([t]|[t]\s|time)" command_name = "time" short_description = "What is the current local time." @@ -54,7 +55,7 @@ class TimePlugin(plugin.APRSDRegexCommandPluginBase): class TimeOWMPlugin(TimePlugin, plugin.APRSFIKEYMixin): """OpenWeatherMap based timezone fetching.""" - command_regex = "^[tT]" + command_regex = r"^([t]|[t]\s|time)" command_name = "time" short_description = "Current time of GPS beacon's timezone. Uses OpenWeatherMap" diff --git a/aprsd/plugins/version.py b/aprsd/plugins/version.py index e9351d9..2b4b552 100644 --- a/aprsd/plugins/version.py +++ b/aprsd/plugins/version.py @@ -10,7 +10,7 @@ LOG = logging.getLogger("APRSD") class VersionPlugin(plugin.APRSDRegexCommandPluginBase): """Version of APRSD Plugin.""" - command_regex = "^[vV]" + command_regex = r"^([v]|[v]\s|version)" command_name = "version" short_description = "What is the APRSD Version" diff --git a/aprsd/plugins/weather.py b/aprsd/plugins/weather.py index 16a4330..f8f8cef 100644 --- a/aprsd/plugins/weather.py +++ b/aprsd/plugins/weather.py @@ -26,7 +26,7 @@ class USWeatherPlugin(plugin.APRSDRegexCommandPluginBase, plugin.APRSFIKEYMixin) "weather" - returns weather near the calling callsign """ - command_regex = "^[wW]" + command_regex = r"^([w]|[w]\s|[w][x]|[w][x]\s|weather)" command_name = "USWeather" short_description = "Provide USA only weather of GPS Beacon location" @@ -92,7 +92,7 @@ class USMetarPlugin(plugin.APRSDRegexCommandPluginBase, plugin.APRSFIKEYMixin): """ - command_regex = "^[metar]" + command_regex = r"^([m]|[m]|[m]\s|metar)" command_name = "USMetar" short_description = "USA only METAR of GPS Beacon location" @@ -182,7 +182,7 @@ class OWMWeatherPlugin(plugin.APRSDRegexCommandPluginBase): """ - command_regex = "^[wW]" + command_regex = r"^([w]|[w]\s|[w][x]|[w][x]\s|weather)" command_name = "OpenWeatherMap" short_description = "OpenWeatherMap weather of GPS Beacon location" @@ -301,7 +301,7 @@ class AVWXWeatherPlugin(plugin.APRSDRegexCommandPluginBase): docker build -f Dockerfile -t avwx-api:master . """ - command_regex = "^[mM]" + command_regex = r"^([m]|[m]|[m]\s|metar)" command_name = "AVWXWeather" short_description = "AVWX weather of GPS Beacon location"