2013-07-19 12:53:40 -04:00
|
|
|
#!/bin/bash
|
2013-07-16 18:19:17 -04:00
|
|
|
|
|
|
|
. bot.properties
|
2013-07-19 12:53:40 -04:00
|
|
|
input=".bot.cfg"
|
|
|
|
echo "NICK $nick" > $input
|
|
|
|
echo "USER $user" >> $input
|
|
|
|
echo "JOIN #$channel" >> $input
|
2013-07-16 18:19:17 -04:00
|
|
|
|
2013-07-19 12:53:40 -04:00
|
|
|
tail -f $input | 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*)
|
2013-07-19 12:53:40 -04:00
|
|
|
echo "$res" | sed "s/I/O/" >> $input
|
2013-07-16 18:19:17 -04:00
|
|
|
;;
|
2013-07-16 21:17:56 -04:00
|
|
|
# for pings on nick/user
|
2013-07-16 18:19:17 -04:00
|
|
|
*"You have not"*)
|
2013-07-19 12:53:40 -04:00
|
|
|
echo "JOIN #$channel" >> $input
|
2013-07-16 18:19:17 -04:00
|
|
|
;;
|
2013-07-17 16:11:00 -04:00
|
|
|
# run when someone joins
|
2013-07-16 18:19:17 -04:00
|
|
|
*JOIN*)
|
2013-07-19 12:53:40 -04:00
|
|
|
who=$(echo "$res" | perl -pe "s/:(.*)\!.*@.*/\1/")
|
2013-07-17 16:06:37 -04:00
|
|
|
if [ "$who" = "$nick" ]
|
|
|
|
then
|
|
|
|
continue
|
|
|
|
fi
|
2013-07-19 12:53:40 -04:00
|
|
|
echo "MODE #$channel +o $who" >> $input
|
2013-07-17 16:06:37 -04:00
|
|
|
;;
|
2013-07-17 16:11:00 -04:00
|
|
|
# run when a message is seen
|
2013-07-17 16:06:37 -04:00
|
|
|
*PRIVMSG*)
|
|
|
|
echo "$res"
|
2013-07-19 12:53:40 -04:00
|
|
|
who=$(echo "$res" | perl -pe "s/:(.*)\!.*@.*/\1/")
|
|
|
|
from=$(echo "$res" | perl -pe "s/.*PRIVMSG (.*[#]?([a-zA-Z]|\-)*) :.*/\1/")
|
2013-07-17 16:06:37 -04:00
|
|
|
# "#" would mean it's a channel
|
|
|
|
if [ "$(echo "$from" | grep '#')" ]
|
|
|
|
then
|
|
|
|
test "$(echo "$res" | grep ":$nick:")" || continue
|
2013-07-19 12:53:40 -04:00
|
|
|
will=$(echo "$res" | perl -pe "s/.*:$nick:(.*)/\1/")
|
2013-07-17 16:06:37 -04:00
|
|
|
else
|
2013-07-19 12:53:40 -04:00
|
|
|
will=$(echo "$res" | perl -pe "s/.*$nick :(.*)/\1/")
|
2013-07-17 16:06:37 -04:00
|
|
|
from=$who
|
|
|
|
fi
|
|
|
|
com=$(echo "$will" | grep -Eio "[a-z]*" | head -n1 | tail -n1)
|
2013-07-20 00:58:07 -04:00
|
|
|
if [ -z "$(ls modules/*.sh | grep -i -- "$com.sh")" ]
|
2013-07-17 16:06:37 -04:00
|
|
|
then
|
2013-07-19 12:53:40 -04:00
|
|
|
./modules/help.sh $who $from >> $input
|
2013-07-17 16:06:37 -04:00
|
|
|
continue
|
|
|
|
fi
|
2013-07-19 12:53:40 -04:00
|
|
|
./modules/$com.sh $who $from $(echo "$will" | cut -d " " -f3-99) >> $input
|
2013-07-16 18:19:17 -04:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "$res"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|