diff options
-rwxr-xr-x | labs_change_detector | 1 | ||||
-rw-r--r-- | lib/main.sh | 10 | ||||
-rw-r--r-- | process_event | 17 | ||||
-rw-r--r-- | transport/transport_plus_ipc.sh.inc | 11 |
4 files changed, 20 insertions, 19 deletions
diff --git a/labs_change_detector b/labs_change_detector index e272fb3..16a440d 100755 --- a/labs_change_detector +++ b/labs_change_detector @@ -2,7 +2,6 @@ source ./bot_settings.sh source ./lib/send.sh -source ./transport/transport_plus_ipc.sh.inc shopt -s extglob diff --git a/lib/main.sh b/lib/main.sh index 36ac055..8a8bcee 100644 --- a/lib/main.sh +++ b/lib/main.sh @@ -123,21 +123,21 @@ envbot_quit() { } # Check for moreutils else we're doomed. -if ! which sponge +if ! which sponge > /dev/null then echo "moreutils is a dep, please install." envbot_quit 1 fi # Check for w3m because we use it to convert html entities. -if ! which w3m +if ! which w3m > /dev/null then echo "w3m is a dep, please install." envbot_quit 1 fi # Check for recode -if ! which recode +if ! which recode > /dev/null then echo "recode is a dep, please install." envbot_quit 1 @@ -332,10 +332,10 @@ time_init log_init debug_init -log_info_stdout "Loading transport" +log_info_stdout "Loading transport: '${config_transport}'" source "${config_transport_dir}/${config_transport}.sh" if [[ $? -ne 0 ]]; then - log_fatal "Couldn't load transport. Couldn't load the file..." + log_fatal "Couldn't load transport in file: ${config_transport_dir}/${config_transport}.sh" envbot_quit 2 fi source "${config_transport_dir}/transport_plus_ipc.sh.inc" # refactored common transport_read_line() diff --git a/process_event b/process_event index ae97b58..2347e7e 100644 --- a/process_event +++ b/process_event @@ -96,10 +96,10 @@ function process_event line_filtered=${line##*PRIVMSG +([![:space:]]) :} [[ "${line_filtered}" != 'Parabola Community Forum' ]] && \ - (($is_injected_msg)) && send_msg "${channel_it_came_from}" "${line_filtered}" - # NOTE: this 'injected_data' is the IPC mechanism - # used by the ./labs_change_detector script - # see ./labs_change_detector, transport/socat.sh, and transport/dev-tcp.sh + (( ${is_injected_msg} )) && send_msg "${channel_it_came_from}" "${line_filtered}" + # NOTE: 'is_injected_msg' is the IPC mechanism + # used by ./pbot-say and the ./labs_change_detector script + # see ./labs_change_detector, ./pbot-say , ./transport_plus_ipc.sh.inc # the 'send_msg' command above was originally mutually exclusive # with the remaining entirety of this function # and it was the only place where the 'injected_data' var was set @@ -107,7 +107,9 @@ function process_event # yet, that is tested for below in the 'Page title getter' section # so, presumably this 'injected_data' was intended to fall through? # or perhaps not, because the "Shared libraries error" matcher - # does not filter this 'injected_data', which it should + # does not filter out these messages, which it should + # supressing furthur handling of such messages for now + (( ${is_injected_msg} )) && return ############################################################### @@ -256,10 +258,7 @@ function process_event done ) - if ! [[ -z ${the_title} ]] - then - send_msg "${channel_it_came_from}" "Page title: '${the_title}'" - fi + [[ -n "${the_title}" ]] && send_msg "${channel_it_came_from}" "Page title: '${the_title}'" fi diff --git a/transport/transport_plus_ipc.sh.inc b/transport/transport_plus_ipc.sh.inc index 998f7c3..92e515a 100644 --- a/transport/transport_plus_ipc.sh.inc +++ b/transport/transport_plus_ipc.sh.inc @@ -2,6 +2,7 @@ # set $line variable for further processing transport_plus_ipc_read_line() { local postpone_ipc=0 + while true do local n_msgs=$(wc -l "${IPC_QUEUE_FILE}" 2> /dev/null | cut -d ' ' -f 1) @@ -11,24 +12,25 @@ transport_plus_ipc_read_line() { then read -r line < "${IPC_QUEUE_FILE}" - if [[ "${line}" =~ ^([0-9]{10})\ (#[^\ ]*)\ (.*)$ ]] + if [[ "${line}" =~ ^([0-9]{10})\ (#[^\ ]*)\ ([^\ ].*)$ ]] then local delivery_time="${BASH_REMATCH[1]}" local target_channel="${BASH_REMATCH[2]}" local message="${BASH_REMATCH[3]}" local pending_line="${IPC_INJECT_PREFIX} ${target_channel} :${message}" + local should_postpone=$( (( ${delivery_time} > $(date +%s) )) && echo 1 || echo 0) - (( ${delivery_time} < $(date +%s) )) && line="${pending_line}" || line='' + line=$( ! (( ${should_postpone} )) && echo "${pending_line}" || echo '') # echo "[IPC]: delivery_time=${BASH_REMATCH[1]}" # echo "[IPC]: target_channel=${BASH_REMATCH[2]}" # echo "[IPC]: message=${BASH_REMATCH[3]}" -# echo "[IPC]: pending_line=${IPC_INJECT_PREFIX} ${target_channel} :${message}" +# echo "[IPC]: pending_line=${pending_line}" [[ -n "${line}" ]] && log_info "[IPC]: relaying to channel: ${target_channel} msg: ${message}" # || log_info "[IPC]: postponing" else - line='ERROR: invalid IPC message' + line='ERROR: invalid IPC message: ${line}' fi [[ -z "${line}" ]] && postpone_ipc=1 && continue @@ -41,6 +43,7 @@ transport_plus_ipc_read_line() { fi break + # set $line variable from network message else read -t 5 -ru 3 line |