From 3fcf1c280f0175cf2cd28bd5b757d05f7651fddf Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Sun, 4 Sep 2016 17:22:05 -0400 Subject: [PATCH] First pass at link announcing. --- bot.properties | 2 ++ bot.sh | 16 ++++++++++++---- modules/help/help.sh | 2 +- triggers/link/link.sh | 10 ++++++++++ 4 files changed, 25 insertions(+), 5 deletions(-) create mode 100755 triggers/link/link.sh 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 "" | sed 's#\(</\|</\)title>##g')" +shortLink="${l#*://}" +shortLink="${shortLink%%/*}" +msg "$2" "$pageTitle at $shortLink" +fi +done