2013-07-19 12:53:40 -04:00
|
|
|
#!/bin/bash
|
2013-07-16 18:19:17 -04:00
|
|
|
|
2016-09-03 00:14:12 -04:00
|
|
|
[ -f functions.sh ] && source functions.sh
|
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-04 20:51:49 -04:00
|
|
|
*"JOIN :#"*)
|
2016-09-02 12:51:56 -04:00
|
|
|
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-04 20:51:49 -04:00
|
|
|
if [ "${greet^^}" = "TRUE" ]; then
|
|
|
|
./triggers/greet/greet.sh $who $chan
|
|
|
|
fi
|
2013-07-17 16:06:37 -04:00
|
|
|
;;
|
2016-09-04 12:43:22 -04:00
|
|
|
# run when someone leaves
|
2016-09-04 13:15:35 -04:00
|
|
|
*"PART #"*)
|
2016-09-04 12:43:22 -04:00
|
|
|
who=$(echo "$res" | perl -pe "s/:(.*)\!.*@.*/\1/")
|
|
|
|
chan="$(echo "$res" | cut -d '#' -f2)"
|
|
|
|
chan="#$chan"
|
|
|
|
if [ "$who" = "$nick" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
echo "MODE #$channel +o $who" >> $input
|
2016-09-04 20:51:49 -04:00
|
|
|
if [ "${leave^^}" = "TRUE" ]; then
|
|
|
|
./triggers/bye/bye.sh $who $chan
|
|
|
|
fi
|
2016-09-04 12:43:22 -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/")
|
2016-09-04 12:43:22 -04:00
|
|
|
# This looks to be the spot where triggers should be called
|
|
|
|
# Call link trigger if msg contains a link:
|
|
|
|
if [[ "$res" =~ .*http://|https://|www\..* ]]; then
|
2016-09-04 17:22:05 -04:00
|
|
|
./triggers/link/link.sh "$who" "$from" "$res"
|
|
|
|
# Although this calls modules, it triggers on text other than the bot's nick
|
2016-09-04 20:51:49 -04:00
|
|
|
elif [[ "$res" =~ *PRIVMSG\ \#${from#*#}\ :$triggers* ]]; then
|
|
|
|
com"${res#*:$triggers}"
|
|
|
|
com"${com//# /}"
|
2016-09-04 17:22:05 -04:00
|
|
|
if [ -z "$(ls modules/ | grep -i -- "${com%* }")" ] || [ -z "$com" ]; then
|
|
|
|
./modules/help/help.sh $who $from
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
./modules/${com% *}/${com% *}.sh $who $from "${com#* }"
|
2016-09-04 12:43:22 -04:00
|
|
|
fi
|
2013-07-17 16:06:37 -04:00
|
|
|
# "#" would mean it's a channel
|
2016-09-04 12:43:22 -04:00
|
|
|
if [ "$(echo "$from" | grep '#')" ]; then
|
2013-07-17 16:06:37 -04:00
|
|
|
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
|
2016-09-04 20:51:49 -04:00
|
|
|
will=$(echo "$will" | perl -pe "s/^ +//")
|
2013-07-22 12:16:31 -04:00
|
|
|
com=$(echo "$will" | cut -d " " -f1)
|
2016-09-04 12:43:22 -04:00
|
|
|
if [ -z "$(ls modules/ | grep -i -- "$com")" ] || [ -z "$com" ]; then
|
2016-09-03 01:38:30 -04:00
|
|
|
./modules/help/help.sh $who $from
|
2013-07-17 16:06:37 -04:00
|
|
|
continue
|
|
|
|
fi
|
2016-09-03 01:38:30 -04:00
|
|
|
./modules/$com/$com.sh $who $from $(echo "$will" | cut -d " " -f2-99)
|
2013-07-16 18:19:17 -04:00
|
|
|
;;
|
|
|
|
*)
|
2016-09-04 12:43:22 -04:00
|
|
|
chan="$(echo "$res" | cut -d '#' -f2)"
|
|
|
|
chan="#$chan"
|
2013-07-16 18:19:17 -04:00
|
|
|
echo "$res"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|