2013-07-19 12:53:40 -04:00
|
|
|
#!/bin/bash
|
2013-07-16 18:19:17 -04:00
|
|
|
|
2016-09-02 12:51:56 -04:00
|
|
|
msg()
|
|
|
|
{
|
|
|
|
local msg="PRIVMSG $1:"
|
|
|
|
shift
|
|
|
|
echo "$msg $@" | tee -a "$log"
|
|
|
|
}
|
|
|
|
|
2016-09-02 10:58:05 -04:00
|
|
|
[ -f bot.properties ] && source bot.properties
|
2013-07-19 12:53:40 -04:00
|
|
|
input=".bot.cfg"
|
2016-09-02 12:51:56 -04:00
|
|
|
echo "Starting session: $(date "+[%y:%m:%d %T]")" | tee $log
|
2013-07-19 12:53:40 -04:00
|
|
|
echo "NICK $nick" > $input
|
|
|
|
echo "USER $user" >> $input
|
2016-09-02 10:58:05 -04:00
|
|
|
for c in ${channel[@]} ; do
|
|
|
|
echo "JOIN #$c" | tee -a $input
|
|
|
|
done
|
2013-07-16 18:19:17 -04:00
|
|
|
|
2016-09-02 10:58:05 -04:00
|
|
|
tail -f $input | telnet $server $port | while read res
|
2013-07-16 21:17:56 -04:00
|
|
|
do
|
2013-07-22 13:29:05 -04:00
|
|
|
# log the session
|
2016-09-02 12:51:56 -04:00
|
|
|
echo "$(date "+[%y:%m:%d %T]")$res" | tee -a $log
|
2013-07-16 21:17:56 -04:00
|
|
|
# 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
|
2016-09-02 12:51:56 -04:00
|
|
|
*JOIN*)
|
|
|
|
who=$(echo "$res" | perl -pe "s/:(.*)\!.*@.*/\1/")
|
|
|
|
chan="$(echo "$res" | cut -d '#' -f2)"
|
|
|
|
chan="#$chan"
|
|
|
|
if [ "$who" = "$nick" ]; then
|
2013-07-17 16:06:37 -04:00
|
|
|
continue
|
|
|
|
fi
|
2013-07-19 12:53:40 -04:00
|
|
|
echo "MODE #$channel +o $who" >> $input
|
2016-09-02 12:51:56 -04:00
|
|
|
[ -e greeting.txt ] && msg $chan $who: $(shuf -n1 greeting.txt)
|
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
|
2013-07-22 12:16:31 -04:00
|
|
|
will=$(echo "$will" | perl -pe "s/^ //")
|
|
|
|
com=$(echo "$will" | cut -d " " -f1)
|
2013-10-18 11:04:46 -04:00
|
|
|
if [ -z "$(ls modules/ | grep -i -- "$com")" ] || [ -z "$com" ]
|
2013-07-17 16:06:37 -04:00
|
|
|
then
|
2013-07-23 10:33:40 -04:00
|
|
|
./modules/help/help.sh $who $from >> $input
|
2013-07-17 16:06:37 -04:00
|
|
|
continue
|
|
|
|
fi
|
2013-07-22 13:37:13 -04:00
|
|
|
./modules/$com/$com.sh $who $from $(echo "$will" | cut -d " " -f2-99) >> $input
|
2013-07-16 18:19:17 -04:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "$res"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|