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
# @author Dimitar Dimitrov
#!/bin/bash
. bot.properties
config=".bot.cfg"
echo "NICK $nick" > $config
echo "USER $user" >> $config
echo "JOIN #$channel" >> $config
input=".bot.cfg"
echo "NICK $nick" > $input
echo "USER $user" >> $input
echo "JOIN #$channel" >> $input
tail -f $config | telnet $server 6667 | while read res
tail -f $input | telnet $server 6667 | while read res
do
# do things when you see output
case "$res" in
# respond to ping requests from the server
PING*)
echo "$res" | sed "s/PING/PONG/" >> $config
echo "$res" | sed "s/I/O/" >> $input
;;
# for pings on nick/user
*"You have not"*)
echo "JOIN #$channel" >> $config
echo "JOIN #$channel" >> $input
;;
# run when someone joins
*JOIN*)
who=$(echo "$res" | sed -r "s/:(.*)\!.*@.*/\1/")
who=$(echo "$res" | perl -pe "s/:(.*)\!.*@.*/\1/")
if [ "$who" = "$nick" ]
then
continue
fi
echo "MODE #$channel +o $who" >> $config
echo "MODE #$channel +o $who" >> $input
;;
# run when a message is seen
*PRIVMSG*)
echo "$res"
who=$(echo "$res" | sed -r "s/:(.*)\!.*@.*/\1/")
from=$(echo "$res" | sed -r "s/.*PRIVMSG ([#]?([a-zA-Z]|\-)*) :.*/\1/")
who=$(echo "$res" | perl -pe "s/:(.*)\!.*@.*/\1/")
from=$(echo "$res" | perl -pe "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/")
will=$(echo "$res" | perl -pe "s/.*:$nick:(.*)/\1/")
else
will=$(echo "$res" | sed -r "s/.*$nick :(.*)/\1/")
will=$(echo "$res" | perl -pe "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
./modules/help.sh $who $from >> $input
continue
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"

View File

@ -4,7 +4,7 @@
# 2 - scissor
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
case "$m_choice" in
@ -29,4 +29,4 @@ else
outcome="win"
fi
echo "PRIVMSG $2 :$1: $4 VS $mr_choice | I $outcome!"
echo "PRIVMSG $2 :$1: $3 VS $mr_choice | I $outcome!"