Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/ii-answer
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-01-10 18:04:51 +0100
committerErich Eckner <git@eckner.net>2019-01-10 18:04:51 +0100
commitb0e5814f1fece32f6d42e6cb0b88bdb68fe5368a (patch)
tree1eff55a3afce606848ec0f1bf3d40a537738101e /bin/ii-answer
parent18e9ac261efcc127811baad009738d38c8493785 (diff)
bin/ii-answer: do not test with single regex, otherwise the salutation must be in fixed position relative to the other recognized words
Diffstat (limited to 'bin/ii-answer')
-rwxr-xr-xbin/ii-answer48
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!"