Archived
1
0
Fork 0

Made a working trains script.

This commit is contained in:
julien 2009-07-07 09:56:53 +02:00
parent 962e19a2bc
commit d44fb2f6ba
6 changed files with 29 additions and 17 deletions

0
README Normal file
View file

View file

@ -4,13 +4,14 @@ SERVER=${1:-kro.corp}
#SERVER=${1:-localhost}
PORT=6667
export NICK=shbot
export CHANNELS=${2:-#codemore}
export CHANNEL2=${2:-#shbot}
export CHANNELS=('#codemore #shbot')
function shbirth ()
{
echo "NICK $NICK"
echo "USER $(whoami) +iw $NICK :$0"
#echo "JOIN $CHANNEL"
echo "JOIN $CHANNEL2"
for CHANNEL in $CHANNELS
do
echo "JOIN $CHANNEL"
done
}

View file

@ -12,12 +12,13 @@ do
echo "PONG :${BASH_REMATCH[1]}" >&3
sleep 0.1
else
[[ ${LINE} =~ :[a-zA-Z]*!.*(#.*)\ :.* ]] && ORIGIN=${BASH_REMATCH[1]}
echo "${LINE}" | ./shbrain.sh | \
while true
do
read ANSWER || break
echo "--> "$ANSWER
echo $ANSWER >&3
echo "PRIVMSG $ORIGIN :"$ANSWER >&3
done
fi
done

View file

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

View file

@ -1,6 +1,6 @@
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).*(le retour|is back) 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]}.

View file

@ -1,9 +1,20 @@
#!/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'
links -dump 'http://transilien.mobi/pam/TempReelSaisieDepartSubmit.do?debutDepart=Courbevoie&tous=Tous+trains' | head -n 22 | tail -n 18 >trains.tmp
echo "PRIVMSG $CHANNEL2 :"$*
cat trains.tmp | \
while true
do
read PATTERN || break
read STATION || break
read UGUU || break
[[ $PATTERN =~ \ *[A-Z]{4}\ *(.*) ]] && PATTERN=${BASH_REMATCH[1]}
if [ -n "$*" ]; then
[[ $STATION =~ $@ ]] && echo "$PATTERN $STATION"
else
echo "$PATTERN $STATION"
fi
done
exit 0