IT'S NEW, IT'S FANCY, IT'S SHELL SCRIPTS!
What a load of bash.
This commit is contained in:
parent
8c76a757aa
commit
77560dbdc6
10 changed files with 235 additions and 0 deletions
2
happybot/act-ignore.txt
Normal file
2
happybot/act-ignore.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
time
|
||||
tz
|
55
happybot/act.sh
Normal file
55
happybot/act.sh
Normal file
|
@ -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;
|
67
happybot/common.sh
Normal file
67
happybot/common.sh
Normal file
|
@ -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/^[^<]*<//' | 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';
|
||||
}
|
35
happybot/frog.sh
Normal file
35
happybot/frog.sh
Normal file
|
@ -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;
|
9
happybot/happy.sh
Normal file
9
happybot/happy.sh
Normal file
|
@ -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;
|
24
happybot/ichi.py
Normal file
24
happybot/ichi.py
Normal file
|
@ -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)
|
9
happybot/ichi.sh
Normal file
9
happybot/ichi.sh
Normal file
|
@ -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;
|
14
happybot/ok.sh
Normal file
14
happybot/ok.sh
Normal file
|
@ -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;
|
11
happybot/react.sh
Normal file
11
happybot/react.sh
Normal file
|
@ -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;
|
9
happybot/zwsp.sh
Normal file
9
happybot/zwsp.sh
Normal file
|
@ -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;
|
Loading…
Reference in a new issue