made it modular! modules/*.sh will be ran if it exists and called
This commit is contained in:
parent
943c5b5e3f
commit
121a1389fd
32
bot.sh
32
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"
|
||||
|
3
modules/help.sh
Executable file
3
modules/help.sh
Executable file
@ -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
|
1
modules/ping.sh
Executable file
1
modules/ping.sh
Executable file
@ -0,0 +1 @@
|
||||
echo "PRIVMSG $2 :$1: pong"
|
1
modules/test.sh
Executable file
1
modules/test.sh
Executable file
@ -0,0 +1 @@
|
||||
echo "PRIVMSG $2 :$1: The test was successful"
|
Loading…
Reference in New Issue
Block a user