2010-12-15 22:36:16 -07:00
|
|
|
|
#! /bin/sh
|
|
|
|
|
|
2011-01-10 15:18:34 -07:00
|
|
|
|
prefix=$1; export prefix; shift
|
2011-01-06 21:08:21 -07:00
|
|
|
|
command=$1; export command; shift
|
2010-12-15 22:36:16 -07:00
|
|
|
|
sender=$1; export sender; shift
|
|
|
|
|
forum=$1; export forum; shift
|
2011-01-06 21:08:21 -07:00
|
|
|
|
text=$1; export text; shift
|
2010-12-15 22:36:16 -07:00
|
|
|
|
# $* is now args
|
2011-01-06 21:08:21 -07:00
|
|
|
|
|
|
|
|
|
# Debug output
|
2011-06-09 21:27:24 -06:00
|
|
|
|
#echo '>>>' ${prefix:+:}$prefix $command "$@" ${text:+:}"$text" 1>&2
|
2011-01-06 21:08:21 -07:00
|
|
|
|
|
|
|
|
|
raw () {
|
|
|
|
|
fmt="\007$1\n"; shift
|
|
|
|
|
printf "$fmt" "$@"
|
|
|
|
|
}
|
2010-12-15 22:36:16 -07:00
|
|
|
|
|
2010-12-16 21:29:52 -07:00
|
|
|
|
join () {
|
2011-01-06 21:08:21 -07:00
|
|
|
|
raw "JOIN $1"
|
2010-12-16 21:29:52 -07:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-28 13:09:55 -07:00
|
|
|
|
out=$(tempfile)
|
|
|
|
|
|
2010-12-15 22:36:16 -07:00
|
|
|
|
case $command in
|
|
|
|
|
001)
|
2011-06-09 21:27:24 -06:00
|
|
|
|
for i in $botdir/channels/*; do
|
|
|
|
|
join $(basename $i)
|
2011-01-07 15:38:20 -07:00
|
|
|
|
done
|
2011-01-06 21:08:21 -07:00
|
|
|
|
;;
|
|
|
|
|
433)
|
2011-06-09 21:27:24 -06:00
|
|
|
|
raw "NICK bot_$(shuf -c 1 /usr/share/dict/words)"
|
2010-12-15 22:36:16 -07:00
|
|
|
|
;;
|
|
|
|
|
PRIVMSG)
|
2010-12-16 21:13:34 -07:00
|
|
|
|
case "$forum" in
|
2010-12-16 21:29:52 -07:00
|
|
|
|
\#*)
|
2011-06-09 21:27:24 -06:00
|
|
|
|
$ircdir/firebot "$text" || \
|
|
|
|
|
$ircdir/whuffie $botdir/whuffie.cdb "$text" || \
|
|
|
|
|
$ircdir/infobot $botdir/factoids.cdb "$text"
|
2010-12-16 21:13:34 -07:00
|
|
|
|
;;
|
|
|
|
|
esac
|
2011-06-09 21:27:24 -06:00
|
|
|
|
$ircdir/notes $botdir/notes "$text"
|
2010-12-15 22:36:16 -07:00
|
|
|
|
;;
|
|
|
|
|
INVITE)
|
2010-12-16 21:29:52 -07:00
|
|
|
|
join "$forum"
|
2011-01-06 21:08:21 -07:00
|
|
|
|
raw "PRIVMSG %s :Thanks for the invitation, %s." "$forum" "$sender"
|
2011-06-09 21:27:24 -06:00
|
|
|
|
touch $botdir/channels/$forum
|
2010-12-15 22:36:16 -07:00
|
|
|
|
;;
|
2011-01-28 13:09:55 -07:00
|
|
|
|
esac > $out
|
|
|
|
|
|
|
|
|
|
if [ "$forum" != "$sender" ] && [ $(wc -l < $out) -gt 5 ]; then
|
|
|
|
|
printf "PRIVMSG %s :Too many lines, sending privately.\r\n" "$forum"
|
|
|
|
|
forum=$sender
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
while read -r line; do
|
2011-01-06 21:08:21 -07:00
|
|
|
|
case "$line" in
|
|
|
|
|
*)
|
|
|
|
|
printf "%s\r\n" "${line#}"
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
printf "PRIVMSG %s :%s\r\n" "$forum" "$line"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2011-01-28 13:09:55 -07:00
|
|
|
|
done < $out
|
|
|
|
|
|
|
|
|
|
rm -f $out
|
2010-12-15 22:36:16 -07:00
|
|
|
|
|