happybot/happybot/act.sh

56 lines
1.4 KiB
Bash

#!/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;