summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjulien2009-07-07 09:56:53 +0200
committerjulien2009-07-07 09:56:53 +0200
commitd44fb2f6bae26ae857279ebcc3a914b990b95480 (patch)
treef6b7d332f393a709d50ff381df8b16f6ed07a019
parentInitial import (diff)
downloadshbot-d44fb2f6bae26ae857279ebcc3a914b990b95480.tar.gz
shbot-d44fb2f6bae26ae857279ebcc3a914b990b95480.tar.bz2
shbot-d44fb2f6bae26ae857279ebcc3a914b990b95480.zip
Made a working trains script.
Diffstat (limited to '')
-rw-r--r--README0
-rwxr-xr-xshbirth.sh9
-rwxr-xr-xshbot.sh3
-rwxr-xr-xshbrain.sh15
-rw-r--r--shbrain.txt2
-rwxr-xr-xshtrains.sh17
6 files changed, 29 insertions, 17 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/README
diff --git a/shbirth.sh b/shbirth.sh
index 2d31a9c..b58c227 100755
--- a/shbirth.sh
+++ b/shbirth.sh
@@ -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
}
diff --git a/shbot.sh b/shbot.sh
index cba3b01..3a0e7ca 100755
--- a/shbot.sh
+++ b/shbot.sh
@@ -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
diff --git a/shbrain.sh b/shbrain.sh
index bf8ade4..6dd968a 100755
--- a/shbrain.sh
+++ b/shbrain.sh
@@ -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
diff --git a/shbrain.txt b/shbrain.txt
index a203053..4ebf14d 100644
--- a/shbrain.txt
+++ b/shbrain.txt
@@ -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]}.
diff --git a/shtrains.sh b/shtrains.sh
index d49738e..0d9739a 100755
--- a/shtrains.sh
+++ b/shtrains.sh
@@ -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