diff --git a/bot.sh b/bot.sh index ddef92e..f04399c 100755 --- a/bot.sh +++ b/bot.sh @@ -1,4 +1,5 @@ # !/bin/bash +# @author Dimitar Dimitrov . bot.properties config=".bot.cfg" @@ -7,18 +8,41 @@ echo "USER $user" >> $config echo "JOIN #$channel" >> $config tail -f $config | telnet $server 6667 | while read res; do -# do things when you see output case "$res" in PING*) echo "$res" | sed "s/PING/PONG/" >> $config ;; -# for pings on nick/user *"You have not"*) echo "JOIN #$channel" >> $config ;; *JOIN*) - whojoin=$(echo "$res" | sed -r "s/:(.*)\!.*@.*/\1/") - echo "PRIVMSG #$channel :Welcome $whojoin :)" >> $config + who=$(echo "$res" | sed -r "s/:(.*)\!.*@.*/\1/") + if [ "$who" = "$nick" ] + then + continue + fi + echo "PRIVMSG #$channel :Welcome $who" >> $config + ;; + *PRIVMSG*) + echo "$res" + who=$(echo "$res" | sed -r "s/:(.*)\!.*@.*/\1/") + from=$(echo "$res" | sed -r "s/.*PRIVMSG ([#]?[a-zA-Z]*) :.*/\1/") + # "#" would mean it's a channel + if [ "$(echo "$from" | grep '#')" ] + then + test "$(echo "$res" | grep ":$nick:")" || continue + will=$(echo "$res" | sed -r "s/.*:$nick:(.*)/\1/") + else + will=$(echo "$res" | sed -r "s/.*$nick :(.*)/\1/") + from=$who + fi + com=$(echo "$will" | grep -Eio "[a-z]*" | head -n1 | tail -n1) + if [ -z "$(ls modules/ | grep -i -- "$com.sh")" ] + then + ./modules/help.sh $who $from >> $config + continue + fi + ./modules/$com.sh $who $from $(echo "$will" | tail -n+1) >> $config ;; *) echo "$res" diff --git a/modules/help.sh b/modules/help.sh new file mode 100755 index 0000000..24ce9da --- /dev/null +++ b/modules/help.sh @@ -0,0 +1,3 @@ +echo "PRIVMSG $2 :$1: The available modules I have are:" +output=$(ls modules/ | sed "s/.sh//") +echo "PRIVMSG $2 :$1: "$output diff --git a/modules/ping.sh b/modules/ping.sh new file mode 100755 index 0000000..efe5990 --- /dev/null +++ b/modules/ping.sh @@ -0,0 +1 @@ +echo "PRIVMSG $2 :$1: pong" diff --git a/modules/test.sh b/modules/test.sh new file mode 100755 index 0000000..dc5c77b --- /dev/null +++ b/modules/test.sh @@ -0,0 +1 @@ +echo "PRIVMSG $2 :$1: The test was successful"