Cleaning up code, added triggers, The bot now greets people when they enter the room.

This commit is contained in:
Storm Dragon 2016-09-03 01:38:30 -04:00
parent b5b5dc1d10
commit ed0fbcb89b
4 changed files with 23 additions and 5 deletions

6
bot.sh
View File

@ -33,7 +33,7 @@ do
continue continue
fi fi
echo "MODE #$channel +o $who" >> $input echo "MODE #$channel +o $who" >> $input
[ -e greeting.txt ] && msg "$chan" "$who: $(shuf -n1 greeting.txt)" ./triggers/greet/greet.sh $who $chan
;; ;;
# run when a message is seen # run when a message is seen
*PRIVMSG*) *PRIVMSG*)
@ -53,10 +53,10 @@ do
com=$(echo "$will" | cut -d " " -f1) com=$(echo "$will" | cut -d " " -f1)
if [ -z "$(ls modules/ | grep -i -- "$com")" ] || [ -z "$com" ] if [ -z "$(ls modules/ | grep -i -- "$com")" ] || [ -z "$com" ]
then then
./modules/help/help.sh $who $from >> $input ./modules/help/help.sh $who $from
continue continue
fi fi
./modules/$com/$com.sh $who $from $(echo "$will" | cut -d " " -f2-99) >> $input ./modules/$com/$com.sh $who $from $(echo "$will" | cut -d " " -f2-99)
;; ;;
*) *)
echo "$res" echo "$res"

View File

@ -1,9 +1,13 @@
#!/bin/bash #!/bin/bash
if [ -z "$input" ]; then
input=".bot.cfg"
fi
msg() msg()
{ {
local msg="PRIVMSG $1" local msg="PRIVMSG $1"
shift shift
echo "$msg $@" | tee -a "$log" echo "$msg $@" | tee -a "$input"
} }

View File

@ -1 +0,0 @@
welcome to $channel

15
triggers/greet/greet.sh Executable file
View File

@ -0,0 +1,15 @@
[ -f functions.sh ] && source functions.sh
# All names to match are completely lowercase.
case "${1,,}" in
storm_dragon)
msg "$2" "my lord, $1: how may I serve you?"
;;
*)
greeting=(
Greetings
Howdy
"Wazzup Moe Fugger!"
Welcome
)
msg "$2" "$1: ${greeting[$(($RANDOM % ${#greeting[@]}))]}"
esac