summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjulien2009-08-19 12:22:40 +0200
committerjulien2009-08-19 12:22:40 +0200
commitd0675339023114166a1f0da81fb49c3ee68d0c18 (patch)
tree6b2517b1fd4dd8520ddf2710b27f1243797a0db8
parentRefactored command handling (diff)
downloadshbot-d0675339023114166a1f0da81fb49c3ee68d0c18.tar.gz
shbot-d0675339023114166a1f0da81fb49c3ee68d0c18.tar.bz2
shbot-d0675339023114166a1f0da81fb49c3ee68d0c18.zip
Added the quote module
-rwxr-xr-xshbot.sh1
-rwxr-xr-xshbrain.sh2
-rwxr-xr-xshhelp.sh12
-rwxr-xr-xshquote.sh25
-rw-r--r--shquote.txt4
5 files changed, 42 insertions, 2 deletions
diff --git a/shbot.sh b/shbot.sh
index 47e3865..066d202 100755
--- a/shbot.sh
+++ b/shbot.sh
@@ -10,7 +10,6 @@ do
echo "<-- "$LINE
if [[ "$LINE" =~ PING\ *:(.*) ]]; then
echo "PONG :${BASH_REMATCH[1]}" >&3
- sleep 0.1
else
[[ ${LINE} =~ :[a-zA-Z]*!.*(#.*)\ :.* ]] && ORIGIN=${BASH_REMATCH[1]}
echo "${LINE}" | ./shbrain.sh | \
diff --git a/shbrain.sh b/shbrain.sh
index 6a42feb..06cad02 100755
--- a/shbrain.sh
+++ b/shbrain.sh
@@ -18,6 +18,8 @@ do
echo "JOIN $ARGS" >&3
elif [ "$CMD" = "part" ]; then
echo "PART $ARGS" >&3
+ elif [ "$CMD" = "quote" ]; then
+ ./shquote.sh ${ARGS[*]}
elif [ "$CMD" = "trains" ]; then
./shtrains.sh ${ARGS[*]}
elif [ "$CMD" = "help" ]; then
diff --git a/shhelp.sh b/shhelp.sh
index 27d1b8f..c2bd9c4 100755
--- a/shhelp.sh
+++ b/shhelp.sh
@@ -1,12 +1,22 @@
#!/bin/bash -ex
case "$1" in
+ "advert") echo "advert <CHANNEL> : Make shbot speak the truth about himself on the specified CHANNEL."
+ ;;
"help") echo "help <TOPIC> : Prints help about TOPIC."
;;
+ "join") echo "join <CHANNEL> : Make shbot join the specified CHANNEL."
+ ;;
+ "part") echo "part <CHANNEL> : Make shbot part the specified CHANNEL."
+ ;;
+ "quote") echo "quote [OWNER QUOTE] :"
+ echo " Without arguments : prints a random quote."
+ echo " if OWNER and QUOTE are provided : save the quote for posterity and legend."
+ ;;
"trains") echo "trains [STATION] : Prints the next trains that will stop at Courbevoie's station."
echo " When provided, only results that concerns STATION are advertised."
;;
- *) echo "The following commands are available : help trains"
+ *) echo "The following commands are available : advert help join part quote trains"
;;
esac
diff --git a/shquote.sh b/shquote.sh
new file mode 100755
index 0000000..82076fb
--- /dev/null
+++ b/shquote.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+if [ -n "$2" ]; then
+ ARGS=$* && ARGS=($ARGS)
+ OWNER=$1
+ LEN=`expr ${#ARGS[*]}`
+ QUOTE=${ARGS[@]:1:$LEN}
+
+ echo "${OWNER}" >> shquote.txt
+ echo "${QUOTE}" >> shquote.txt
+#elif [ -n "$1" ]; then
+ # TODO : quote someone
+else
+ NB_LINES=(`wc -l shquote.txt`)
+ LINE=$((RANDOM * NB_LINES[0] / 65534))
+
+ # IFS="\r" LINES=(`tail -n $((LINE + 2)) shquote.txt | head -n 2`)
+ # QUOTE=${LINES[0]}
+ # OWNER=${LINES[1]}
+ QUOTE=`tail -n $((LINE * 2 + 1)) shquote.txt | head -n 1`
+ OWNER=`tail -n $((LINE * 2 + 2)) shquote.txt | head -n 1`
+ echo "\"${QUOTE}\""
+ echo "-- ${OWNER}"
+fi
+
diff --git a/shquote.txt b/shquote.txt
new file mode 100644
index 0000000..415a8d2
--- /dev/null
+++ b/shquote.txt
@@ -0,0 +1,4 @@
+galdor 08/17/09 21:08:14
+J'ai 23 ans et une gueule de nerd.
+julien 08/17/09 21:42:28
+J'ai déjà fait beaucoup de rapports en latex.