First pass at link announcing.

This commit is contained in:
Storm Dragon 2016-09-04 17:22:05 -04:00
parent 4f525e713f
commit 3fcf1c280f
4 changed files with 25 additions and 5 deletions

View File

@ -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"

16
bot.sh
View File

@ -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

View File

@ -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"

10
triggers/link/link.sh Executable file
View File

@ -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 "<title>" | sed 's#\(</\|</\)title>##g')"
shortLink="${l#*://}"
shortLink="${shortLink%%/*}"
msg "$2" "$pageTitle at $shortLink"
fi
done