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
This commit is contained in:
Hemna 2022-12-29 14:18:38 -05:00
parent 83d2e708eb
commit 3d0bb8ae8e
10 changed files with 29 additions and 15 deletions

View File

@ -86,7 +86,6 @@ def server(ctx, flush):
packets.WatchList().load()
packets.SeenList().load()
rx_thread = rx.APRSDPluginRXThread(
packet_queue=threads.packet_queue,
)

View File

@ -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()

View File

@ -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"

View File

@ -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

View File

@ -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"

View File

@ -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?"

View File

@ -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!"

View File

@ -16,7 +16,8 @@ LOG = logging.getLogger("APRSD")
class TimePlugin(plugin.APRSDRegexCommandPluginBase):
"""Time command."""
command_regex = "^[tT]"
# Look for t or t<space> or T<space> 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"

View File

@ -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"

View File

@ -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"