Update for aprsd >= 2.7.0
the new aprsd changes the packets to a dataclass object, so access to the attributes is different.
This commit is contained in:
parent
53d45e9e74
commit
b624055d06
|
@ -2,11 +2,12 @@ import logging
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from aprsd import messaging, plugin, plugin_utils
|
from aprsd import packets, plugin, plugin_utils
|
||||||
|
|
||||||
import aprsd_slack_plugin
|
import aprsd_slack_plugin
|
||||||
from aprsd_slack_plugin import base_plugin
|
from aprsd_slack_plugin import base_plugin
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger("APRSD")
|
LOG = logging.getLogger("APRSD")
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,8 +51,8 @@ class SlackLocationPlugin(base_plugin.SlackPluginBase, plugin.APRSDRegexCommandP
|
||||||
def process(self, packet):
|
def process(self, packet):
|
||||||
LOG.info("SlackCommandPlugin")
|
LOG.info("SlackCommandPlugin")
|
||||||
|
|
||||||
fromcall = packet["from"]
|
fromcall = packet.from_call
|
||||||
message = packet["message_text"]
|
message = packet.message_text
|
||||||
|
|
||||||
is_setup = self.setup_slack()
|
is_setup = self.setup_slack()
|
||||||
if not is_setup:
|
if not is_setup:
|
||||||
|
@ -61,7 +62,7 @@ class SlackLocationPlugin(base_plugin.SlackPluginBase, plugin.APRSDRegexCommandP
|
||||||
try:
|
try:
|
||||||
self.config.exists(["services", "aprs.fi", "apiKey"])
|
self.config.exists(["services", "aprs.fi", "apiKey"])
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.error("Failed to find config aprs.fi:apikey {}".format(ex))
|
LOG.error(f"Failed to find config aprs.fi:apikey {ex}")
|
||||||
return "No aprs.fi apikey found"
|
return "No aprs.fi apikey found"
|
||||||
|
|
||||||
api_key = self.config["services"]["aprs.fi"]["apiKey"]
|
api_key = self.config["services"]["aprs.fi"]["apiKey"]
|
||||||
|
@ -78,10 +79,10 @@ class SlackLocationPlugin(base_plugin.SlackPluginBase, plugin.APRSDRegexCommandP
|
||||||
try:
|
try:
|
||||||
aprs_data = plugin_utils.get_aprs_fi(api_key, searchcall)
|
aprs_data = plugin_utils.get_aprs_fi(api_key, searchcall)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.error("Failed to fetch aprs.fi '{}'".format(ex))
|
LOG.error(f"Failed to fetch aprs.fi '{ex}'")
|
||||||
return "Failed to fetch aprs.fi location"
|
return "Failed to fetch aprs.fi location"
|
||||||
|
|
||||||
LOG.debug("LocationPlugin: aprs_data = {}".format(aprs_data))
|
LOG.debug(f"LocationPlugin: aprs_data = {aprs_data}")
|
||||||
if not len(aprs_data["entries"]):
|
if not len(aprs_data["entries"]):
|
||||||
LOG.error("Didn't get any entries from aprs.fi")
|
LOG.error("Didn't get any entries from aprs.fi")
|
||||||
return "Failed to fetch aprs.fi location"
|
return "Failed to fetch aprs.fi location"
|
||||||
|
@ -103,7 +104,7 @@ class SlackLocationPlugin(base_plugin.SlackPluginBase, plugin.APRSDRegexCommandP
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.warning("Couldn't fetch forecast.weather.gov")
|
LOG.warning("Couldn't fetch forecast.weather.gov")
|
||||||
|
|
||||||
callsign_url = "<http://aprs.fi/info/a/{}|{}>".format(searchcall, searchcall)
|
callsign_url = f"<http://aprs.fi/info/a/{searchcall}|{searchcall}>"
|
||||||
|
|
||||||
aprs_url = "<http://aprs.fi/#!mt=roadmap&z=15&lat={}&lng={}|" " http://aprs.fi/>".format(
|
aprs_url = "<http://aprs.fi/#!mt=roadmap&z=15&lat={}&lng={}|" " http://aprs.fi/>".format(
|
||||||
lat,
|
lat,
|
||||||
|
@ -114,7 +115,7 @@ class SlackLocationPlugin(base_plugin.SlackPluginBase, plugin.APRSDRegexCommandP
|
||||||
message["username"] = "APRSD - Slack Location Plugin"
|
message["username"] = "APRSD - Slack Location Plugin"
|
||||||
message["icon_emoji"] = ":satellite_antenna:"
|
message["icon_emoji"] = ":satellite_antenna:"
|
||||||
message["attachments"] = [{}]
|
message["attachments"] = [{}]
|
||||||
message["text"] = "{} - Location".format(callsign_url)
|
message["text"] = f"{callsign_url} - Location"
|
||||||
message["channel"] = "#random"
|
message["channel"] = "#random"
|
||||||
|
|
||||||
attachment = message["attachments"][0]
|
attachment = message["attachments"][0]
|
||||||
|
@ -140,15 +141,15 @@ class SlackLocationPlugin(base_plugin.SlackPluginBase, plugin.APRSDRegexCommandP
|
||||||
"title": "Altitude",
|
"title": "Altitude",
|
||||||
"value": altfeet,
|
"value": altfeet,
|
||||||
"short": True,
|
"short": True,
|
||||||
"fallback": "Altitude - {}".format(altfeet),
|
"fallback": f"Altitude - {altfeet}",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
attachment["fields"].append(
|
attachment["fields"].append(
|
||||||
{
|
{
|
||||||
"title": "Time",
|
"title": "Time",
|
||||||
"value": "{} h ago".format(round(delta_hours, 1)),
|
"value": f"{round(delta_hours, 1)} h ago",
|
||||||
"short": True,
|
"short": True,
|
||||||
"fallback": "Time {} h ago".format(round(delta_hours, 1)),
|
"fallback": f"Time {round(delta_hours, 1)} h ago",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -160,4 +161,4 @@ class SlackLocationPlugin(base_plugin.SlackPluginBase, plugin.APRSDRegexCommandP
|
||||||
self.swc.chat_postMessage(**message)
|
self.swc.chat_postMessage(**message)
|
||||||
|
|
||||||
# Don't have aprsd try and send a reply
|
# Don't have aprsd try and send a reply
|
||||||
return messaging.NULL_MESSAGE
|
return packets.NULL_MESSAGE
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from aprsd import messaging
|
from aprsd import packets
|
||||||
|
|
||||||
import aprsd_slack_plugin
|
import aprsd_slack_plugin
|
||||||
from aprsd_slack_plugin import base_plugin
|
from aprsd_slack_plugin import base_plugin
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger("APRSD")
|
LOG = logging.getLogger("APRSD")
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,9 +47,9 @@ class SlackMessagePlugin(base_plugin.SlackPluginBase):
|
||||||
command_name = "message-slack"
|
command_name = "message-slack"
|
||||||
|
|
||||||
def command(self, packet):
|
def command(self, packet):
|
||||||
message = packet.get("message_text", None)
|
message = packet.message_text
|
||||||
fromcall = packet.get("from", None)
|
fromcall = packet.from_call
|
||||||
LOG.info("SlackMessagePlugin '{}'".format(message))
|
LOG.info(f"SlackMessagePlugin '{message}'")
|
||||||
|
|
||||||
is_setup = self.setup_slack()
|
is_setup = self.setup_slack()
|
||||||
if not is_setup:
|
if not is_setup:
|
||||||
|
@ -68,7 +69,7 @@ class SlackMessagePlugin(base_plugin.SlackPluginBase):
|
||||||
slack_message = {}
|
slack_message = {}
|
||||||
slack_message["username"] = "APRSD - Slack Message Plugin"
|
slack_message["username"] = "APRSD - Slack Message Plugin"
|
||||||
slack_message["icon_emoji"] = ":satellite_antenna:"
|
slack_message["icon_emoji"] = ":satellite_antenna:"
|
||||||
slack_message["text"] = "{} says {}".format(fromcall, message)
|
slack_message["text"] = f"{fromcall} says {message}"
|
||||||
slack_message["channel"] = "#random"
|
slack_message["channel"] = "#random"
|
||||||
|
|
||||||
LOG.debug(slack_message)
|
LOG.debug(slack_message)
|
||||||
|
@ -79,4 +80,4 @@ class SlackMessagePlugin(base_plugin.SlackPluginBase):
|
||||||
# self.swc.chat_postMessage(**message)
|
# self.swc.chat_postMessage(**message)
|
||||||
|
|
||||||
# Don't have aprsd try and send a reply
|
# Don't have aprsd try and send a reply
|
||||||
return messaging.NULL_MESSAGE
|
return packets.NULL_MESSAGE
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
pbr
|
pbr
|
||||||
slack_sdk>=3.0
|
slack_sdk>=3.0
|
||||||
slackeventsapi>=2.1.0
|
slackeventsapi>=2.1.0
|
||||||
aprsd>=2.0.0
|
aprsd>=2.7.0
|
||||||
|
|
Loading…
Reference in New Issue