mirror of
https://github.com/hemna/aprsd-slack-plugin.git
synced 2024-12-03 21:53:13 -05:00
Added new notification and location plugin
This is an update to support the new version of aprsd
This commit is contained in:
parent
41468d5467
commit
3ce8471cb0
@ -1,6 +1,9 @@
|
||||
CHANGES
|
||||
=======
|
||||
|
||||
* Update for new plugin interface. Add Notify plugin
|
||||
* Added geo description in location
|
||||
* fixed tests for tox
|
||||
* fixed tests after refactoring
|
||||
* prep for release
|
||||
* new updated location plugin
|
||||
|
183
Makefile.venv
Normal file
183
Makefile.venv
Normal file
@ -0,0 +1,183 @@
|
||||
#
|
||||
# SEAMLESSLY MANAGE PYTHON VIRTUAL ENVIRONMENT WITH A MAKEFILE
|
||||
#
|
||||
# https://github.com/sio/Makefile.venv v2020.08.14
|
||||
#
|
||||
#
|
||||
# Insert `include Makefile.venv` at the bottom of your Makefile to enable these
|
||||
# rules.
|
||||
#
|
||||
# When writing your Makefile use '$(VENV)/python' to refer to the Python
|
||||
# interpreter within virtual environment and '$(VENV)/executablename' for any
|
||||
# other executable in venv.
|
||||
#
|
||||
# This Makefile provides the following targets:
|
||||
# venv
|
||||
# Use this as a dependency for any target that requires virtual
|
||||
# environment to be created and configured
|
||||
# python, ipython
|
||||
# Use these to launch interactive Python shell within virtual environment
|
||||
# shell, bash, zsh
|
||||
# Launch interactive command line shell. "shell" target launches the
|
||||
# default shell Makefile executes its rules in (usually /bin/sh).
|
||||
# "bash" and "zsh" can be used to refer to the specific desired shell.
|
||||
# show-venv
|
||||
# Show versions of Python and pip, and the path to the virtual environment
|
||||
# clean-venv
|
||||
# Remove virtual environment
|
||||
# $(VENV)/executable_name
|
||||
# Install `executable_name` with pip. Only packages with names matching
|
||||
# the name of the corresponding executable are supported.
|
||||
# Use this as a lightweight mechanism for development dependencies
|
||||
# tracking. E.g. for one-off tools that are not required in every
|
||||
# developer's environment, therefore are not included into
|
||||
# requirements.txt or setup.py.
|
||||
# Note:
|
||||
# Rules using such target or dependency MUST be defined below
|
||||
# `include` directive to make use of correct $(VENV) value.
|
||||
# Example:
|
||||
# codestyle: $(VENV)/pyflakes
|
||||
# $(VENV)/pyflakes .
|
||||
# See `ipython` target below for another example.
|
||||
#
|
||||
# This Makefile can be configured via following variables:
|
||||
# PY
|
||||
# Command name for system Python interpreter. It is used only initialy to
|
||||
# create the virtual environment
|
||||
# Default: python3
|
||||
# REQUIREMENTS_TXT
|
||||
# Space separated list of paths to requirements.txt files.
|
||||
# Paths are resolved relative to current working directory.
|
||||
# Default: requirements.txt
|
||||
# WORKDIR
|
||||
# Parent directory for the virtual environment.
|
||||
# Default: current working directory.
|
||||
# VENVDIR
|
||||
# Python virtual environment directory.
|
||||
# Default: $(WORKDIR)/.venv
|
||||
#
|
||||
# This Makefile was written for GNU Make and may not work with other make
|
||||
# implementations.
|
||||
#
|
||||
#
|
||||
# Copyright (c) 2019-2020 Vitaly Potyarkin
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0
|
||||
# <http://www.apache.org/licenses/LICENSE-2.0>
|
||||
#
|
||||
|
||||
|
||||
#
|
||||
# Configuration variables
|
||||
#
|
||||
|
||||
PY?=python3
|
||||
WORKDIR?=.
|
||||
VENVDIR?=$(WORKDIR)/.venv
|
||||
REQUIREMENTS_TXT?=$(wildcard requirements.txt) # Multiple paths are supported (space separated)
|
||||
MARKER=.initialized-with-Makefile.venv
|
||||
|
||||
|
||||
#
|
||||
# Internal variable resolution
|
||||
#
|
||||
|
||||
VENV=$(VENVDIR)/bin
|
||||
EXE=
|
||||
# Detect windows
|
||||
ifeq (win32,$(shell $(PY) -c "import __future__, sys; print(sys.platform)"))
|
||||
VENV=$(VENVDIR)/Scripts
|
||||
EXE=.exe
|
||||
endif
|
||||
|
||||
|
||||
#
|
||||
# Virtual environment
|
||||
#
|
||||
|
||||
.PHONY: venv
|
||||
venv: $(VENV)/$(MARKER)
|
||||
|
||||
.PHONY: clean-venv
|
||||
clean-venv:
|
||||
-$(RM) -r "$(VENVDIR)"
|
||||
|
||||
.PHONY: show-venv
|
||||
show-venv: venv
|
||||
@$(VENV)/python -c "import sys; print('Python ' + sys.version.replace('\n',''))"
|
||||
@$(VENV)/pip --version
|
||||
@echo venv: $(VENVDIR)
|
||||
|
||||
.PHONY: debug-venv
|
||||
debug-venv:
|
||||
@$(MAKE) --version
|
||||
$(info PY="$(PY)")
|
||||
$(info REQUIREMENTS_TXT="$(REQUIREMENTS_TXT)")
|
||||
$(info VENVDIR="$(VENVDIR)")
|
||||
$(info VENVDEPENDS="$(VENVDEPENDS)")
|
||||
$(info WORKDIR="$(WORKDIR)")
|
||||
|
||||
|
||||
#
|
||||
# Dependencies
|
||||
#
|
||||
|
||||
ifneq ($(strip $(REQUIREMENTS_TXT)),)
|
||||
VENVDEPENDS+=$(REQUIREMENTS_TXT)
|
||||
endif
|
||||
|
||||
ifneq ($(wildcard setup.py),)
|
||||
VENVDEPENDS+=setup.py
|
||||
endif
|
||||
ifneq ($(wildcard setup.cfg),)
|
||||
VENVDEPENDS+=setup.cfg
|
||||
endif
|
||||
|
||||
$(VENV):
|
||||
$(PY) -m venv $(VENVDIR)
|
||||
$(VENV)/python -m pip install --upgrade pip setuptools wheel
|
||||
|
||||
$(VENV)/$(MARKER): $(VENVDEPENDS) | $(VENV)
|
||||
ifneq ($(strip $(REQUIREMENTS_TXT)),)
|
||||
$(VENV)/pip install $(foreach path,$(REQUIREMENTS_TXT),-r $(path))
|
||||
endif
|
||||
ifneq ($(wildcard setup.py),)
|
||||
$(VENV)/pip install -e .
|
||||
endif
|
||||
touch $(VENV)/$(MARKER)
|
||||
|
||||
|
||||
#
|
||||
# Interactive shells
|
||||
#
|
||||
|
||||
.PHONY: python
|
||||
python: venv
|
||||
exec $(VENV)/python
|
||||
|
||||
.PHONY: ipython
|
||||
ipython: $(VENV)/ipython
|
||||
exec $(VENV)/ipython
|
||||
|
||||
.PHONY: shell
|
||||
shell: venv
|
||||
. $(VENV)/activate && exec $(notdir $(SHELL))
|
||||
|
||||
.PHONY: bash zsh
|
||||
bash zsh: venv
|
||||
. $(VENV)/activate && exec $@
|
||||
|
||||
|
||||
#
|
||||
# Commandline tools (wildcard rule, executable name must match package name)
|
||||
#
|
||||
|
||||
ifneq ($(EXE),)
|
||||
$(VENV)/%: $(VENV)/%$(EXE) ;
|
||||
.PHONY: $(VENV)/%
|
||||
.PRECIOUS: $(VENV)/%$(EXE)
|
||||
endif
|
||||
|
||||
$(VENV)/%$(EXE): $(VENV)/$(MARKER)
|
||||
$(VENV)/pip install --upgrade $*
|
||||
touch $@
|
82
aprsd_slack_plugin/message_plugin.py
Normal file
82
aprsd_slack_plugin/message_plugin.py
Normal file
@ -0,0 +1,82 @@
|
||||
import logging
|
||||
import re
|
||||
|
||||
from aprsd import messaging
|
||||
|
||||
import aprsd_slack_plugin
|
||||
from aprsd_slack_plugin import base_plugin
|
||||
|
||||
LOG = logging.getLogger("APRSD")
|
||||
|
||||
|
||||
class SlackMessagePlugin(base_plugin.SlackPluginBase):
|
||||
"""SlackMessagePlugin.
|
||||
|
||||
This APRSD plugin looks for the slack msg command comming in
|
||||
to aprsd, then forwards the message to the configured slack channel.
|
||||
|
||||
To use this:
|
||||
Create a slack bot for your workspace at api.slack.com.
|
||||
A good source of information on how to create the app
|
||||
and the tokens and permissions and install the app in your
|
||||
workspace is here:
|
||||
|
||||
https://api.slack.com/start/building/bolt-python
|
||||
|
||||
|
||||
You will need the signing secret from the
|
||||
Basic Information -> App Credentials form.
|
||||
You will also need the Bot User OAuth Access Token from
|
||||
OAuth & Permissions -> OAuth Tokens for Your Team ->
|
||||
Bot User OAuth Access Token.
|
||||
|
||||
Install the app/bot into your workspace.
|
||||
|
||||
Edit your ~/.config/aprsd/aprsd.yml and add the section
|
||||
slack:
|
||||
signing_secret: <signing secret token here>
|
||||
bot_token: <Bot User OAuth Access Token here>
|
||||
channel: <channel name here>
|
||||
"""
|
||||
|
||||
version = aprsd_slack_plugin.__version__
|
||||
|
||||
# matches any string starting with h or H
|
||||
command_regex = "^[sS]"
|
||||
command_name = "message-slack"
|
||||
|
||||
def command(self, packet):
|
||||
message = packet.get("message_text", None)
|
||||
fromcall = packet.get("from", None)
|
||||
LOG.info("SlackMessagePlugin '{}'".format(message))
|
||||
|
||||
is_setup = self.setup_slack()
|
||||
if not is_setup:
|
||||
LOG.error("Slack isn't setup!")
|
||||
return
|
||||
|
||||
# optional second argument is a callsign to search
|
||||
a = re.search(r"^.*\s+(.*)", message)
|
||||
LOG.debug(a)
|
||||
if a is not None:
|
||||
searchcall = a.group(1)
|
||||
searchcall = searchcall.upper()
|
||||
else:
|
||||
# if no second argument, search for calling station
|
||||
searchcall = fromcall
|
||||
|
||||
slack_message = {}
|
||||
slack_message["username"] = "APRSD - Slack Message Plugin"
|
||||
slack_message["icon_emoji"] = ":satellite_antenna:"
|
||||
slack_message["text"] = "{} says {}".format(fromcall, message)
|
||||
slack_message["channel"] = "#random"
|
||||
|
||||
LOG.debug(slack_message)
|
||||
|
||||
self.swc.chat_postMessage(**slack_message)
|
||||
# for channel in self.slack_channels:
|
||||
# message["channel"] = channel
|
||||
# self.swc.chat_postMessage(**message)
|
||||
|
||||
# Don't have aprsd try and send a reply
|
||||
return messaging.NULL_MESSAGE
|
@ -1,4 +1,4 @@
|
||||
pbr
|
||||
slack_sdk>=3.0
|
||||
slackeventsapi>=2.1.0
|
||||
aprsd>=1.5.2
|
||||
aprsd
|
||||
|
Loading…
Reference in New Issue
Block a user