From f5faacf250d7c5da5c1e4ebe53d84d2bf788b72f Mon Sep 17 00:00:00 2001 From: Vivia Nikolaidou Date: Tue, 5 Nov 2013 15:34:05 +0200 Subject: Fix nickname and channel detection * Nicknames were assumed to be in [A-Za-z] format. Just detecting a [^!] now as ! separates the nickname from the host. * Channels may start with two hashes, the previous regexp didn't recognize that. --- shbot.sh | 2 +- shbrain.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shbot.sh b/shbot.sh index 066d202..0deee12 100755 --- a/shbot.sh +++ b/shbot.sh @@ -11,7 +11,7 @@ do if [[ "$LINE" =~ PING\ *:(.*) ]]; then echo "PONG :${BASH_REMATCH[1]}" >&3 else - [[ ${LINE} =~ :[a-zA-Z]*!.*(#.*)\ :.* ]] && ORIGIN=${BASH_REMATCH[1]} + [[ ${LINE} =~ :[^!]*![^#]*(#.*)\ :.* ]] && ORIGIN=${BASH_REMATCH[1]} echo "${LINE}" | ./shbrain.sh | \ while true do diff --git a/shbrain.sh b/shbrain.sh index 06cad02..572bd10 100755 --- a/shbrain.sh +++ b/shbrain.sh @@ -8,7 +8,7 @@ do LINE=${LINE[@]:0:$LEN} ### Parsing potential shcmd - if [[ $LINE =~ :([a-zA-Z]*)!.*:shcmd ]]; then + if [[ $LINE =~ :([^!]*)!.*:shcmd ]]; then EXPAND=(${LINE}) CMD=${EXPAND[4]#:} ARGS=${EXPAND[*]:5} -- cgit v1.2.3 From 6710f8b056262f90f2cd96ef444f1f992a0d10f1 Mon Sep 17 00:00:00 2001 From: Vivia Nikolaidou Date: Tue, 5 Nov 2013 15:45:52 +0200 Subject: Fixed advert command --- shbrain.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shbrain.sh b/shbrain.sh index 572bd10..93bded0 100755 --- a/shbrain.sh +++ b/shbrain.sh @@ -13,7 +13,7 @@ do CMD=${EXPAND[4]#:} ARGS=${EXPAND[*]:5} if [ "$CMD" = "advert" ]; then - echo "PRIVMSG $ARGS :Listen to shbot, the one true Bot"'!' >&3 + echo "Listen to shbot, the one true Bot!" elif [ "$CMD" = "join" ]; then echo "JOIN $ARGS" >&3 elif [ "$CMD" = "part" ]; then -- cgit v1.2.3 From 2f80a68b1f4e9cb5a636a38de90dd39987ebaa51 Mon Sep 17 00:00:00 2001 From: Vivia Nikolaidou Date: Tue, 5 Nov 2013 15:49:25 +0200 Subject: Added the duck generation module. The duck generation module listens to the "duck" command. It will then generate a random duck based on https://github.com/adyxax/hsbot with some additional heads and beaks. --- shbrain.sh | 2 ++ shduck.sh | 30 ++++++++++++++++++++++++++++++ shhelp.sh | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100755 shduck.sh diff --git a/shbrain.sh b/shbrain.sh index 93bded0..3b1f700 100755 --- a/shbrain.sh +++ b/shbrain.sh @@ -22,6 +22,8 @@ do ./shquote.sh ${ARGS[*]} elif [ "$CMD" = "trains" ]; then ./shtrains.sh ${ARGS[*]} + elif [ "$CMD" = "duck" ]; then + ./shduck.sh elif [ "$CMD" = "help" ]; then ./shhelp.sh $ARGS else diff --git a/shduck.sh b/shduck.sh new file mode 100755 index 0000000..5fc4b02 --- /dev/null +++ b/shduck.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Duck generation based on https://github.com/adyxax/hsbot + +RANDOM=$$ #Seed random number generator from script PID +export GLOBIGNORE="*" #Do not substitute asterisks (e.g. in $heads) for lists of files!! + +#Body parts (both RTL and LTR where applicable) +leftbeaks=(">" "=") +rightbeaks=("<" "=") +leftbody=("_/" "__/" "_~" "__~") +rightbody=("\\\\_" "\\\\__" "~_" "~__") +heads=("o" "O" "0" "@" "©" "®" "ð" "*" "ò" "ô" "ó" "ø" "⊕" "Ω" "ꙫ" "ꙩ" "Ꙩ" "ȯ" "◔" "õ" "ȯ" "⁰" "Ö" "Ó" "Ò" "Õ" "Ô" "ö") + +head=${heads[$RANDOM % ${#heads[@]} ]} #Pick a head + +left=$(expr $RANDOM % 2) #Whether it will be a left-to-right duck + +#Generate the duck +if [ $left == 1 ]; then + beak=${leftbeaks[$RANDOM % ${#leftbeaks[@]} ]} + body=${leftbody[$RANDOM % ${#leftbody[@]} ]} + duck=$beak$head$body +else + beak=${rightbeaks[$RANDOM % ${#rightbeaks[@]} ]} + body=${rightbody[$RANDOM % ${#rightbody[@]} ]} + duck=$body$head$beak +fi + +echo $duck diff --git a/shhelp.sh b/shhelp.sh index c2bd9c4..d3566ed 100755 --- a/shhelp.sh +++ b/shhelp.sh @@ -16,7 +16,7 @@ case "$1" in "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 : advert help join part quote trains" + *) echo "The following commands are available : advert help join part quote trains duck" ;; esac -- cgit v1.2.3