summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbill-auger <mr.j.spam.me@gmail.com>2019-09-23 17:44:45 -0400
committerbill-auger <mr.j.spam.me@gmail.com>2019-11-27 23:42:50 -0500
commit8375e8e21aa40c6bc4c4c816620ae40696ed929d (patch)
tree6ccbc66f4dd79e5c180dceca0fef2f018f22627f
parent4b404b554bb09e10e1366691c9990c9abd98122b (diff)
add 'pbot-say' and notification git hook
-rw-r--r--bot_settings.sh2
-rw-r--r--lib/main.sh3
-rw-r--r--lib/send.sh8
-rw-r--r--modules/m_spamfilter.sh2
-rwxr-xr-xnotify-pbot-git-hook19
-rwxr-xr-xpbot-say10
-rw-r--r--transport/transport_plus_ipc.sh.inc11
7 files changed, 43 insertions, 12 deletions
diff --git a/bot_settings.sh b/bot_settings.sh
index cff7942..8c7dc13 100644
--- a/bot_settings.sh
+++ b/bot_settings.sh
@@ -186,7 +186,7 @@ readonly OP_CHANNELS='#parabola'
# mail directory to use to trigger creation of internally injected messages (e.g. redmine changes)
readonly BOT_MAIL_DIR="/home/pbot/Maildir/new"
# storage file to use for internally injected messages pending
-readonly IPC_STORE_FILE=/tmp/un-provoked-message-store
+readonly IPC_QUEUE_FILE=/var/lib/pbot/ipc-message-queue
# nick to use for internally injected messages
readonly INJECT_NICK='01234-PBOT-BCDEF%' # invalid IRC nick
# prefix to use for internally injected messages
diff --git a/lib/main.sh b/lib/main.sh
index ac28f05..36ac055 100644
--- a/lib/main.sh
+++ b/lib/main.sh
@@ -334,11 +334,12 @@ debug_init
log_info_stdout "Loading transport"
source "${config_transport_dir}/${config_transport}.sh"
-source "${config_transport_dir}/transport_plus_ipc.sh.inc" # common transport_read_line()
if [[ $? -ne 0 ]]; then
log_fatal "Couldn't load transport. Couldn't load the file..."
envbot_quit 2
fi
+source "${config_transport_dir}/transport_plus_ipc.sh.inc" # refactored common transport_read_line()
+touch "${IPC_QUEUE_FILE}" || log_error "[MAIN]: ERROR: insufficient permissions on \$IPC_QUEUE_FILE: '${IPC_QUEUE_FILE}' (should be world-writable)."
if ! transport_check_support; then
log_fatal "The transport reported it can't work on this system or with this configuration."
diff --git a/lib/send.sh b/lib/send.sh
index 59f90df..9cbe247 100644
--- a/lib/send.sh
+++ b/lib/send.sh
@@ -181,14 +181,14 @@ send_ipc_msg()
{
if [[ -z "${IPC_NOTICE_CHANNEL}" ]]
then echo '[SEND]: no target channel set in IPC_NOTICE_CHANNEL'
- elif ! touch "${IPC_STORE_FILE}" 2> /dev/null
- then echo "[SEND]: no such file set in IPC_STORE_FILE: '${IPC_STORE_FILE}'"
+ elif ! touch "${IPC_QUEUE_FILE}" 2> /dev/null
+ then echo "[SEND]: no such file set in IPC_QUEUE_FILE: '${IPC_QUEUE_FILE}'"
else
local delay_secs=$1 ; shift ;
local message=$*
local delivery_time=$(( $(date +%s) + ${delay_secs} ))
- echo "${delivery_time} ${IPC_NOTICE_CHANNEL} ${message}" >> "${IPC_STORE_FILE}"
- sort -o "${IPC_STORE_FILE}" "${IPC_STORE_FILE}"
+ echo "${delivery_time} ${IPC_NOTICE_CHANNEL} ${message}" >> "${IPC_QUEUE_FILE}"
+ sort -o "${IPC_QUEUE_FILE}" "${IPC_QUEUE_FILE}"
fi
}
diff --git a/modules/m_spamfilter.sh b/modules/m_spamfilter.sh
index 6f6253e..c3ac9b0 100644
--- a/modules/m_spamfilter.sh
+++ b/modules/m_spamfilter.sh
@@ -151,7 +151,7 @@ module_spamfilter_on_PART()
[[ " ${FILTER_CHANNELS} " =~ " ${channel} " ]] && \
[[ " ${OP_CHANNELS} " =~ " ${channel} " ]] && \
[[ -d "${person_dir}" ]] && \
- grep -E ${welcome_regex} "${IPC_STORE_FILE}" &> /dev/null && rm -rf ${person_dir}
+ grep -E ${welcome_regex} "${IPC_QUEUE_FILE}" &> /dev/null && rm -rf ${person_dir}
}
module_spamfilter_on_PRIVMSG() # (hostmask , target , query)
diff --git a/notify-pbot-git-hook b/notify-pbot-git-hook
new file mode 100755
index 0000000..6cb993d
--- /dev/null
+++ b/notify-pbot-git-hook
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+eval $( sed -En 's|^([0-9a-f]{40}) ([0-9a-f]{40}) .*/([^/]*)$|prev=\1 curr=\2 branch=\3|p')
+author="$( git log -1 --format='%an')"
+log_msg="$(git log -1 --format='%s')"
+n_behind=$(git rev-list $curr..$prev --count)
+n_ahead=$( git rev-list $prev..$curr --count)
+
+if false # DEBUG
+then echo "prev=$prev" > ./notify-pbot.debug
+ echo "curr=$curr" >> ./notify-pbot.debug
+ echo "branch=$branch" >> ./notify-pbot.debug
+ echo "author=$author" >> ./notify-pbot.debug
+ echo "log_msg=$log_msg" >> ./notify-pbot.debug
+ echo "n_behind=$n_behind" >> ./notify-pbot.debug
+ echo "n_ahead=$n_ahead" >> ./notify-pbot.debug
+fi # DEBUG
+
+pbot-say "${author} just pushed (-${n_behind} +${n_ahead}) commits to $(basename $(pwd))/${branch}: ${log_msg}"
diff --git a/pbot-say b/pbot-say
new file mode 100755
index 0000000..06bb1bd
--- /dev/null
+++ b/pbot-say
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+# pbot will postpone delivery of this message until $DELIVERY_TS
+readonly DELAY_SECS=0
+readonly DELIVERY_TS=$(( $(date +%s) + ${DELAY_SECS} ))
+readonly TARGET_CHANNEL='#parabola'
+readonly IPC_QUEUE_FILE=/var/lib/pbot/ipc-message-queue # ASSERT: per bot_settings.sh
+
+
+echo "${DELIVERY_TS} ${TARGET_CHANNEL} $*" >> ${IPC_QUEUE_FILE}
diff --git a/transport/transport_plus_ipc.sh.inc b/transport/transport_plus_ipc.sh.inc
index fc9ab70..815061c 100644
--- a/transport/transport_plus_ipc.sh.inc
+++ b/transport/transport_plus_ipc.sh.inc
@@ -4,11 +4,12 @@ transport_plus_ipc_read_line() {
local postpone_ipc=0
while true
do
- local n_msgs=$(wc -l "${IPC_STORE_FILE}" 2> /dev/null | cut -d ' ' -f 1)
+ local n_msgs=$(wc -l "${IPC_QUEUE_FILE}" 2> /dev/null | cut -d ' ' -f 1)
+
# set $line variable from IPC message
- if ! (( ${postpone_ipc} )) && (( ${n_msgs} )) && [[ -w "${IPC_STORE_FILE}" ]]
+ if ! (( ${postpone_ipc} )) && (( ${n_msgs} )) && [[ -w "${IPC_QUEUE_FILE}" ]]
then
- read -r line < "${IPC_STORE_FILE}"
+ read -r line < "${IPC_QUEUE_FILE}"
if [[ "${line}" =~ ^([0-9]{10})\ (#[^\ ]*)\ (.*)$ ]]
then
@@ -32,9 +33,9 @@ transport_plus_ipc_read_line() {
if (( ${n_msgs} < 2 ))
then
- echo -n > "${IPC_STORE_FILE}"
+ echo -n > "${IPC_QUEUE_FILE}"
else
- tail -n +2 "${IPC_STORE_FILE}" | sponge "${IPC_STORE_FILE}"
+ tail -n +2 "${IPC_QUEUE_FILE}" | sponge "${IPC_QUEUE_FILE}"
fi
break