stormbot/bot.sh

52 lines
1.3 KiB
Bash
Executable File

# !/bin/bash
# @author Dimitar Dimitrov
. bot.properties
config=".bot.cfg"
echo "NICK $nick" > $config
echo "USER $user" >> $config
echo "JOIN #$channel" >> $config
tail -f $config | telnet $server 6667 | while read res; do
case "$res" in
PING*)
echo "$res" | sed "s/PING/PONG/" >> $config
;;
*"You have not"*)
echo "JOIN #$channel" >> $config
;;
*JOIN*)
who=$(echo "$res" | sed -r "s/:(.*)\!.*@.*/\1/")
if [ "$who" = "$nick" ]
then
continue
fi
echo "PRIVMSG #$channel :Welcome $who" >> $config
;;
*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
;;
*)
echo "$res"
;;
esac
done