From 962e19a2bcd0697aa80e5da8b0bf499557219a59 Mon Sep 17 00:00:00 2001 From: julien Date: Mon, 6 Jul 2009 17:26:39 +0200 Subject: Initial import --- shbirth.sh | 16 ++++++++++++++++ shbot.sh | 27 +++++++++++++++++++++++++++ shbrain.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ shbrain.txt | 7 +++++++ shtrains.sh | 9 +++++++++ 5 files changed, 109 insertions(+) create mode 100755 shbirth.sh create mode 100755 shbot.sh create mode 100755 shbrain.sh create mode 100644 shbrain.txt create mode 100755 shtrains.sh diff --git a/shbirth.sh b/shbirth.sh new file mode 100755 index 0000000..2d31a9c --- /dev/null +++ b/shbirth.sh @@ -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" +} diff --git a/shbot.sh b/shbot.sh new file mode 100755 index 0000000..cba3b01 --- /dev/null +++ b/shbot.sh @@ -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 + diff --git a/shbrain.sh b/shbrain.sh new file mode 100755 index 0000000..bf8ade4 --- /dev/null +++ b/shbrain.sh @@ -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 + diff --git a/shbrain.txt b/shbrain.txt new file mode 100644 index 0000000..a203053 --- /dev/null +++ b/shbrain.txt @@ -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]}. + diff --git a/shtrains.sh b/shtrains.sh new file mode 100755 index 0000000..d49738e --- /dev/null +++ b/shtrains.sh @@ -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 + -- cgit v1.2.3