2013-07-19 12:53:40 -04:00
|
|
|
#!/bin/bash
|
2013-07-16 18:19:17 -04:00
|
|
|
|
2017-04-05 19:00:57 -04:00
|
|
|
if [ "$(whoami)" = "root" ]; then
|
|
|
|
echo "This bot should not be ran as root."
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-09-03 00:14:12 -04:00
|
|
|
[ -f functions.sh ] && source functions.sh
|
2016-09-06 12:08:29 -04:00
|
|
|
[ -f bot.cfg ] && source bot.cfg
|
2016-09-05 21:44:04 -04:00
|
|
|
input=".botinput"
|
|
|
|
|
|
|
|
close_bot()
|
|
|
|
{
|
2016-09-06 22:35:15 -04:00
|
|
|
echo -en "QUIT :$quitMessage\r\n" >> "$input"
|
2016-09-06 10:55:35 -04:00
|
|
|
rm "$input"
|
|
|
|
exit 0
|
2016-09-05 21:44:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
trap close_bot EXIT $?
|
|
|
|
|
2016-09-06 22:35:15 -04:00
|
|
|
echo "Session started $(date "+%I:%M%p%n %A, %B %d, %Y")" | tee "$log"
|
|
|
|
echo "NICK $nick" | tee "$input"
|
|
|
|
echo "USER $user" | tee -a "$input"
|
2016-09-02 10:58:05 -04:00
|
|
|
for c in ${channel[@]} ; do
|
2016-09-06 22:35:15 -04:00
|
|
|
echo "JOIN #$c" | tee -a "$input"
|
|
|
|
sleep 0.5
|
2016-09-02 10:58:05 -04:00
|
|
|
done
|
2013-07-16 18:19:17 -04:00
|
|
|
|
2016-09-06 22:35:15 -04:00
|
|
|
tail -f "$input" | telnet "$server" "$port" | while read result
|
2013-07-16 21:17:56 -04:00
|
|
|
do
|
2013-07-22 13:29:05 -04:00
|
|
|
# log the session
|
2016-09-06 22:35:15 -04:00
|
|
|
echo "$(date "+[$dateFormat]") $result" | tee -a "$log"
|
2013-07-16 21:17:56 -04:00
|
|
|
# do things when you see output
|
2016-09-06 22:35:15 -04:00
|
|
|
case "$result" 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*)
|
2016-09-06 22:35:15 -04:00
|
|
|
echo "$result" | tee -a "$log"
|
|
|
|
echo "${result/I/O}" | tee -a "$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"*)
|
2016-09-06 22:35:15 -04:00
|
|
|
echo "JOIN #$channel" | tee -a "$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-06 22:35:15 -04:00
|
|
|
who="${result%%!*}"
|
|
|
|
who="${who:1}"
|
|
|
|
from="${result#*#}"
|
|
|
|
from="#$from"
|
2016-09-02 12:51:56 -04:00
|
|
|
if [ "$who" = "$nick" ]; then
|
2013-07-17 16:06:37 -04:00
|
|
|
continue
|
|
|
|
fi
|
2016-09-06 22:35:15 -04:00
|
|
|
echo "MODE #$channel +o $who" | tee -a "$input"
|
2016-09-04 20:51:49 -04:00
|
|
|
if [ "${greet^^}" = "TRUE" ]; then
|
2017-04-02 10:41:28 -04:00
|
|
|
set -f
|
|
|
|
./triggers/greet/greet.sh "$who" "$from"
|
|
|
|
set +f
|
2016-09-04 20:51:49 -04:00
|
|
|
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-06 22:35:15 -04:00
|
|
|
who="${result%%!*}"
|
|
|
|
who="${who:1}"
|
|
|
|
from="${result#*#}"
|
|
|
|
from="#$from"
|
2016-09-04 12:43:22 -04:00
|
|
|
if [ "$who" = "$nick" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
2016-09-04 20:51:49 -04:00
|
|
|
if [ "${leave^^}" = "TRUE" ]; then
|
2017-04-02 10:41:28 -04:00
|
|
|
set -f
|
|
|
|
./triggers/bye/bye.sh "$who" "$from"
|
|
|
|
set +f
|
2016-09-04 20:51:49 -04:00
|
|
|
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*)
|
2016-09-06 22:35:15 -04:00
|
|
|
echo "$result" | tee -a "$log"
|
|
|
|
who="${result%%!*}"
|
|
|
|
who="${who:1}"
|
|
|
|
from="${result#*#}"
|
|
|
|
from="#${from%% *}"
|
|
|
|
# Trigger stuff happens here.
|
2016-09-04 12:43:22 -04:00
|
|
|
# Call link trigger if msg contains a link:
|
2016-09-06 22:35:15 -04:00
|
|
|
if [[ "$result" =~ .*http://|https://|www\..* ]]; then
|
|
|
|
./triggers/link/link.sh "$who" "$from" "$result"
|
2016-09-04 17:22:05 -04:00
|
|
|
# Although this calls modules, it triggers on text other than the bot's nick
|
2016-09-06 22:35:15 -04:00
|
|
|
elif [[ "$result" =~ ^.*PRIVMSG.*:[[:punct:]].* ]]; then
|
|
|
|
command="${result#*:[[:punct:]]}"
|
|
|
|
command="${command//# /}"
|
|
|
|
will="${command#* }"
|
|
|
|
command="${command%% *}"
|
|
|
|
if [ -z "$(ls modules/ | grep -i -- "$command")" ] || [ -z "$command" ]; then
|
2016-09-04 17:22:05 -04:00
|
|
|
continue
|
|
|
|
fi
|
2017-04-02 10:41:28 -04:00
|
|
|
# Disable wildcards
|
|
|
|
set -f
|
|
|
|
./modules/${command% *}/${command% *}.sh "$who" "$from" $will
|
|
|
|
# Enable wildcards
|
|
|
|
set +f
|
2016-09-06 14:25:46 -04:00
|
|
|
else
|
2017-04-02 10:41:28 -04:00
|
|
|
set -f
|
2016-09-06 22:35:15 -04:00
|
|
|
./triggers/keywords/keywords.sh "$who" "$from" "$result"
|
2017-04-02 10:41:28 -04:00
|
|
|
set +f
|
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
|
2016-09-06 22:35:15 -04:00
|
|
|
test "$(echo "$result" | grep ":$nick:")" || continue
|
2016-09-07 08:35:19 -04:00
|
|
|
will="${result#*#*:}"
|
|
|
|
will="${will#*:}"
|
2013-07-17 16:06:37 -04:00
|
|
|
else
|
2016-09-07 08:35:19 -04:00
|
|
|
will="${result:1}"
|
|
|
|
will="${will#* :}"
|
2016-09-07 10:06:14 -04:00
|
|
|
from="$who"
|
2013-07-17 16:06:37 -04:00
|
|
|
fi
|
2016-09-07 08:35:19 -04:00
|
|
|
# Had to turn on globbing to remove all leading whitespace, then turn it off again afterwards.
|
|
|
|
shopt -s extglob
|
|
|
|
will="${will##*( )}"
|
|
|
|
shopt -u extglob
|
2016-09-07 10:06:14 -04:00
|
|
|
command="${will%% *}"
|
2016-09-06 22:35:15 -04:00
|
|
|
will="${will#* }"
|
2016-09-07 08:35:19 -04:00
|
|
|
if [ -z "$(ls modules/ | grep -i -- "$command")" ] || [ -z "$command" ]; then
|
2017-04-02 10:41:28 -04:00
|
|
|
set -f
|
|
|
|
./modules/help/help.sh "$who" "$from"
|
|
|
|
set +f
|
2013-07-17 16:06:37 -04:00
|
|
|
continue
|
|
|
|
fi
|
2017-04-02 10:41:28 -04:00
|
|
|
set -f
|
|
|
|
./modules/$command/$command.sh "$who" "$from" $will
|
|
|
|
set +f
|
2013-07-16 18:19:17 -04:00
|
|
|
;;
|
|
|
|
*)
|
2016-09-07 08:39:08 -04:00
|
|
|
echo "$result" | tee -a "$log"
|
2013-07-16 18:19:17 -04:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|