diff options
-rwxr-xr-x | bin/ii-answer | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/bin/ii-answer b/bin/ii-answer index ced8867..3fb9926 100755 --- a/bin/ii-answer +++ b/bin/ii-answer @@ -35,10 +35,10 @@ find "${irc_dir}" \ channel="${channel##*/}" if [ -z "${channel%%#*}" ]; then prefix='buildmaster: ' - sloppy_salutation='^\S\+\s\+<\(\S\+\)>\s.*buildmaster' + sloppy_salutation='^\S\+\s\+\S\+\s.*buildmaster' else prefix='' - sloppy_salutation='^\S\+\s\+<\(\S\+\)>\s' + sloppy_salutation='' fi # answer "why don't you?" regex='^\S\+ <\(\S\+\)> '"${prefix}"'!\?why[- ]don'"'"'\?t[- ]you \(build\|stabilize\|unstage\|keep\|stubbornly_keep\) ' @@ -147,29 +147,31 @@ find "${irc_dir}" \ irc_say "${channel}" 'copy' fi # answer "say/tell ... new/random/more" - regex="${sloppy_salutation}"'.*\(say\|tell\).*\(new\|random\|more\).*' - askers=$( - sed -i ' - /'"${regex}"'/ { - s/'"${regex}"'/\1/ + 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' + ' "${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 if [ -z "${channel%%#*}" ]; then # answer "Shut up!" |