diff --git a/happybot/act-ignore.txt b/happybot/act-ignore.txt new file mode 100644 index 0000000..fed3023 --- /dev/null +++ b/happybot/act-ignore.txt @@ -0,0 +1,2 @@ +time +tz diff --git a/happybot/act.sh b/happybot/act.sh new file mode 100644 index 0000000..2539224 --- /dev/null +++ b/happybot/act.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env ash + +. /home/zgrep/offtopiabday/happybot/common.sh + +irc | while read -r n m; do + m=$(var "$m" | sed 's/[^][A-Za-z0-9\\\-{}^|_` ]//g'); + var "$m"; + if reg '^(?:[hH][aA][pP][pP][yY]|[hH][aA][tT][eE])[bB][oO][tT] (\S+) (\S+)$' "$m" && ! grep -Fxq -- "$(m 1 | tr 'A-Z' 'a-z')" happybot/act-ignore.txt; then + echo "$n requested that I do '$(m 1)' to '$(m 2)'."; + a=$(var "$(m 1)" | tr 'A-Z' 'a-z' | sed 's/[^a-z ]//g') + if [ -z "$a" ]; then + var "$n: You're not using me properly. :(" | zwsp | say; + elif [ "$a" == "zwsp" ]; then + echo "Ignoring zwsp request."; + else + case "$(m 2)" in + "happybot" | "hatebot" | "yourself" | "you" | "thyself" ) + if [ -e /home/zgrep/offtopiabday/hateweekfile ]; then + n="hatebot"; + else + n="happybot"; + fi + ;; + "me") + # Same person. + ;; + "someone" | "anyone" | "anybody" | "somebody") + n="$(person)"; + ;; + "everybody" | "everyone" | "all") + n="$chan" + ;; + "errybody" | "erryone") + n="erry" + ;; + *) + n="$(m 2)"; + ;; + esac; + f="happybot/msgs/$a.sh"; + if [ -e "$f" ]; then + sh happybot/msgs/$a.sh "$n" "$chan" > /tmp/tmpact.txt; + f="/tmp/tmpact.txt"; + else + f="happybot/msgs/$a.txt"; + if [ ! -e "$f" ]; then + f="happybot/msgs/_.txt"; + fi; + fi; + N=$(var "$n" | tr 'a-z' 'A-Z'); + m=$(rand "$f"); m='var "'"$m"'"'; m=$(eval "$m"); + var "$m" | zwsp | say; + fi; + fi; +done; diff --git a/happybot/common.sh b/happybot/common.sh new file mode 100644 index 0000000..475ed06 --- /dev/null +++ b/happybot/common.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env ash + +chan="$1"; +serv="irc.freenode.net"; +cd "/home/zgrep/offtopiabday" || exit 1; + +var() { printf '%s\n' "$1"; } +say() { cat - > "$serv/$chan/in"; } +alias safe="sed 's%^/%//%'" +log="$serv/$chan/out"; + +irc() { + tail -0 -f "$serv/$chan/out" | while read -r l; do + var "$l" | sed 's/^[^<]*//'; + done; +} + +reg() { + r=$(var "$1" | sed 's%/%\\\/%g'); + r=$(var "$2" | perl -ne '@m=m/'"$r"'/ or exit 1;printf join "\n", @m'); +} +hreg() { + reg "$(var "$1" | sed 's/happybot/(?:[hH][aA][pP][pP][yY]|[hH][aA][tT][eE])[bB][oO][tT]/g')" "$2" +} +m() { var "$r" | sed -n "$1p"; } + +zwsp=$(python3 -c 'print("\u200b",end="")'); +zwsp() { cat - | sed 's%^\(/m \)\?%\1'"$zwsp"'%'; } + +nth() { + case "$1" in + "11" | "12" | "13") + var "${1}th"; + ;; + *"1") + var "${1}st"; + ;; + *"2") + var "${1}nd"; + ;; + *"3") + var "${1}rd"; + ;; + *) + var "${1}th"; + ;; + esac; +} + +s() { + if [ "$1" == "1" ]; then + var ""; + else + var "s"; + fi; +} + +ns() { var "$1$(s "$1")"; } + +rand() { + if [ -z "$1" ]; then f="-"; else f="$1"; fi + perl -e 'srand; rand($.) < 1 && ($line = $_) while <>; print $line;' "$f" +} + +person() { + shuf -n100 "$serv/$chan/out" | grep -v -- '-!-' | rand | awk '{print$3}' | sed 's/^<\|>$//g'; +} diff --git a/happybot/frog.sh b/happybot/frog.sh new file mode 100644 index 0000000..84b2a8b --- /dev/null +++ b/happybot/frog.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env ash + +. /home/zgrep/offtopiabday/happybot/common.sh + + +irc | while read -r n m; do +# if reg '^ยก(([RrFf]|[Ss][Pp])[Rr][Oo][Gg]|[Gg][Oo][Rr]([Pp][Ss]|[RrFf]))$' "$m"; then + if reg '^!(([RrFf]|[Ss][Pp])[Rr][Oo][Gg]|[Gg][Oo][Rr]([Pp][Ss]|[RrFf]))$' "$m"; then + l=$(var "$(m 1)" | tr 'A-Z' 'a-z'); + + s=$(var "$(m 1)" | sed 's/[A-Z]/\\U\\#/g' | sed 's/[a-z]/\\L\\#/g'); + s=$(printf '%s' "$s" | tr '#' '\n' | awk '{print$0 NR}' | tr -d '\n'); + p=$(var "$(m 1)" | sed 's/./\\(\.\\)/g'); w=$(var "$(m 1)" | sed 's/./ /g'); + + f=$(curl -s 'https://frog.tips/api/1/tips/' | jq -r '.tips[0].tip'); + + if [ "$l" == "sprog" ] || [ "$l" == "gorps" ]; then + f=$(var "$f" | sed 's/FROG/TADPOLE/g'); + fi; + + rainbow='5 4 7 8 9 3 11 10 12 2 6 13'; + if [ "$l" == "gorf" ] || [ "$l" == "gorr" ] || [ "$l" == "gorps" ]; then + rainbow='13 6 2 12 10 11 3 9 8 7 4 5'; + f=$(var "$f" | rev); + fi; + + f=$(var "$f$w" | sed 's/'"$p"'/'"$s"'/g' | sed 's/ *$//'); + + if [ "$l" == "rrog" ] || [ "$l" == "gorr" ]; then + f=$(var "$f" | awk -v FS="" '{split("'"$rainbow"'",color," ");for (i=1;i<=NF;i++) print "\x03" color[(1+(i-1)%length(color))] $i}' | tr -d '\n'); + fi; + + var "$f" | zwsp | say; + fi; +done; diff --git a/happybot/happy.sh b/happybot/happy.sh new file mode 100644 index 0000000..34364b0 --- /dev/null +++ b/happybot/happy.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env ash + +. /home/zgrep/offtopiabday/happybot/common.sh + +irc | while read -r n m; do + if reg '^(happy|hate)bot[:,] :D$' "$m"; then + echo ":D" | say; + fi; +done; diff --git a/happybot/ichi.py b/happybot/ichi.py new file mode 100644 index 0000000..5f6bdb1 --- /dev/null +++ b/happybot/ichi.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + +import requests as rq +from lxml import html + +from sys import argv +if len(argv) != 2: + print('Not enough arguments. Bug zgrep.') + exit(1) + +q = argv[1] + +r = rq.get('http://ichi.moe/cl/qr/', params={'q': q}) + +if r.status_code != 200: + print('Non-200 status code. Bug zgrep.') + exit() + +# tree +t = html.fromstring(r.content) + +ichi = ''.join(t.xpath('//span[@class="ds-text"]//text()')) + +print(ichi) diff --git a/happybot/ichi.sh b/happybot/ichi.sh new file mode 100644 index 0000000..4c2575d --- /dev/null +++ b/happybot/ichi.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env ash + +. /home/zgrep/offtopiabday/happybot/common.sh + +irc | while read -r n m; do + if reg '^(happy|hate)bot[:,] ichi (.*)' "$m"; then + python3 happybot/ichi.py "$(m 2)" | say; + fi; +done; diff --git a/happybot/ok.sh b/happybot/ok.sh new file mode 100644 index 0000000..56fa70e --- /dev/null +++ b/happybot/ok.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env ash + +. /home/zgrep/offtopiabday/happybot/common.sh + +esc() { echo -n '/s '; cat -; } + +irc | while read -r n m; do + if reg '^[o][kK]: ?(.*)' "$m"; then + var "$(m 1)"; + fi; +done | ok/ircrepl.js | while read -r l; do + var "$l" | zwsp | esc | say; + sleep 0.2; +done; diff --git a/happybot/react.sh b/happybot/react.sh new file mode 100644 index 0000000..28d93b6 --- /dev/null +++ b/happybot/react.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env ash + +. /home/zgrep/offtopiabday/happybot/common.sh + +irc | while read -r n m; do +if reg '^\x01ACTION (.*?)(?:[hH][aA][pP][pP][yY]|[hH][aA][tT][eE])[bB][oO][tT](.*)\x01$' "$m"; then + if [[ "$n" != "happybot" ]] && [[ "$n" != "hatebot" ]]; then + var "/m $(m 1)$n$(m 2)" | say; + fi; +fi; +done; diff --git a/happybot/zwsp.sh b/happybot/zwsp.sh new file mode 100644 index 0000000..1af4a75 --- /dev/null +++ b/happybot/zwsp.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env ash + +. /home/zgrep/offtopiabday/happybot/common.sh + +irc | while read -r n m; do + if reg '^(happy|hate)bot[:,] zwsp' "$m"; then + echo "${zwsp}zero-width space protocol: http://ayu.smar.fi:7070/0/zwsp" | say; + fi; +done;