Archived
1
0
Fork 0

Initial import

This commit is contained in:
julien 2009-07-06 17:26:39 +02:00
commit 962e19a2bc
5 changed files with 109 additions and 0 deletions

16
shbirth.sh Executable file
View file

@ -0,0 +1,16 @@
#! /bin/bash
SERVER=${1:-kro.corp}
#SERVER=${1:-localhost}
PORT=6667
export NICK=shbot
export CHANNELS=${2:-#codemore}
export CHANNEL2=${2:-#shbot}
function shbirth ()
{
echo "NICK $NICK"
echo "USER $(whoami) +iw $NICK :$0"
#echo "JOIN $CHANNEL"
echo "JOIN $CHANNEL2"
}

27
shbot.sh Executable file
View file

@ -0,0 +1,27 @@
#!/bin/bash
source ./shbirth.sh
exec 3<>/dev/tcp/$SERVER/$PORT
shbirth 1>&3
while true
do
read LINE 0<&3 || break
echo "<-- "$LINE
if [[ "$LINE" =~ PING\ *:(.*) ]]; then
echo "PONG :${BASH_REMATCH[1]}" >&3
sleep 0.1
else
echo "${LINE}" | ./shbrain.sh | \
while true
do
read ANSWER || break
echo "--> "$ANSWER
echo $ANSWER >&3
done
fi
done
exec 3>&-
exit 0

50
shbrain.sh Executable file
View file

@ -0,0 +1,50 @@
#!/bin/bash
while true
do
read LINE || break
### First of all we get rid of the trailing \n
LEN=`expr ${#LINE} - 1`
LINE=${LINE[@]:0:$LEN}
### Parsing potential shcmd
if [[ $LINE =~ :([a-zA-Z]*)!.*:shcmd ]]; then
EXPAND=(${LINE})
CMD=${EXPAND[4]#:}
ARGS=${EXPAND[*]:5}
if [[ "trains" =~ "$CMD" ]]; then
sh -ex ./shtrains.sh ${ARGS[*]}
break
elif [ "$CMD" = "help" ]; then
echo "PRIVMSG $CHANNEL2 :Help"
break
else
echo "PRIVMSG $CHANNEL2 :Use \"shcmd help\" to list available commands."
fi
fi
### Parsing brain file for potential replies
LINENUM=1
cat shbrain.txt | \
while true
do
read BRAIN || break
IFS=" " BRAIN=($BRAIN)
PATTERN=${BRAIN[0]}
PERCENT=${BRAIN[1]}
RESPONSE=${BRAIN[2]}
if [[ "$LINE" =~ ${PATTERN} ]]; then
if [[ "$((RANDOM / 320))" -lt ${PERCENT} ]]; then
echo "PRIVMSG $CHANNEL2 :"`eval echo $RESPONSE`
#awk 'NR==$LINENUM{$0='"$RESPONSE"'}1' shbrain.txt
#sed "$LINENUM"'s\\'"${PATTERN} 10 ${RESPONSE}" -i shbrain.txt
break
fi
fi
(( LINENUM++ ))
done
done
exit 0

7
shbrain.txt Normal file
View file

@ -0,0 +1,7 @@
ping 100 pong
plop 100 pataplop
:([a-zA-Z]*)!.*:.*(shbot|julien|root).*(le retour) 100 De retour, encore plus fort...
:([a-zA-Z]*)!.*:.*(shbot|julien|root).*(fuck|merde) 100 You, fuck you ${BASH_REMATCH[1]}...
:([a-zA-Z]*)!.*:.*(clex|galdor).*(fuck|merde|suck) 100 You are right ${BASH_REMATCH[1]}, fuck you ${BASH_REMATCH[2]}.

9
shtrains.sh Executable file
View file

@ -0,0 +1,9 @@
#!/bin/bash
links -dump 'http://transilien.mobi/pam/TempReelSaisieDepartSubmit.do?debutDepart=Courbevoie&tous=Tous+trains' > trains.tmp
#wget -q -O trains.tmp 'http://transilien.mobi/pam/TempReelSaisieDepartSubmit.do?debutDepart=Courbevoie&tous=Tous+trains'
echo "PRIVMSG $CHANNEL2 :"$*
exit 0