made it work on mac terms

This commit is contained in:
Dimitar Dimitrov 2013-07-19 17:53:40 +01:00
parent 19181cdfa9
commit 78f02d16dd
2 changed files with 18 additions and 19 deletions

33
bot.sh
View File

@ -1,54 +1,53 @@
# !/bin/bash #!/bin/bash
# @author Dimitar Dimitrov
. bot.properties . bot.properties
config=".bot.cfg" input=".bot.cfg"
echo "NICK $nick" > $config echo "NICK $nick" > $input
echo "USER $user" >> $config echo "USER $user" >> $input
echo "JOIN #$channel" >> $config echo "JOIN #$channel" >> $input
tail -f $config | telnet $server 6667 | while read res tail -f $input | telnet $server 6667 | while read res
do do
# do things when you see output # do things when you see output
case "$res" in case "$res" in
# respond to ping requests from the server # respond to ping requests from the server
PING*) PING*)
echo "$res" | sed "s/PING/PONG/" >> $config echo "$res" | sed "s/I/O/" >> $input
;; ;;
# for pings on nick/user # for pings on nick/user
*"You have not"*) *"You have not"*)
echo "JOIN #$channel" >> $config echo "JOIN #$channel" >> $input
;; ;;
# run when someone joins # run when someone joins
*JOIN*) *JOIN*)
who=$(echo "$res" | sed -r "s/:(.*)\!.*@.*/\1/") who=$(echo "$res" | perl -pe "s/:(.*)\!.*@.*/\1/")
if [ "$who" = "$nick" ] if [ "$who" = "$nick" ]
then then
continue continue
fi fi
echo "MODE #$channel +o $who" >> $config echo "MODE #$channel +o $who" >> $input
;; ;;
# run when a message is seen # run when a message is seen
*PRIVMSG*) *PRIVMSG*)
echo "$res" echo "$res"
who=$(echo "$res" | sed -r "s/:(.*)\!.*@.*/\1/") who=$(echo "$res" | perl -pe "s/:(.*)\!.*@.*/\1/")
from=$(echo "$res" | sed -r "s/.*PRIVMSG ([#]?([a-zA-Z]|\-)*) :.*/\1/") from=$(echo "$res" | perl -pe "s/.*PRIVMSG (.*[#]?([a-zA-Z]|\-)*) :.*/\1/")
# "#" would mean it's a channel # "#" would mean it's a channel
if [ "$(echo "$from" | grep '#')" ] if [ "$(echo "$from" | grep '#')" ]
then then
test "$(echo "$res" | grep ":$nick:")" || continue test "$(echo "$res" | grep ":$nick:")" || continue
will=$(echo "$res" | sed -r "s/.*:$nick:(.*)/\1/") will=$(echo "$res" | perl -pe "s/.*:$nick:(.*)/\1/")
else else
will=$(echo "$res" | sed -r "s/.*$nick :(.*)/\1/") will=$(echo "$res" | perl -pe "s/.*$nick :(.*)/\1/")
from=$who from=$who
fi fi
com=$(echo "$will" | grep -Eio "[a-z]*" | head -n1 | tail -n1) com=$(echo "$will" | grep -Eio "[a-z]*" | head -n1 | tail -n1)
if [ -z "$(ls modules/ | grep -i -- "$com.sh")" ] if [ -z "$(ls modules/ | grep -i -- "$com.sh")" ]
then then
./modules/help.sh $who $from >> $config ./modules/help.sh $who $from >> $input
continue continue
fi fi
./modules/$com.sh $who $from $(echo "$will" | tail -n+1) >> $config ./modules/$com.sh $who $from $(echo "$will" | cut -d " " -f3-99) >> $input
;; ;;
*) *)
echo "$res" echo "$res"

View File

@ -4,7 +4,7 @@
# 2 - scissor # 2 - scissor
m_choice=$(($RANDOM%3)) m_choice=$(($RANDOM%3))
o_choice=$(echo $4 | sed -r "s/^[rR].*/0/" | sed -r "s/^[pP].*/1/" | sed -r "s/^[sS].*/2/") o_choice=$(echo $3 | sed -r "s/^[rR].*/0/" | sed -r "s/^[pP].*/1/" | sed -r "s/^[sS].*/2/")
#convert my random to either r/p/s #convert my random to either r/p/s
case "$m_choice" in case "$m_choice" in
@ -29,4 +29,4 @@ else
outcome="win" outcome="win"
fi fi
echo "PRIVMSG $2 :$1: $4 VS $mr_choice | I $outcome!" echo "PRIVMSG $2 :$1: $3 VS $mr_choice | I $outcome!"