Cleaned up the code a bit, the formatting at least, there's plenty more to do.
This commit is contained in:
parent
273e24a63a
commit
5984a2dbb2
56
bot.sh
56
bot.sh
@ -1,15 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$(whoami)" = "root" ]; then
|
||||
echo "This bot should not be ran as root."
|
||||
exit 1
|
||||
echo "This bot should not be ran as root."
|
||||
exit 1
|
||||
fi
|
||||
[ -f functions.sh ] && source functions.sh
|
||||
[ -f bot.cfg ] && source bot.cfg
|
||||
input=".botinput"
|
||||
|
||||
close_bot()
|
||||
{
|
||||
close_bot() {
|
||||
echo -en "QUIT :$quitMessage\r\n" >> "$input"
|
||||
rm "$input"
|
||||
exit 0
|
||||
@ -22,8 +21,7 @@ echo "NICK $nick" > "$input"
|
||||
echo "USER $user" >> "$input"
|
||||
echo "JOIN #$channel" >> "$input"
|
||||
|
||||
tail -f "$input" | telnet "$server" "$port" | while read result
|
||||
do
|
||||
tail -f "$input" | telnet "$server" "$port" | while read -r result ; do
|
||||
# log the session
|
||||
echo "$(date "+[$dateFormat]") $result" >> "$log"
|
||||
# do things when you see output
|
||||
@ -60,9 +58,9 @@ do
|
||||
fi
|
||||
echo "MODE #$channel +o $who" | tee -a "$input"
|
||||
if [ "${greet^^}" = "TRUE" ]; then
|
||||
set -f
|
||||
./triggers/greet/greet.sh "$who" "$from"
|
||||
set +f
|
||||
set -f
|
||||
./triggers/greet/greet.sh "$who" "$from"
|
||||
set +f
|
||||
fi
|
||||
;;
|
||||
# run when someone leaves
|
||||
@ -75,9 +73,9 @@ set +f
|
||||
continue
|
||||
fi
|
||||
if [ "${leave^^}" = "TRUE" ]; then
|
||||
set -f
|
||||
./triggers/bye/bye.sh "$who" "$from"
|
||||
set +f
|
||||
set -f
|
||||
./triggers/bye/bye.sh "$who" "$from"
|
||||
set +f
|
||||
fi
|
||||
;;
|
||||
# run when a message is seen
|
||||
@ -102,23 +100,23 @@ set +f
|
||||
will="${command#* }"
|
||||
command="${command%% *}"
|
||||
if command -v "./modules/${command% *}/${command% *}.sh" ; then
|
||||
echo "Calling module ./modules/${command% *}/${command% *}/${command% *}.sh \"$who\" \"$from\" $will" >> "$log"
|
||||
# Disable wildcards
|
||||
set -f
|
||||
./modules/${command% *}/${command% *}.sh "$who" "$from" $will
|
||||
# Enable wildcards
|
||||
set +f
|
||||
else
|
||||
./modules/say/say.sh "$who" "$from" "$who: $(shuf -n1 "response/error.txt")"
|
||||
fi
|
||||
echo "Calling module ./modules/${command% *}/${command% *}/${command% *}.sh \"$who\" \"$from\" $will" >> "$log"
|
||||
# Disable wildcards
|
||||
set -f
|
||||
./modules/${command% *}/${command% *}.sh "$who" "$from" $will
|
||||
# Enable wildcards
|
||||
set +f
|
||||
else
|
||||
set -f
|
||||
./modules/say/say.sh "$who" "$from" "$who: $(shuf -n1 "response/error.txt")"
|
||||
fi
|
||||
else
|
||||
set -f
|
||||
./triggers/keywords/keywords.sh "$who" "$from" "$result"
|
||||
set +f
|
||||
fi
|
||||
# "#" would mean it's a channel
|
||||
if [ "$(echo "$from" | grep '#')" ]; then
|
||||
test "$(echo "$result" | grep ":$nick:")" || continue
|
||||
[[ "$(echo "$result" | grep ":$nick:")" ]] || continue
|
||||
will="${result#*#*:}"
|
||||
will="${will#*:}"
|
||||
else
|
||||
@ -133,14 +131,14 @@ set -f
|
||||
command="${will%% *}"
|
||||
will="${will#* }"
|
||||
if [ -z "$(ls modules/ | grep -i -- "$command")" ] || [ -z "$command" ]; then
|
||||
set -f
|
||||
./modules/help/help.sh "$who" "$from"
|
||||
set +f
|
||||
set -f
|
||||
./modules/help/help.sh "$who" "$from"
|
||||
set +f
|
||||
continue
|
||||
fi
|
||||
set -f
|
||||
./modules/$command/$command.sh "$who" "$from" $will
|
||||
set +f
|
||||
set -f
|
||||
./modules/$command/$command.sh "$who" "$from" $will
|
||||
set +f
|
||||
;;
|
||||
*)
|
||||
echo "$result" >> "$log"
|
||||
|
Loading…
x
Reference in New Issue
Block a user