diff --git a/bot.properties b/bot.properties index 99fba9a..9ff6ddd 100644 --- a/bot.properties +++ b/bot.properties @@ -14,4 +14,6 @@ nick="storm_bot" port=6667 server="irc.netwirc.tk" # format=username hostname servername :realname +# Triggers, symbols, that when starting a message, will cause the bot to search modules. +triggers="," user="$nick ${server%.} $server :$nick" diff --git a/bot.sh b/bot.sh index 6893334..a4cb721 100755 --- a/bot.sh +++ b/bot.sh @@ -25,7 +25,7 @@ do echo "JOIN #$channel" >> $input ;; # run when someone joins - *JOIN*) + *"JOIN #"*) who=$(echo "$res" | perl -pe "s/:(.*)\!.*@.*/\1/") chan="$(echo "$res" | cut -d '#' -f2)" chan="#$chan" @@ -33,7 +33,7 @@ do continue fi echo "MODE #$channel +o $who" >> $input - [ "${greet,,}" = "true" ] && ./triggers/greet/greet.sh $who $chan + [ "${greet^^}" = "TRUE" ] && ./triggers/greet/greet.sh $who $chan ;; # run when someone leaves *"PART #"*) @@ -44,7 +44,7 @@ do continue fi echo "MODE #$channel +o $who" >> $input - [ "${leave,,}" = "TRUE" ] && ./triggers/bye/bye.sh $who $chan + [ "${leave^^}" = "TRUE" ] && ./triggers/bye/bye.sh $who $chan ;; # run when a message is seen *PRIVMSG*) @@ -54,7 +54,15 @@ do # 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 - msg "$from" "This contains a url. Unfortunately my master is being lazy and hasn't made a url parser, so I can't tell you where it goes." + ./triggers/link/link.sh "$who" "$from" "$res" + # Although this calls modules, it triggers on text other than the bot's nick + elif [[ "$res" =~ .*$from\ :$who:$triggers.* ]]; then + com"${res#*$from :$who:$triggers}" + 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#* }" fi # "#" would mean it's a channel if [ "$(echo "$from" | grep '#')" ]; then diff --git a/modules/help/help.sh b/modules/help/help.sh index b3a7eee..9356a6e 100755 --- a/modules/help/help.sh +++ b/modules/help/help.sh @@ -1,4 +1,4 @@ [ -f functions.sh ] && source functions.sh output="$1: The modules I have are:" -output="$output $(find modules/ -type d | tr '[:space:]' ' ' | sed -e 's#modules/##g')" +output="$output $(find modules/ -type d | sort -d | tr '[:space:]' ' ' | sed -e 's#modules/##g')" msg "$2" "$output" diff --git a/triggers/link/link.sh b/triggers/link/link.sh new file mode 100755 index 0000000..802fe1d --- /dev/null +++ b/triggers/link/link.sh @@ -0,0 +1,10 @@ +[ -f functions.sh ] && source functions.sh + +for l in $3 ; do +if [[ "$l" =~ http://|https://|www\.* ]]; then +pageTitle="$(curl -s "$l" | grep "