Annna is a woman now. She listens on all channels. - annna - Annna the nice friendly bot. HTML git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/ DIR Log DIR Files DIR Refs DIR Tags DIR README --- DIR commit 7d52d331bf02f2b674bb6a697c71c68987826e34 DIR parent 7508bcc3337150305f3850897b994a2a8f951bd6 HTML Author: Annna Robert-Houdin <annna@bitreich.org> Date: Wed, 13 May 2020 19:44:19 +0200 Annna is a woman now. She listens on all channels. Diffstat: M annna-start-services | 1254 ++++++++++++++++--------------- 1 file changed, 641 insertions(+), 613 deletions(-) --- DIR diff --git a/annna-start-services b/annna-start-services @@ -30,689 +30,717 @@ regeximatch() { printf '%s' "$1" | grep -i -E -q "$2" } -# Permissions -[ -d ${iiroot} ] && chmod o+rx ${iiroot} -[ -d ${iibase} ] && chmod o+rx ${iibase} -## EN Channel (this script) -[ -d "${iibase}/#bitreich-en" ] \ - && chmod o+rx "${iibase}/#bitreich-en" -[ -p "${iibase}/#bitreich-en/in" ] \ - && chmod o+w "${iibase}/#bitreich-en/in" -## SCM (/scm/post-receive) -[ -d "${iibase}/#bitreich-scm" ] \ - && chmod o+rx "${iibase}/#bitreich-scm" -[ -p "${iibase}/#bitreich-scm/in" ] \ - && chmod o+w "${iibase}/#bitreich-scm/in" -## Radio (/br/radio/playlist.sh + this script) -[ -d "${iibase}/#bitreich-radio" ] \ - && chmod o+rx "${iibase}/#bitreich-radio" -[ -p "${iibase}/#bitreich-radio/in" ] \ - && chmod o+w "${iibase}/#bitreich-radio/in" - -if [ -f "${iibase}/#bitreich-radio/out" ]; -then -# bitreich-radio -{ - ls "${iibase}/#bitreich-radio/out" | entr tail -n 1 "${iibase}/#bitreich-radio/out" \ - | grep -v --line-buffered '[0-9]* -!- ' \ - | sed -u 's,[0-9]* <\([^ >]*\)> \(.*\),\1\n\2,' \ - | { - while read -r user; - do - read -r text - - [ "$user" = "${botname}" ] && continue - - if [ "${text}" = "${botname}, next please." ]; - then - /br/bin/bitreich-radio-playlist-next - annna-say -c "#bitreich-radio" "You are very kind ${user}. To your command." - continue; - fi - - if [ "${text}" = "${botname}, please help." ]; - then - annna-say -c "${user}" "»next please.« gets the playlist further, ${user}." - annna-say -c "${user}" "»please help.« gives you this help listing, ${user}." - continue; - fi - done - } -} & -fi - -# bitreich-en -if [ -f "${iibase}/#bitreich-en/out" ]; -then -{ - ls "${iibase}/#bitreich-en/out" | entr tail -n 1 "${iibase}/#bitreich-en/out" \ - | grep -v --line-buffered '[0-9]* -!- ' \ - | sed -u 's,[0-9]* <\([^ >]*\)> \(.*\),\1\n\2,' \ - | { - while read -r user; - do - read -r text - [ "$user" = "${botname}" ] && continue - - uri="$(printf "%s\n" "${text}" \ - | sed -n '/.*\(https\{0,1\}:\/\/[^ ]\{1,\}\).*/s//\1/p')" - case "${text}" in - *\#nospoil*) - ;; - *) - if [ -n "$uri" ]; +annna_common() { + channel="$1" + user="$2" + text="$3" + + printf "annna_common: %s %s %s\n" "${channel}" "${user}" "${text}" + + [ "$user" = "${botname}" ] && return + + uri="$(printf "%s\n" "${text}" \ + | sed -n '/.*\(https\{0,1\}:\/\/[^ ]\{1,\}\).*/s//\1/p')" + case "${text}" in + *\#nospoil*) + ;; + *) + if [ -n "$uri" ]; + then + tmpf=$(mktemp) + fetch-url "${uri}" > "${tmpf}" + urititle="$(grabtitle < "${tmpf}" | sed 's/^ *\(.\{0,200\}\).*/\1/')" + # TODO: Replace all of this with a better logic for parsing global domains. + if [ -n "$urititle" ]; then - tmpf=$(mktemp) - fetch-url "${uri}" > "${tmpf}" - urititle="$(grabtitle < "${tmpf}" | sed 's/^ *\(.\{0,200\}\).*/\1/')" - # TODO: Replace all of this with a better logic for parsing global domains. - if [ -n "$urititle" ]; - then - case "${urititle}" in - *Gunther*|*GUNTHER*|*Gnther*) - annna-say -c "#bitreich-en" "Oh Gunther! ❤ ❤ ❤ ${urititle}" - ;; - *\|\ Cloudflare*) - annna-say -c "#bitreich-en" "Mind your own business! We got clownflared: gopher://bitreich.org/0/ascii/clownflare.vt" - ;; - *) - if expr "${uri}" : '^https*://[^/]*youtu\(\.be\|be\..\{2,3\}\)/' + case "${urititle}" in + *Gunther*|*GUNTHER*|*Gnther*) + annna-say -c "${channel}" "Oh Gunther! ❤ ❤ ❤ ${urititle}" + ;; + *\|\ Cloudflare*) + annna-say -c "${channel}" "Mind your own business! We got clownflared: gopher://bitreich.org/0/ascii/clownflare.vt" + ;; + *) + if expr "${uri}" : '^https*://[^/]*youtu\(\.be\|be\..\{2,3\}\)/' + then + spurl="$(subtitle-paste "${uri}")" + if [ -n "${spurl}" ]; then - spurl="$(subtitle-paste "${uri}")" - if [ -n "${spurl}" ]; - then - annna-say -c "#bitreich-en" "HTML title: ${urititle} ; subtitles: ${spurl}" - else - annna-say -c "#bitreich-en" "HTML title: ${urititle}" - fi + annna-say -c "${channel}" "HTML title: ${urititle} ; subtitles: ${spurl}" else - wikipedia=0 - case "${uri}" in - *twitter.com*) - nurl="$(printf "%s\n" "${uri}" | sed 's;\(mobile\.\)\{0,1\}twitter\.com;nitter\.net;')" - spurl="$(screenshot-paste "${nurl}")" - annna-say -c '#bitreich-en' "nitter: ${nurl}" - - ;; - *en.wikipedia.org/wiki*) - if ! regeximatch "$uri" '\.(jpg,bmp,gif,png,tiff,avi,mp4,webm,mkv,pdf,ps,eps)$'; then - nurl="$(printf '%s\n' "${uri}" | sed "s;.*en.wikipedia.org/wiki;gopher://gopherpedia.com/0;")" - purl="$(9 htmlfmt < "${tmpf}" | /br/bin/bitreich-paste)" - annna-say -c '#bitreich-en' "gopherpedia: ${nurl} ; content: ${purl}" - # Hack, Hack, Hack. - wikipedia=1 - fi - ;; - *www.reddit.com*) - nurl="$(printf '%s\n' "${uri}" | sed "s;www.reddit.com;old.reddit.com;")" + annna-say -c "${channel}" "HTML title: ${urititle}" + fi + else + wikipedia=0 + case "${uri}" in + *twitter.com*) + nurl="$(printf "%s\n" "${uri}" | sed 's;\(mobile\.\)\{0,1\}twitter\.com;nitter\.net;')" + spurl="$(screenshot-paste "${nurl}")" + annna-say -c "${channel}" "nitter: ${nurl}" + + ;; + *en.wikipedia.org/wiki*) + if ! regeximatch "$uri" '\.(jpg,bmp,gif,png,tiff,avi,mp4,webm,mkv,pdf,ps,eps)$'; then + nurl="$(printf '%s\n' "${uri}" | sed "s;.*en.wikipedia.org/wiki;gopher://gopherpedia.com/0;")" purl="$(9 htmlfmt < "${tmpf}" | /br/bin/bitreich-paste)" - if [ -n "${uri#*www.reddit.com/r/*}" ]; then - subreddit="$(printf '%s\n' "${uri}" | cut -d / -f 5)" - post="$(printf '%s\n' "${uri}" | cut -d / -f 7)" - if [ -n "${post}" ]; then - gurl="gopher://gopherddit.com/1/cgi-bin/reddit.cgi?view&${post}&${subreddit}&10" - else - gurl="gopher://gopherddit.com/1/cgi-bin/reddit.cgi?menu&${subreddit}&10" - fi - annna-say -c '#bitreich-en' "old.reddit: ${nurl} ; gopherddit: ${gurl} ; content: ${purl}" - else - annna-say -c '#bitreich-en' "old.reddit: ${nurl} ; content: ${purl}" - fi + annna-say -c "${channel}" "gopherpedia: ${nurl} ; content: ${purl}" # Hack, Hack, Hack. wikipedia=1 - ;; - *) - spurl="" - ;; - esac - - if [ $wikipedia -eq 0 ]; - then - purl="$(9 htmlfmt < "${tmpf}" | /br/bin/bitreich-paste)" - if [ -n "${spurl}" ]; - then - annna-say -c "#bitreich-en" "content: ${purl} ; screen: ${spurl} ; HTML title: ${urititle}" + fi + ;; + *www.reddit.com*) + nurl="$(printf '%s\n' "${uri}" | sed "s;www.reddit.com;old.reddit.com;")" + purl="$(9 htmlfmt < "${tmpf}" | /br/bin/bitreich-paste)" + if [ -n "${uri#*www.reddit.com/r/*}" ]; then + subreddit="$(printf '%s\n' "${uri}" | cut -d / -f 5)" + post="$(printf '%s\n' "${uri}" | cut -d / -f 7)" + if [ -n "${post}" ]; then + gurl="gopher://gopherddit.com/1/cgi-bin/reddit.cgi?view&${post}&${subreddit}&10" else - annna-say -c "#bitreich-en" "content: ${purl} ; HTML title: ${urititle}" + gurl="gopher://gopherddit.com/1/cgi-bin/reddit.cgi?menu&${subreddit}&10" fi + annna-say -c "${channel}" "old.reddit: ${nurl} ; gopherddit: ${gurl} ; content: ${purl}" + else + annna-say -c "${channel}" "old.reddit: ${nurl} ; content: ${purl}" + fi + # Hack, Hack, Hack. + wikipedia=1 + ;; + *) + spurl="" + ;; + esac + + if [ $wikipedia -eq 0 ]; + then + purl="$(9 htmlfmt < "${tmpf}" | /br/bin/bitreich-paste)" + if [ -n "${spurl}" ]; + then + annna-say -c "${channel}" "content: ${purl} ; screen: ${spurl} ; HTML title: ${urititle}" + else + annna-say -c "${channel}" "content: ${purl} ; HTML title: ${urititle}" fi fi - ;; - esac - fi - rm -f "${tmpf}" - continue + fi + ;; + esac fi + rm -f "${tmpf}" + return + fi + ;; + esac + + case "${text}" in + "${botname}, what is "*) + word="$(printf "%s\n" "${text}" | cut -c 16-)" + case "$word" in + *\?) + word="$(printf "%s\n" "${word}" | cut -c -"$(($(expr length "${word}") - 1))")" ;; esac - case "${text}" in - "${botname}, what is "*) - word="$(printf "%s\n" "${text}" | cut -c 16-)" - case "$word" in - *\?) - word="$(printf "%s\n" "${word}" | cut -c -"$(($(expr length "${word}") - 1))")" - ;; - esac - - purl="" + purl="" + dresult="$(dict "dict://parazyd.org/d:${word}")" + derr=$? + if [ $derr -eq 20 ]; + then dresult="$(dict "dict://parazyd.org/d:${word}")" - derr=$? - if [ $derr -eq 20 ]; - then - dresult="$(dict "dict://parazyd.org/d:${word}")" - derr2="$?" - [ $derr2 -ne $derr ] && derr=$derr2 - fi - case "$derr" in - 0|21) - purl="$(printf "%s" "${dresult}" | /br/bin/bitreich-paste)" - ;; - 20) - purl="No matches found." - ;; - 1) - purl="Parse error." + derr2="$?" + [ $derr2 -ne $derr ] && derr=$derr2 + fi + case "$derr" in + 0|21) + purl="$(printf "%s" "${dresult}" | /br/bin/bitreich-paste)" + ;; + 20) + purl="No matches found." + ;; + 1) + purl="Parse error." + ;; + *) + purl="Parazyd destroyed the server. Nothing to see here." + ;; + esac + annna-say -c "${channel}" "${purl}" + ;; + "${botname}, wolfram is "*) + word="$(printf "%s\n" "${text}" | cut -c 19- | sed 's,\t, ,g')" + case "$word" in + *\?) + word="$(printf "%s\n" "${word}" | cut -c -"$(($(expr length "${word}") - 1))")" + ;; + esac + + purl="" + dresult="$(printf "/wolfram\t%s\r\n" "${word}" \ + | nc magical.fish 70 \ + | awk '/iAnswer:/,/iAsk/' \ + | grep -v '^i ' \ + | head -n -1 \ + | tail -n +2 \ + | sed 's,i\(.*\)fake\texample.com.*,\1,;s,[ \t]*$,,')" + + + if [ -n "$dresult" ]; + then + case "${dresult}" in + b*) + dresult="$(printf "%s\n" "${dresult}" \ + | tr '\n' ' ' \ + | sed "s,^b',,;s,' $,," \ + | sed 's,^b",,;s," $,,' \ + | sed 's,\\n,\n,g;s,\\t,\t,g')" ;; *) - purl="Parazyd destroyed the server. Nothing to see here." + dresult="$(printf "%s\n" "${dresult}" \ + | sed 's,\([a-zA-Z]\)$,\1 ,' \ + | tr -d '\n')" ;; esac - annna-say -c '#bitreich-en' "${purl}" - ;; - "${botname}, wolfram is "*) - word="$(printf "%s\n" "${text}" | cut -c 19- | sed 's,\t, ,g')" - case "$word" in - *\?) - word="$(printf "%s\n" "${word}" | cut -c -"$(($(expr length "${word}") - 1))")" - ;; - esac - - purl="" - dresult="$(printf "/wolfram\t%s\r\n" "${word}" \ - | nc magical.fish 70 \ - | awk '/iAnswer:/,/iAsk/' \ - | grep -v '^i ' \ - | head -n -1 \ - | tail -n +2 \ - | sed 's,i\(.*\)fake\texample.com.*,\1,;s,[ \t]*$,,')" + wcl="$(printf "%s" "${dresult}" | wc -l)" - if [ -n "$dresult" ]; + if [ $wcl -gt 1 ]; then - case "${dresult}" in - b*) - dresult="$(printf "%s\n" "${dresult}" \ - | tr '\n' ' ' \ - | sed "s,^b',,;s,' $,," \ - | sed 's,^b",,;s," $,,' \ - | sed 's,\\n,\n,g;s,\\t,\t,g')" - ;; - *) - dresult="$(printf "%s\n" "${dresult}" \ - | sed 's,\([a-zA-Z]\)$,\1 ,' \ - | tr -d '\n')" - ;; - esac - - wcl="$(printf "%s" "${dresult}" | wc -l)" - - if [ $wcl -gt 1 ]; - then - purl="$(printf "%s" "${dresult}" | /br/bin/bitreich-paste)" - else - purl="${dresult}" - fi + purl="$(printf "%s" "${dresult}" | /br/bin/bitreich-paste)" else - purl="No matches found." + purl="${dresult}" fi - annna-say -c '#bitreich-en' "${purl}" - ;; - "${botname}, textsynth is "*) - word="$(printf "%s\n" "${text}" | cut -c 21- | sed 's,\t, ,g')" - case "$word" in - *\?) - word="$(printf "%s\n" "${word}" | cut -c -"$(($(expr length "${word}") - 1))")" - ;; - esac - - # Do in background, because read is very slow. - { - dresult="$(textsynth-complete "${word}")" - if [ -n "${dresult}" ]; - then - purl="$({ - # First the old words. - printf "%s" "${word}"; - # then the generated text. - printf "%s" "${dresult}"; - } | /br/bin/bitreich-paste)" - else - purl="Textsynth did not answer." - fi - annna-say -c '#bitreich-en' "textsynth result: ${purl}" - } & - - ;; - "${botname}, are "*) - case "${text}" in - *" in love?") - words="$(printf "%s\n" "${text}" | sed 's,.*are \(.*\) and \(.*\) in love?,\1 \2,')" - lovedistance="$(printf "%s * 100\n" "$(fstrcmp ${words})" | bc | cut -d'.' -f 1)" - if [ $lovedistance -gt 15 ]; - then - annna-say -c '#bitreich-en' 'Yes!!! Pure <3 <3' - else - annna-say -c '#bitreich-en' "No." - fi - ;; - esac - ;; - esac - - case "${text}" in - "${botname}, please turn on "*) - word="$(printf "%s\n" "${text}" | cut -c 22-)" - annna-say -c '#bitreich-en' "☞ ⏻ ${word}" - ;; - "${botname}, please turn me on.") - annna-say -c '#bitreich-en' "☞ ⏻ ${user}" + else + purl="No matches found." + fi + annna-say -c "${channel}" "${purl}" + ;; + "${botname}, textsynth is "*) + word="$(printf "%s\n" "${text}" | cut -c 21- | sed 's,\t, ,g')" + case "$word" in + *\?) + word="$(printf "%s\n" "${word}" | cut -c -"$(($(expr length "${word}") - 1))")" ;; esac - if [ "${text}" = "${botname}, I'm bored." ]; - then - randomlink="$(/br/bin/bitreich-lawn-random-link)" - linktype="$(printf "%s\n" "${randomlink}" | cut -d '|' -f1 | cut -c2-)" - linktext="$(printf "%s\n" "${randomlink}" | cut -d '|' -f2)" - linksel="$(printf "%s\n" "${randomlink}" | cut -d '|' -f3)" - linkserver="$(printf "%s\n" "${randomlink}" | cut -d '|' -f4)" - linkport="$(printf "%s\n" "${randomlink}" | cut -d '|' -f5 | cut -d']' -f1)" - outtext="$(printf "%s - gopher://%s" "$linktext" "$linkserver")" - if [ "$linkport" != "70" -a "$linkport" != "port" ]; - then - outtext="$(printf "%s:%s" "$outtext" "$linkport")" - fi - if [ -n "$linksel" ]; + # Do in background, because read is very slow. + { + dresult="$(textsynth-complete "${word}")" + if [ -n "${dresult}" ]; then - outtext="$(printf "%s/%s%s" "$outtext" "$linktype" "$linksel")" + purl="$({ + # First the old words. + printf "%s" "${word}"; + # then the generated text. + printf "%s" "${dresult}"; + } | /br/bin/bitreich-paste)" + else + purl="Textsynth did not answer." fi - annna-say -c "#bitreich-en" "$outtext" - fi - - if [ "${text}" = "${botname}, what's up?" ]; - then - newsstr="$(ecl -shell /home/solene/gopher/bin/generator.lisp)" - annna-say -c "#bitreich-en" "$newsstr" - continue; - fi - - if [ "${text}" = "${botname}, I feel sick." ]; - then - newsstr="$(cd /br/gopher/hypochondria && ./hypochondria -s random)" - annna-say -c "#bitreich-en" "You could have ${newsstr}! Be careful!" - continue; - fi + annna-say -c "${channel}" "textsynth result: ${purl}" + } & - if [ "${text}" = "${botname}, oh hai!" ]; - then - annna-say -c "#bitreich-en" "${user}, hai! How is your sex life?" - continue; - fi - - if [ "${text}" = "${botname}, please tech hype me." ]; - then - techstr="$(${modbase}/markov_tech/markov)" - annna-say -c "#bitreich-en" "${techstr}" - continue; - fi - - if [ "${text}" = "${botname}, what's my horoscope?" ]; - then - horostr="$($HOME/scm/bullshit/horoscope)" - annna-say -c "#bitreich-en" "${user}, ${horostr}" - continue; - fi - - if [ "${text}" = "${botname}, what's my future?" ]; - then - purl="$(sacc gopher://parazyd.org/0/tarot.cgi | /br/bin/bitreich-paste)" - annna-say -c "#bitreich-en" "${user}, your future is here: ${purl}" - continue; - fi - - randomtag=0 - if [ "${text}" = "${botname}, please meme meme meme me." ]; - then - randomtag=2 - fi - - if [ "${text}" = "${botname}, what's the wheelchair shooter meme again?" ]; - then - tagname="#scrollby" - tagline="$(printf "%s\n" "$(hashtags)" | grep "^${tagname} ")" - tagname="$(printf "%s\n" "${tagline}" | cut -d ' ' -f 1)" - taguri="$(printf "%s\n" "${tagline}" | cut -d ' ' -f 2-)" - annna-say -c "#bitreich-en" "${tagname}: ${taguri}" - fi - + ;; + "${botname}, are "*) case "${text}" in - *\#nospoil*) - ;; - *\#tag[^a-zA-Z-]*) - randomtag=1 - ;; - *\#tag) - randomtag=1 - ;; - *rfc[0-9]*) - rfcname="$(printf "%s\n" "${text}" | sed 's,.*\(rfc[0-9]*\).*,\1,')" - annna-say -c "#bitreich-en" "${rfcname}: ftp://ftp.rfc-editor.org/in-notes/${rfcname}.txt" - ;; - *RFC[0-9]*) - rfcname="$(printf "%s\n" "${text}" | sed 's,.*\(RFC[0-9]*\).*,\1,' | tr '[A-Z]' '[a-z]')" - annna-say -c "#bitreich-en" "${rfcname}: ftp://ftp.rfc-editor.org/in-notes/${rfcname}.txt" + *" in love?") + words="$(printf "%s\n" "${text}" | sed 's,.*are \(.*\) and \(.*\) in love?,\1 \2,')" + lovedistance="$(printf "%s * 100\n" "$(fstrcmp ${words})" | bc | cut -d'.' -f 1)" + if [ $lovedistance -gt 15 ]; + then + annna-say -c "${channel}" 'Yes!!! Pure <3 <3' + else + annna-say -c "${channel}" "No." + fi ;; esac - - if [ $randomtag -gt 0 ]; - then - while [ $randomtag -gt 0 ]; - do - rtag="$(printf "%s\n" "$(hashtags)" | shuf -n 1)" - tagname="" - taguri="" - for tag in ${rtag}; - do - [ -z "${tagname}" ] && tagname="${tag}" && continue - taguri="${tag}" - done - - annna-say -c "#bitreich-en" "${tagname}: ${taguri}" - - randomtag=$(($randomtag - 1)) - done - else + ;; + esac + + case "${text}" in + "${botname}, please turn on "*) + word="$(printf "%s\n" "${text}" | cut -c 22-)" + annna-say -c "${channel}" "☞ ⏻ ${word}" + ;; + "${botname}, please turn me on.") + annna-say -c "${channel}" "☞ ⏻ ${user}" + ;; + esac + + if [ "${text}" = "${botname}, I'm bored." ]; + then + randomlink="$(/br/bin/bitreich-lawn-random-link)" + linktype="$(printf "%s\n" "${randomlink}" | cut -d '|' -f1 | cut -c2-)" + linktext="$(printf "%s\n" "${randomlink}" | cut -d '|' -f2)" + linksel="$(printf "%s\n" "${randomlink}" | cut -d '|' -f3)" + linkserver="$(printf "%s\n" "${randomlink}" | cut -d '|' -f4)" + linkport="$(printf "%s\n" "${randomlink}" | cut -d '|' -f5 | cut -d']' -f1)" + outtext="$(printf "%s - gopher://%s" "$linktext" "$linkserver")" + if [ "$linkport" != "70" -a "$linkport" != "port" ]; + then + outtext="$(printf "%s:%s" "$outtext" "$linkport")" + fi + if [ -n "$linksel" ]; + then + outtext="$(printf "%s/%s%s" "$outtext" "$linktype" "$linksel")" + fi + annna-say -c "${channel}" "$outtext" + fi + + if [ "${text}" = "${botname}, what's up?" ]; + then + newsstr="$(ecl -shell /home/solene/gopher/bin/generator.lisp)" + annna-say -c "${channel}" "$newsstr" + return + fi + + if [ "${text}" = "${botname}, I feel sick." ]; + then + newsstr="$(cd /br/gopher/hypochondria && ./hypochondria -s random)" + annna-say -c "${channel}" "You could have ${newsstr}! Be careful!" + return + fi + + if [ "${text}" = "${botname}, oh hai!" ]; + then + annna-say -c "${channel}" "${user}, hai! How is your sex life?" + return + fi + + if [ "${text}" = "${botname}, please tech hype me." ]; + then + techstr="$(${modbase}/markov_tech/markov)" + annna-say -c "${channel}" "${techstr}" + return + fi + + if [ "${text}" = "${botname}, what's my horoscope?" ]; + then + horostr="$($HOME/scm/bullshit/horoscope)" + annna-say -c "${channel}" "${user}, ${horostr}" + return + fi + + if [ "${text}" = "${botname}, what's my future?" ]; + then + purl="$(sacc gopher://parazyd.org/0/tarot.cgi | /br/bin/bitreich-paste)" + annna-say -c "${channel}" "${user}, your future is here: ${purl}" + return + fi + + randomtag=0 + if [ "${text}" = "${botname}, please meme meme meme me." ]; + then + randomtag=2 + fi + + if [ "${text}" = "${botname}, what's the wheelchair shooter meme again?" ]; + then + tagname="#scrollby" + tagline="$(printf "%s\n" "$(hashtags)" | grep "^${tagname} ")" + tagname="$(printf "%s\n" "${tagline}" | cut -d ' ' -f 1)" + taguri="$(printf "%s\n" "${tagline}" | cut -d ' ' -f 2-)" + annna-say -c "${channel}" "${tagname}: ${taguri}" + fi + + case "${text}" in + *\#nospoil*) + ;; + *\#tag[^a-zA-Z-]*) + randomtag=1 + ;; + *\#tag) + randomtag=1 + ;; + *rfc[0-9]*) + rfcname="$(printf "%s\n" "${text}" | sed 's,.*\(rfc[0-9]*\).*,\1,')" + annna-say -c "${channel}" "${rfcname}: ftp://ftp.rfc-editor.org/in-notes/${rfcname}.txt" + ;; + *RFC[0-9]*) + rfcname="$(printf "%s\n" "${text}" | sed 's,.*\(RFC[0-9]*\).*,\1,' | tr '[A-Z]' '[a-z]')" + annna-say -c "${channel}" "${rfcname}: ftp://ftp.rfc-editor.org/in-notes/${rfcname}.txt" + ;; + esac + + if [ $randomtag -gt 0 ]; + then + while [ $randomtag -gt 0 ]; + do + rtag="$(printf "%s\n" "$(hashtags)" | shuf -n 1)" tagname="" taguri="" - for tag in $(hashtags); + for tag in ${rtag}; do [ -z "${tagname}" ] && tagname="${tag}" && continue taguri="${tag}" - - case "${text}" in - *\#nospoil*) - break; - ;; - *${tagname}[^a-zA-Z-]*) - annna-say -c "#bitreich-en" "${tagname}: ${taguri}" - break; - ;; - *${tagname}) - annna-say -c "#bitreich-en" "${tagname}: ${taguri}" - break; - ;; - esac - tagname="" done - fi - - if [ "${text}" = "${botname}, how many memes do you know?" ]; - then - annna-say -c "#bitreich-en" "I know $(hashtagcount) memes: gopher://adamsgaard.dk/0/pub/memecount" - continue; - fi - - if [ "${text}" = "${botname}, how many people died of corona?" ]; - then - annna-say -c "#bitreich-en" "${user}, too many. :( Please see yourself: gopher://magical.fish/1/covid" - continue; - fi - - - if [ "${text}" = "${botname}, please show me your memes." ]; - then - purl="$(printf "%s" "$(hashtags)" | /br/bin/bitreich-paste)" - annna-say -c "#bitreich-en" "Here are my memes: ${purl}" - continue; - fi - if [ "${text}" = "${botname}, please distro-hop with me." ]; - then - ndistro="$(curl -s 'https://distrowatch.com/dwres.php?resource=popularity' \ - | grep phr2 \ - | sed 's,.*href="\(.*\)".*,\1,' \ - | sort | uniq | shuf -n 1)" - annna-say -c "#bitreich-en" "How about https://distrowatch.com/${ndistro} ?" - continue; - fi + annna-say -c "${channel}" "${tagname}: ${taguri}" - ismember=0 - for member in $brmembers; - do - [ "$user" = "$member" ] && ismember=1 + randomtag=$(($randomtag - 1)) done - [ $ismember -lt 1 ] && continue - - if [ "${text}" = "${botname}, be cool." ]; - then - case "$(($RANDOM % 4))" in - 0) - annna-say -c "#bitreich-en" "(⌐■_■)" - ;; - 1) - annna-say -c "#bitreich-en" "(▰˘◡˘▰)" - ;; - 2) - annna-say -c "#bitreich-en" "(▀ Ĺ▀ )̄" - ;; - *) - annna-say -c "#bitreich-en" "(▀Ĺ▀ )" - ;; - esac - continue; - fi - - if [ "${text}" = "${botname}, please cheer." ]; - then - case "$(($RANDOM % 2))" in - 0) - annna-say -c "#bitreich-en" '~\o/~' - ;; - *) - annna-say -c "#bitreich-en" '✺◟( ° ʖ °)◞✺' - ;; - esac - continue; - fi + else + tagname="" + taguri="" + for tag in $(hashtags); + do + [ -z "${tagname}" ] && tagname="${tag}" && continue + taguri="${tag}" - if [ "${text}" = "${botname}, be cute." ]; - then - case "$(($RANDOM % 4))" in - 0) - annna-say -c "#bitreich-en" ' (\ /)' - sleep 0.1 - annna-say -c "#bitreich-en" ' (. .)' - sleep 0.1 - annna-say -c "#bitreich-en" ' C(") (")' - ;; - 1) - annna-say -c "#bitreich-en" ' (\-/)' - sleep 0.1 - annna-say -c "#bitreich-en" " (='.'=)" - sleep 0.1 - annna-say -c "#bitreich-en" ' (")-(")o' + case "${text}" in + *\#nospoil*) + break; ;; - 2) - annna-say -c "#bitreich-en" ' ( ) ( )' - sleep 0.1 - annna-say -c "#bitreich-en" ' (>•.•<)' - sleep 0.1 - annna-say -c "#bitreich-en" ' (") (")' + *${tagname}[^a-zA-Z-]*) + annna-say -c "${channel}" "${tagname}: ${taguri}" + break; ;; - *) - annna-say -c "#bitreich-en" ' (\ (\' - sleep 0.1 - annna-say -c "#bitreich-en" " (=' :')" - sleep 0.1 - annna-say -c "#bitreich-en" ' (, (") (")' + *${tagname}) + annna-say -c "${channel}" "${tagname}: ${taguri}" + break; ;; esac - continue; - fi - - if [ "${text}" = "${botname}, can you show me the uptime please?" ]; - then - annna-say -c "#bitreich-en" "$(hostname) uptime: $(uptime)" - continue; - fi - - if [ "${text}" = "${botname}, please show me the load." ]; - then - annna-say -c "#bitreich-en" "$(hostname) load: $(LANG=C uptime | sed 's,.*load average: \(.*\)$,\1,')" - continue; - fi - - if [ "${text}" = "${botname}, please show me your Macron." ]; - then - annna-say -c "#bitreich-en" "gopher://bitreich.org/0/ascii/macron.vt" - continue; - fi - - if [ "${text}" = "${botname}, please give me the count of online users." ]; - then - annna-say -c "#bitreich-en" "$(hostname): $(who -q | tail -n 1 | cut -d'=' -f 2)" - continue; - fi + tagname="" + done + fi + + if [ "${text}" = "${botname}, how many memes do you know?" ]; + then + annna-say -c "${channel}" "I know $(hashtagcount) memes: gopher://adamsgaard.dk/0/pub/memecount" + return + fi + + if [ "${text}" = "${botname}, how many people died of corona?" ]; + then + annna-say -c "${channel}" "${user}, too many. :( Please see yourself: gopher://magical.fish/1/covid" + return + fi + + + if [ "${text}" = "${botname}, please show me your memes." ]; + then + purl="$(printf "%s" "$(hashtags)" | /br/bin/bitreich-paste)" + annna-say -c "${channel}" "Here are my memes: ${purl}" + return + fi + + if [ "${text}" = "${botname}, please distro-hop with me." ]; + then + ndistro="$(curl -s 'https://distrowatch.com/dwres.php?resource=popularity' \ + | grep phr2 \ + | sed 's,.*href="\(.*\)".*,\1,' \ + | sort | uniq | shuf -n 1)" + annna-say -c "${channel}" "How about https://distrowatch.com/${ndistro} ?" + return + fi + + ismember=0 + for member in $brmembers; + do + [ "$user" = "$member" ] && ismember=1 + done + [ $ismember -lt 1 ] && return - if [ "${text}" = "${botname}, please roll a dice for me." ]; - then - annna-say -c "#bitreich-en" "$((($RANDOM % 6) + 1))" - continue; + if [ "${text}" = "${botname}, be cool." ]; + then + case "$(($RANDOM % 4))" in + 0) + annna-say -c "${channel}" "(⌐■_■)" + ;; + 1) + annna-say -c "${channel}" "(▰˘◡˘▰)" + ;; + 2) + annna-say -c "${channel}" "(▀ Ĺ▀ )̄" + ;; + *) + annna-say -c "${channel}" "(▀Ĺ▀ )" + ;; + esac + return + fi + + if [ "${text}" = "${botname}, please cheer." ]; + then + case "$(($RANDOM % 2))" in + 0) + annna-say -c "${channel}" '~\o/~' + ;; + *) + annna-say -c "${channel}" '✺◟( ° ʖ °)◞✺' + ;; + esac + return + fi + + if [ "${text}" = "${botname}, be cute." ]; + then + case "$(($RANDOM % 4))" in + 0) + annna-say -c "${channel}" ' (\ /)' + sleep 0.1 + annna-say -c "${channel}" ' (. .)' + sleep 0.1 + annna-say -c "${channel}" ' C(") (")' + ;; + 1) + annna-say -c "${channel}" ' (\-/)' + sleep 0.1 + annna-say -c "${channel}" " (='.'=)" + sleep 0.1 + annna-say -c "${channel}" ' (")-(")o' + ;; + 2) + annna-say -c "${channel}" ' ( ) ( )' + sleep 0.1 + annna-say -c "${channel}" ' (>•.•<)' + sleep 0.1 + annna-say -c "${channel}" ' (") (")' + ;; + *) + annna-say -c "${channel}" ' (\ (\' + sleep 0.1 + annna-say -c "${channel}" " (=' :')" + sleep 0.1 + annna-say -c "${channel}" ' (, (") (")' + ;; + esac + return + fi + + if [ "${text}" = "${botname}, can you show me the uptime please?" ]; + then + annna-say -c "${channel}" "$(hostname) uptime: $(uptime)" + return + fi + + if [ "${text}" = "${botname}, please show me the load." ]; + then + annna-say -c "${channel}" "$(hostname) load: $(LANG=C uptime | sed 's,.*load average: \(.*\)$,\1,')" + return + fi + + if [ "${text}" = "${botname}, please show me your Macron." ]; + then + annna-say -c "${channel}" "gopher://bitreich.org/0/ascii/macron.vt" + return + fi + + if [ "${text}" = "${botname}, please give me the count of online users." ]; + then + annna-say -c "${channel}" "$(hostname): $(who -q | tail -n 1 | cut -d'=' -f 2)" + return + fi + + if [ "${text}" = "${botname}, please roll a dice for me." ]; + then + annna-say -c "${channel}" "$((($RANDOM % 6) + 1))" + return + fi + + if [ "${text}" = "${botname}, please tell me your favourite flower." ]; + then + annna-say -c "${channel}" "My favourite flower is the beer flower." + return + fi + + if [ "${text}" = "${botname}, please tell me your favourite color." ]; + then + annna-say -c "${channel}" "My favourite color is yellow." + return + fi + + if [ "${text}" = "${botname}, please dance." ]; + then + if [ $(($RANDOM % 2)) -gt 0 ]; + then + annna-say -c "${channel}" ',o/ o/_ _\o _o_ \o\' + else + annna-say -c "${channel}" '\o7 -o7 _o7 .o7 \o. \o_ \o- \o7' fi + return + fi - if [ "${text}" = "${botname}, please tell me your favourite flower." ]; + if [ "${text}" = "${botname}, please dance with me." ]; + then + if [ $(($RANDOM % 2)) -gt 0 ]; then - annna-say -c "#bitreich-en" "My favourite flower is the beer flower." - continue; - fi + annna-say -c "${channel}" "I am not that kind of woman." + else + annna-say -c "${channel}" "Thank you! Let us dance! :-D" + fi + return + fi + + if [ "${text}" = "${botname}, please tell me who is your favourite pleasure man." ]; + then + annna-say -c "${channel}" "My favourite pleasure man is of course Gunther!" + return + fi + + if [ "${text}" = "${botname}, sudo make me a sandwich" ]; + then + annna-say -c "${channel}" "Humans are no objects." + return + fi + + if [ "${text}" = "${botname}, sudo please make me a sandwich" ]; + then + annna-say -c "${channel}" "Here is your sandwich." + return + fi + + if [ "${text}" = "${botname}, please update the phlog index." ]; + then + phlog-index > /dev/null 2>&1 + annna-say -c "${channel}" "Thanks! Your request has been fulfilled with the quickness! :)" + return + fi + + if [ "${text}" = "${botname}, bonjour !" ]; + then + annna-say -c "${channel}" "${user}, bonjour !" + return + fi + + if [ "${text}" = "${botname}, please help." ]; + then + # TODO: Add multiple line support to annna-say -c(1) with sleep. + annna-say -c "${user}" "»how many memes do you know?«gets you the number of memes annna knows, ${user}." + sleep 0.5 + annna-say -c "${user}" "»please show me your memes.« gets you all memes anna knows, ${user}." + sleep 0.5 + annna-say -c "${user}" "»can you show me the uptime please?« gets you the uptime, ${user}." + sleep 0.5 + annna-say -c "${user}" "»please show me the load, ${user}." + sleep 0.5 + annna-say -c "${user}" "»please give me the count of online users.«, ${user}." + sleep 0.5 + annna-say -c "${user}" "»please tell me your favourite flower.«, ${user}." + sleep 0.5 + annna-say -c "${user}" "»please tell me your favourite color.«, ${user}." + sleep 0.5 + annna-say -c "${user}" "»please dance with me.«, ${user}." + sleep 0.5 + annna-say -c "${user}" "»please distro-hop with me.«, ${user}." + sleep 0.5 + annna-say -c "${user}" "»please dance.«, ${user}." + sleep 0.5 + annna-say -c "${user}" "»what's up?«, ${user}." + sleep 0.5 + annna-say -c "${user}" "»please update the phlog index.«, ${user}." + sleep 0.5 + annna-say -c "${user}" "»sudo make me a sandwich«, ${user}." + sleep 0.5 + annna-say -c "${user}" "»sudo please make me a sandwich«, ${user}." + sleep 0.5 + annna-say -c "${user}" "»please tell me who is your favourite pleasure man.«, ${user}." + sleep 0.5 + annna-say -c "${user}" "»please roll a dice for me.«, ${user}." + sleep 0.5 + annna-say -c "${user}" "»I'm bored.«, ${user}." + sleep 0.5 + annna-say -c "${user}" "», be cool.«, ${user}." + sleep 0.5 + annna-say -c "${user}" "», be cute.«, ${user}." + sleep 0.5 + annna-say -c "${user}" "», what is \$term?«, ${user}." + sleep 0.5 + annna-say -c "${user}" "», please turn on \$term«, ${user}." + sleep 0.5 + annna-say -c "${user}" "», turn me on." + sleep 0.5 + annna-say -c "${user}" "», please tech hype me." + sleep 0.5 + annna-say -c "${user}" "», bonjour !" + sleep 0.5 + annna-say -c "${user}" "»please help.« gives you this help listing, ${user}." + return + fi +} - if [ "${text}" = "${botname}, please tell me your favourite color." ]; - then - annna-say -c "#bitreich-en" "My favourite color is yellow." - continue; - fi +# Permissions +[ -d ${iiroot} ] && chmod o+rx ${iiroot} +[ -d ${iibase} ] && chmod o+rx ${iibase} - if [ "${text}" = "${botname}, please dance." ]; - then - if [ $(($RANDOM % 2)) -gt 0 ]; - then - annna-say -c "#bitreich-en" ',o/ o/_ _\o _o_ \o\' - else - annna-say -c "#bitreich-en" '\o7 -o7 _o7 .o7 \o. \o_ \o- \o7' - fi - continue; - fi +# All channels only requiring annna_common. +common_channels="#bitreich-en #bitreich-fr #bitreich-de #bitreich-nl #bitreich-it #bitreich-con #bitreich-scm #bitreich-cooking #bitreich-lawn #bitreich-tv" +for chan in $common_channels; +do + [ -d "${iibase}/${chan}" ] \ + && chmod o+rx "${iibase}/${chan}" + [ -p "${iibase}/${chan}/in" ] \ + && chmod o+w "${iibase}/${chan}/in" +done + +# Channels with extra features or external scripts. +## SCM (/scm/post-receive) +## This one is handled by common_channels. - if [ "${text}" = "${botname}, please dance with me." ]; - then - if [ $(($RANDOM % 2)) -gt 0 ]; - then - annna-say -c "#bitreich-en" "I am not that kind of woman." - else - annna-say -c "#bitreich-en" "Thank you! Let us dance! :-D" - fi - - continue; - fi +## Radio (/br/radio/playlist.sh + this script) +[ -d "${iibase}/#bitreich-radio" ] \ + && chmod o+rx "${iibase}/#bitreich-radio" +[ -p "${iibase}/#bitreich-radio/in" ] \ + && chmod o+w "${iibase}/#bitreich-radio/in" - if [ "${text}" = "${botname}, please tell me who is your favourite pleasure man." ]; - then - annna-say -c "#bitreich-en" "My favourite pleasure man is of course Gunther!" - continue; - fi - if [ "${text}" = "${botname}, sudo make me a sandwich" ]; - then - annna-say -c "#bitreich-en" "Humans are no objects." - continue; - fi +# Channel handlers. - if [ "${text}" = "${botname}, sudo please make me a sandwich" ]; - then - annna-say -c "#bitreich-en" "Here is your sandwich." - continue; - fi +## Special handlers first. +if [ -f "${iibase}/#bitreich-radio/out" ]; +then +{ + channel="#bitreich-radio" + ls "${iibase}/${channel}/out" | entr tail -n 1 "${iibase}/${channel}/out" \ + | grep -v --line-buffered '[0-9]* -!- ' \ + | sed -u 's,[0-9]* <\([^ >]*\)> \(.*\),\1\n\2,' \ + | { + while read -r user; + do + read -r text - if [ "${text}" = "${botname}, please update the phlog index." ]; - then - phlog-index > /dev/null 2>&1 - annna-say -c "#bitreich-en" "Thanks! Your request has been fulfilled with the quickness! :)" - continue; - fi + [ "$user" = "${botname}" ] && continue - if [ "${text}" = "${botname}, bonjour !" ]; + if [ "${text}" = "${botname}, next please." ]; then - annna-say -c "#bitreich-en" "${user}, bonjour !" + /br/bin/bitreich-radio-playlist-next + annna-say -c "${channel}" "You are very kind ${user}. To your command." continue; fi if [ "${text}" = "${botname}, please help." ]; then - # TODO: Add multiple line support to annna-say -c(1) with sleep. - annna-say -c "${user}" "»how many memes do you know?«gets you the number of memes annna knows, ${user}." - sleep 0.5 - annna-say -c "${user}" "»please show me your memes.« gets you all memes anna knows, ${user}." - sleep 0.5 - annna-say -c "${user}" "»can you show me the uptime please?« gets you the uptime, ${user}." - sleep 0.5 - annna-say -c "${user}" "»please show me the load, ${user}." - sleep 0.5 - annna-say -c "${user}" "»please give me the count of online users.«, ${user}." - sleep 0.5 - annna-say -c "${user}" "»please tell me your favourite flower.«, ${user}." - sleep 0.5 - annna-say -c "${user}" "»please tell me your favourite color.«, ${user}." - sleep 0.5 - annna-say -c "${user}" "»please dance with me.«, ${user}." - sleep 0.5 - annna-say -c "${user}" "»please distro-hop with me.«, ${user}." - sleep 0.5 - annna-say -c "${user}" "»please dance.«, ${user}." - sleep 0.5 - annna-say -c "${user}" "»what's up?«, ${user}." - sleep 0.5 - annna-say -c "${user}" "»please update the phlog index.«, ${user}." - sleep 0.5 - annna-say -c "${user}" "»sudo make me a sandwich«, ${user}." - sleep 0.5 - annna-say -c "${user}" "»sudo please make me a sandwich«, ${user}." - sleep 0.5 - annna-say -c "${user}" "»please tell me who is your favourite pleasure man.«, ${user}." - sleep 0.5 - annna-say -c "${user}" "»please roll a dice for me.«, ${user}." - sleep 0.5 - annna-say -c "${user}" "»I'm bored.«, ${user}." - sleep 0.5 - annna-say -c "${user}" "», be cool.«, ${user}." - sleep 0.5 - annna-say -c "${user}" "», be cute.«, ${user}." - sleep 0.5 - annna-say -c "${user}" "», what is \$term?«, ${user}." - sleep 0.5 - annna-say -c "${user}" "», please turn on \$term«, ${user}." - sleep 0.5 - annna-say -c "${user}" "», turn me on." - sleep 0.5 - annna-say -c "${user}" "», please tech hype me." - sleep 0.5 - annna-say -c "${user}" "», bonjour !" - sleep 0.5 + annna-say -c "${user}" "»next please.« gets the playlist further, ${user}." annna-say -c "${user}" "»please help.« gives you this help listing, ${user}." + + # Give out common help too. + annna_common "${channel}" "${user}" "${text}" continue; fi + + # Allow common functions too. + annna_common "${channel}" "${user}" "${text}" done } } & fi +## Common channel handler. +for channel in $common_channels; +do + if [ -f "${iibase}/${channel}/out" ]; + then + { + ls "${iibase}/${channel}/out" | entr tail -n 1 "${iibase}/${channel}/out" \ + | grep -v --line-buffered '[0-9]* -!- ' \ + | sed -u 's,[0-9]* <\([^ >]*\)> \(.*\),\1\n\2,' \ + | { + while read -r user; + do + read -r text + + annna_common "${channel}" "${user}" "${text}" + done + } + } & + fi +done +