summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbill-auger <mr.j.spam.me@gmail.com>2019-04-21 03:33:48 -0400
committerbill-auger <mr.j.spam.me@gmail.com>2019-04-21 04:14:45 -0400
commite6481f020982dcfc30f75e224f6649053abf3776 (patch)
tree468aa76c6bcc9f2826fa3223a379c9c6671faffd
parentd955de148bbda4456746536b9196af7e3314b789 (diff)
teach pbot to parse to forum posts
-rwxr-xr-xlabs_change_detector50
1 files changed, 37 insertions, 13 deletions
diff --git a/labs_change_detector b/labs_change_detector
index dc2b405..fb8862e 100755
--- a/labs_change_detector
+++ b/labs_change_detector
@@ -3,46 +3,70 @@
source ./bot_settings.sh
source ./lib/send.sh
source ./transport/transport_plus_ipc.sh.inc
+shopt -s extglob
+
if ! which inotifywait &> /dev/null
then
- echo '[LABS]: inotify is a dep. fail'
+ echo "[LABS]: ERROR: cannot find the \`inotify\` program"
exit
-fi
-if [[ ! -d "${BOT_MAIL_DIR}" ]]
-then
+elif [[ ! -d "${BOT_MAIL_DIR}" ]]
echo "[LABS]: no such directory set in BOT_MAIL_DIR: '${BOT_MAIL_DIR}'. fail"
exit
fi
-
-shopt -s extglob
-
-next_line_is_url=0
-
inotifywait -m --format '%w%f' -e create "${BOT_MAIL_DIR}" 2>/dev/null |
while read email
do
+ is_forum=0
+ is_reply=0
+ thread=''
+ next_line_is_url=0
+
while read line
do
case "${line}" in
'Subject: ['* )
lp1="${line#Subject: [}"
lp="${lp1%% - *}"
+ [[ "$lp" == 'Parabola Community Forum' ]] && is_forum=1 || is_forum=0
+ (( is_forum )) && line=$(echo ${line##*]})
+ next_line_continues_subject=${is_forum}
+
echo -n "${lp}"
;;
+ 'Mime-Version: '* )
+ next_line_continues_subject=0
+ [[ "${thread#RE:}" != "${thread}" ]] && is_reply=1 || is_reply=0
+ ;;
+
'Issue #'* )
- echo -n " - ${line}"
+ nick=${line}
+ echo -n " - ${nick}"
+ ;;
+ 'X-Redmine-Sender: '* )
+ nick=${line##*: }
+
+ (( is_forum )) && ! (( is_reply )) && echo -n " - ${nick} started: \"${thread#RE:*}\""
+ (( is_forum )) && (( is_reply )) && echo -n " - ${nick} commented on: \"${thread#RE:*}\""
;;
+
*' #'+([[:digit:]])': '* )
echo -n " (${line#'Bug #'+([[:digit:]])': '})"
- next_line_is_url=1
+ ! (( is_forum )) && next_line_is_url=1
+ ;;
+ 'List-Id: <labs.parabola.nu>' )
+ (( is_forum )) && next_line_is_url=1
;;
- 'https://labs.parabola.nu/issues/'* )
- (( next_line_is_url )) && echo -n " ${line}"
+
+ 'https://labs.parabola.nu/issues/'* | \
+ 'https://labs.parabola.nu/boards/'* )
+ (( next_line_is_url )) && echo -n " - <${line}>"
break
;;
esac
+
+ (( next_line_continues_subject )) && thread+="${line}"
done < "${email}"
echo