stormbot/bot.sh

58 lines
1.5 KiB
Bash
Raw Normal View History

2013-07-16 18:19:17 -04:00
# !/bin/bash
# @author Dimitar Dimitrov
2013-07-16 18:19:17 -04:00
. bot.properties
config=".bot.cfg"
echo "NICK $nick" > $config
echo "USER $user" >> $config
echo "JOIN #$channel" >> $config
2013-07-17 16:11:00 -04:00
tail -f $config | telnet $server 6667 | while read res
2013-07-16 21:17:56 -04:00
do
# do things when you see output
2013-07-16 18:19:17 -04:00
case "$res" in
2013-07-17 16:11:00 -04:00
# respond to ping requests from the server
2013-07-16 18:19:17 -04:00
PING*)
echo "$res" | sed "s/PING/PONG/" >> $config
;;
2013-07-16 21:17:56 -04:00
# for pings on nick/user
2013-07-16 18:19:17 -04:00
*"You have not"*)
echo "JOIN #$channel" >> $config
;;
2013-07-17 16:11:00 -04:00
# run when someone joins
2013-07-16 18:19:17 -04:00
*JOIN*)
who=$(echo "$res" | sed -r "s/:(.*)\!.*@.*/\1/")
if [ "$who" = "$nick" ]
then
continue
fi
2013-07-17 16:11:00 -04:00
echo "MODE #$channel +o $who" >> $config
;;
2013-07-17 16:11:00 -04:00
# run when a message is seen
*PRIVMSG*)
echo "$res"
who=$(echo "$res" | sed -r "s/:(.*)\!.*@.*/\1/")
from=$(echo "$res" | sed -r "s/.*PRIVMSG ([#]?([a-zA-Z]|\-)*) :.*/\1/")
# "#" would mean it's a channel
if [ "$(echo "$from" | grep '#')" ]
then
test "$(echo "$res" | grep ":$nick:")" || continue
will=$(echo "$res" | sed -r "s/.*:$nick:(.*)/\1/")
else
will=$(echo "$res" | sed -r "s/.*$nick :(.*)/\1/")
from=$who
fi
com=$(echo "$will" | grep -Eio "[a-z]*" | head -n1 | tail -n1)
if [ -z "$(ls modules/ | grep -i -- "$com.sh")" ]
then
./modules/help.sh $who $from >> $config
continue
fi
./modules/$com.sh $who $from $(echo "$will" | tail -n+1) >> $config
2013-07-16 18:19:17 -04:00
;;
*)
echo "$res"
;;
esac
done