#!/bin/sh # answer to stuff on irc # shellcheck disable=SC2119,SC2120 # shellcheck source=../lib/load-configuration . "${0%/*}/../lib/load-configuration" # welcome devs (in #archlinux32 and #archlinux32-devops only) welcome_user_regex='^\S\+ -!- \(abaumann\|deep42thought\)(.* has joined \S\+$' for channel in '#archlinux32:Hi \0!\n!rq \0' '#archlinux32-devops:Hi \0!'; do new_users=$( sed -i ' s/'"${welcome_user_regex}"'/\1/ T w /dev/stdout d ' "${irc_dir}/${channel%%:*}/out" \ | grep -vxF "$( { printf '%s SNIP\n' $(($(date +%s)-5*60)) cat "${irc_dir}/out" cat "${irc_dir}/${channel%%:*}/out" } \ | sort -k1nr,1 \ | sed ' /^\S\+ SNIP$/q ' \ | sed ' s/^\S\+\s\+-!- \([^([:space:]]\+\)\((\S\+\)\? has quit.*$/\1/ t d ' \ | sort -u )" \ | sort -u ) if [ -n "${new_users}" ]; then printf '%s\n' "${new_users}" | \ sed ' s/^.*$/'"${channel#*:}"'/ ' | \ irc_say "${channel%%:*}" 'copy' fi done find "${irc_dir}" \ -type f \ -name 'out' \ -printf '%p\n' | \ while read -r out_file; do channel="${out_file%/out}" channel="${channel##*/}" if [ -z "${channel%%#*}" ]; then prefix='buildmaster: ' sloppy_salutation='^\S\+\s\+\S\+\s.*buildmaster' else prefix='' sloppy_salutation='' fi # answer "why don't you?" regex='^\S\+ <\(\S\+\)> '"${prefix}"'!\?why[- ]don'"'"'\?t[- ]you \(build\|stabilize\|unstage\|keep\|stubbornly_keep\) \([^?]*\)?\?$' if grep -q "${regex}" "${out_file}"; then sed -i ' s/'"${regex}"'/\1 \2 \3/ T w /dev/stdout d ' "${out_file}" | \ while read -r asker line; do reason=$( echo "${line}" | \ xargs "${base_dir}/bin/why-dont-you" 2>&1 | \ sed ' 1 s/^/'"${asker}"': / ' ) if [ "$(echo "${reason}" | wc -l)" -le 5 ]; then echo "${reason}" else echo "${reason}" | \ head -n5 printf '... (%s lines total)\n' "$(echo "${reason}" | wc -l)" fi | \ irc_say "${channel}" 'copy' done fi # answer "wtf?" regex='^\S\+ <\(\S\+\)> '"${prefix}"'!\?wtf ' if grep -q "${regex}" "${out_file}"; then sed -i ' s/'"${regex}"'/\1 / T w /dev/stdout d ' "${out_file}" | \ while read -r asker line; do reason=$("${base_dir}/bin/wtf" "${line}"); if [ -z "${reason}" ]; then reason="Huh, I don't know that one." fi reason="${asker}: ${reason}" if [ "$(echo "${reason}" | wc -l)" -le 5 ]; then echo "${reason}" else echo "${reason}" | \ head -n5 printf '... (%s lines total)\n' "$(echo "${reason}" | wc -l)" fi | \ irc_say "${channel}" 'copy' done fi # answer "wtp?" regex='^\S\+ <\(\S\+\)> '"${prefix}"'!\?wtp ' if grep -q "${regex}" "${out_file}"; then sed -i ' s/'"${regex}"'/\1 / T w /dev/stdout d ' "${out_file}" | \ while read -r asker line; do reason=$("${base_dir}/bin/wtp" "${line}"); if [ -z "${reason}" ]; then reason="No, we don't have that." fi reason="${asker}: ${reason}" if [ "$(echo "${reason}" | wc -l)" -le 5 ]; then echo "${reason}" else echo "${reason}" | \ head -n5 printf '... (%s lines total)\n' "$(echo "${reason}" | wc -l)" fi | \ irc_say "${channel}" 'copy' done fi # answer "What's up?" regex='^\S\+ <\S\+> .*[Ww]hat'"'"'\?s *[Uu]p' if grep "${regex}" "${out_file}" | \ grep -q "${sloppy_salutation}"; then sed -i "/${regex}/d" "${out_file}" { printf 'up? I'"'"'m up for %s, %s' \ "$(uptime -p | sed 's/^up //')" \ "$(uptime | sed 's/.*, //')" if [ -s "${work_dir}/build-master-sanity" ]; then printf ' ... and I'"'"'m insane :-D' fi printf '\n' } | \ irc_say "${channel}" 'copy' fi # answer "Thanks!" regex='^\S\+ <\(\S\+\)> \(.* \)\?[Tt]h\(anks\|x\)\([ ,.!].*\)\?$' if grep "${regex}" "${out_file}" | \ grep -q "${sloppy_salutation}"; then sed -i ' /'"${sloppy_salutation}"'/ s/'"${regex}"'/np, \1/ T w /dev/stdout d ' "${out_file}" | \ sort -u | \ irc_say "${channel}" 'copy' fi # answer "sanity-check" regex='^\S\+ <\S\+> .*\([Gg]et.*straight\|[Pp]ull.*yourself.*together\|[Cc]heck.*again\)' if grep "${regex}" "${out_file}" | \ grep -q "${sloppy_salutation}"; then sed -i "/${regex}/d" "${out_file}" if [ -s "${work_dir}/build-master-sanity" ]; then printf 'I will check my sanity again.\n' \ | irc_say "${channel}" 'copy' "${base_dir}/bin/sanity-check" -w else printf 'Are you kidding? I'"'"'m all right.\n' \ | irc_say "${channel}" 'copy' fi fi # answer "say/tell ... new/random/more" regex='^\S\+ <\(\S\+\)> \(.* \)\?\([Ss]ay\|[Tt]ell\).*\(new\|random\|more\).*' if grep "${regex}" "${out_file}" | \ grep -q "${sloppy_salutation}"; then askers=$( sed -i ' /'"${sloppy_salutation}"'/ s/'"${regex}"'/\1/ T w /dev/stdout d ' "${out_file}" | \ sort -u ) if [ -n "${askers}" ]; then # markov's source is there: https://git.eckner.net/Erich/markov # its parameters are: a word list, the depth of the markov chain # and the count of words to print "${base_dir}/bin/markov" ~/.words.irc 3 "$(printf '%s\n' "${askers}" | wc -l)" | \ for asker in ${askers}; do if ! read -r random; then continue fi printf '%s: %s\n' "${asker}" "${random}" done | \ irc_say "${channel}" 'copy' fi fi # answer "bug/fs32 " regex='^\S\+ <\(\S\+\)> '"${prefix}"'!\?\([Bb]ug\|[Ff][Ss]\)\(32\)\? \([0-9]\+\)$' if grep -q "${regex}" "${out_file}"; then sed -i ' s@'"${regex}"'@\1: https://bugs.archlinux32.org/task/\4@ T w /dev/stdout d ' "${out_file}" | \ irc_say "${channel}" 'copy' fi if [ -z "${channel%%#*}" ]; then # answer "Shut up!" regex='^\S\+ <\S\+> \(.* \)\?([Ss][Hh][Uu][Tt] \?[Uu][Pp]\|pss\+t\|[Bb]e \(.* \)\?quiet' if grep "${regex}" "${out_file}" | \ grep -q "${sloppy_salutation}"; then sed -i "/${regex}/d" "${out_file}" printf 'Sorry, I will be quiet.\n' | \ irc_say "${channel}" 'copy' printf '%s\n' "$(( $(date '+%s') + 3600 ))" > "${work_dir}/irc-shut-up" fi fi done