Refactor annna text command matches. - 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 c3d834f28259c7860e41365fb87cfcc3777cf973 DIR parent af34952c8eec82a609f56229c0a6ff6d2db2895b HTML Author: Annna Robert-Houdin <annna@bitreich.org> Date: Fri, 5 Jun 2020 20:38:13 +0200 Refactor annna text command matches. Move some member commands which do not harm to non-member context. Diffstat: M annna-start-services | 410 ++++++++++++------------------- 1 file changed, 159 insertions(+), 251 deletions(-) --- DIR diff --git a/annna-start-services b/annna-start-services @@ -267,9 +267,6 @@ annna_common() { ;; esac ;; - esac - - case "${text}" in "Ok, ${botname}"*) annna-say -c "${channel}" "${user}, I am not a consumer device." ;; @@ -287,10 +284,7 @@ annna_common() { "${botname}, please turn me on.") annna-say -c "${channel}" "☞ ⏻ ${user}" ;; - esac - - if [ "${text}" = "${botname}, I'm bored." ]; - then + "${botname}, I'm bored") 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)" @@ -307,182 +301,60 @@ annna_common() { outtext="$(printf "%s/%s%s" "$outtext" "$linktype" "$linksel")" fi annna-say -c "${channel}" "$outtext" - fi - - if [ "${text}" = "${botname}, wb." ]; - then + ;; + "${botname}, wb.") annna-say -c "${channel}" "${user}, ty! I am so happy to be here. :)" - return - fi - - if [ "${text}" = "${botname}, welcome back." ]; - then + ;; + "${botname}, welcome back.") annna-say -c "${channel}" "${user}, thank you! I am so happy to be here. :)" - return - fi - - if [ "${text}" = "${botname}, what's up?" ]; - then + ;; + "${botname}, what's up?") newsstr="$(ecl -shell /home/solene/gopher/bin/generator.lisp)" annna-say -c "${channel}" "$newsstr" - return - fi - - if [ "${text}" = "${botname}, what's down?" ]; - then + ;; + "${botname}, what's down?") annna-say -c "${channel}" "${user}, we all love you." - return - fi - - if [ "${text}" = "${botname}, I feel sick." ]; - then + ;; + "${botname}, I feel sick.") 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 + ;; + "${botname}, oh hai!") annna-say -c "${channel}" "${user}, hai! How is your sex life?" - return - fi - - if [ "${text}" = "${botname}, please tech hype me." ]; - then + ;; + "${botname}, please tech hype me.") techstr="$(${modbase}/markov_tech/markov)" annna-say -c "${channel}" "${techstr}" - return - fi - - if [ "${text}" = "${botname}, what's my horoscope?" ]; - then + ;; + "${botname}, what's my horoscope?") horostr="$($HOME/scm/bullshit/horoscope)" annna-say -c "${channel}" "${user}, ${horostr}" - return - fi - - if [ "${text}" = "${botname}, what's my future?" ]; - then + ;; + "${botname}, what's my future?") 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 ${rtag}; - do - [ -z "${tagname}" ] && tagname="${tag}" && continue - taguri="${tag}" - done - - annna-say -c "${channel}" "${tagname}: ${taguri}" - - randomtag=$(($randomtag - 1)) - done - else - tagname="" - taguri="" - for tag in $(hashtags); - do - [ -z "${tagname}" ] && tagname="${tag}" && continue - taguri="${tag}" - - case "${text}" in - *\#nospoil*) - break; - ;; - *${tagname}[^a-zA-Z-]*) - annna-say -c "${channel}" "${tagname}: ${taguri}" - break; - ;; - *${tagname}) - annna-say -c "${channel}" "${tagname}: ${taguri}" - break; - ;; - esac - tagname="" - done - fi - - if [ "${text}" = "${botname}, how many memes do you know?" ]; - then + "${botname}, how many memes do you know?") 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 + ;; + "${botname}, how many people died of corona?") 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 + ;; + "${botname}, please show me your memes.") 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 + ;; + "${botname}, please distro-hop with me.") 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}, be cool." ]; - then + ;; + "${botname}, please show me your Macron.") + annna-say -c "${channel}" "gopher://bitreich.org/0/ascii/macron.vt" + ;; + "${botname}, be cool.") case "$(($RANDOM % 4))" in 0) annna-say -c "${channel}" "(⌐■_■)" @@ -497,11 +369,8 @@ annna_common() { annna-say -c "${channel}" "(▀Ĺ▀ )" ;; esac - return - fi - - if [ "${text}" = "${botname}, please cheer." ]; - then + ;; + "${botname}, please cheer.") case "$(($RANDOM % 2))" in 0) annna-say -c "${channel}" '~\o/~' @@ -510,11 +379,8 @@ annna_common() { annna-say -c "${channel}" '✺◟( ° ʖ °)◞✺' ;; esac - return - fi - - if [ "${text}" = "${botname}, be cute." ]; - then + ;; + "${botname}, be cute.") case "$(($RANDOM % 4))" in 0) annna-say -c "${channel}" ' (\ /)' @@ -545,106 +411,46 @@ annna_common() { 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 + ;; + "${botname}, please roll a dice for me.") annna-say -c "${channel}" "$((($RANDOM % 6) + 1))" - return - fi - - if [ "${text}" = "${botname}, please tell me your favourite flower." ]; - then + ;; + "${botname}, please tell me your favourite flower.") annna-say -c "${channel}" "My favourite flower is the beer flower." - return - fi - - if [ "${text}" = "${botname}, please tell me your favourite color." ]; - then + ;; + "${botname}, please tell me your favourite color.") annna-say -c "${channel}" "My favourite color is yellow." - return - fi - - if [ "${text}" = "${botname}, please dance." ]; - then + ;; + "${botname}, please dance.") 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 dance with me." ]; - then + ;; + "${botname}, please dance with me.") if [ $(($RANDOM % 2)) -gt 0 ]; then 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 + ;; + "${botname}, please tell me who is your favourite pleasure man.") annna-say -c "${channel}" "My favourite pleasure man is of course Gunther!" - return - fi - - if [ "${text}" = "${botname}, sudo make me a sandwich" ]; - then + ;; + "${botname}, sudo make me a sandwich") annna-say -c "${channel}" "Humans are no objects." - return - fi - - if [ "${text}" = "${botname}, sudo please make me a sandwich" ]; - then + ;; + "${botname}, sudo please make me a sandwich") 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 + ;; + "${botname}, bonjour !") annna-say -c "${channel}" "${user}, bonjour !" - return - fi - - if [ "${text}" = "${botname}, please help." ]; - then + ;; + "${botname}, please help.") + # Help Message. # 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 @@ -699,8 +505,110 @@ annna_common() { annna-say -c "${user}" "», bonjour !" sleep 0.5 annna-say -c "${user}" "»please help.« gives you this help listing, ${user}." - return + ;; + esac + + 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 ${rtag}; + do + [ -z "${tagname}" ] && tagname="${tag}" && continue + taguri="${tag}" + done + + annna-say -c "${channel}" "${tagname}: ${taguri}" + + randomtag=$(($randomtag - 1)) + done + else + tagname="" + taguri="" + for tag in $(hashtags); + do + [ -z "${tagname}" ] && tagname="${tag}" && continue + taguri="${tag}" + + case "${text}" in + *\#nospoil*) + break; + ;; + *${tagname}[^a-zA-Z-]*) + annna-say -c "${channel}" "${tagname}: ${taguri}" + break; + ;; + *${tagname}) + annna-say -c "${channel}" "${tagname}: ${taguri}" + break; + ;; + esac + tagname="" + done fi + + # Membership Level. + ismember=0 + for member in $brmembers; + do + [ "$user" = "$member" ] && ismember=1 + done + [ $ismember -lt 1 ] && return + + + case "${text}" in + "${botname}, can you show me the uptime please?") + annna-say -c "${channel}" "$(hostname) uptime: $(uptime)" + ;; + "${botname}, please show me the load.") + annna-say -c "${channel}" "$(hostname) load: $(LANG=C uptime | sed 's,.*load average: \(.*\)$,\1,')" + ;; + "${botname}, please give me the count of online users.") + annna-say -c "${channel}" "$(hostname): $(who -q | tail -n 1 | cut -d'=' -f 2)" + ;; + "${botname}, please update the phlog index.") + phlog-index > /dev/null 2>&1 + annna-say -c "${channel}" "Thanks! Your request has been fulfilled with the quickness! :)" + ;; + esac + } # Permissions