From b0e5814f1fece32f6d42e6cb0b88bdb68fe5368a Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Thu, 10 Jan 2019 18:04:51 +0100 Subject: bin/ii-answer: do not test with single regex, otherwise the salutation must be in fixed position relative to the other recognized words --- bin/ii-answer | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'bin/ii-answer') 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!" -- cgit v1.2.3