summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@also>2010-05-07 04:52:10 +0200
committertv <tv@also>2010-05-07 04:52:10 +0200
commitee937603bb8ad9b18d03113bee4759811748d337 (patch)
treeea4cff25143181f66053d2e4367deea656d62388
parent75d12a3ba0c0a2bc9adaeb6660757d8dfdff6f1e (diff)
parente164088a38e067b4456cf131a260e3cdd90d0fb3 (diff)
Merge ssh://shack/~/noise
-rw-r--r--.gitignore1
-rwxr-xr-xmodules/chat33
-rwxr-xr-xmodules/date6
-rwxr-xr-xmodules/echo (renamed from modules/msg)0
-rwxr-xr-xmodules/join15
-rwxr-xr-xmodules/names22
-rwxr-xr-xmodules/nick10
-rwxr-xr-xmodules/part15
-rwxr-xr-xmodules/query23
-rwxr-xr-xmodules/send_to_channel17
-rwxr-xr-xmodules/sleep10
-rwxr-xr-xmodules/test10
-rwxr-xr-xmodules/twitter18
-rwxr-xr-xmodules/wall5
-rwxr-xr-xmodules/zeit4
-rwxr-xr-xnoise36
-rwxr-xr-xnoise-as-shack2
17 files changed, 200 insertions, 27 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..81154dd4
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+samples
diff --git a/modules/chat b/modules/chat
new file mode 100755
index 00000000..e5badc36
--- /dev/null
+++ b/modules/chat
@@ -0,0 +1,33 @@
+#! /bin/sh
+
+case "$1" in
+ (--help) echo send text to everyone with @@ prepended ;;
+ (/nick)
+ echo set nick to $2
+ echo /set chat_nick $2 >$NOISE_linefeed;;
+ (/names)
+ cd /tmp/noise
+ . $NOISE_pid/environment
+ nick="${chat_nick-$NOISE_pid}"
+ channel="$chat_channel"
+ echo "Users in channel $channel"
+ for client in * ; do
+ . $client/environment
+ chat_nick="${chat_nick-$client}"
+ if test "$channel" = "$chat_channel" && test "$default_command" = chat ; then
+ echo "$chat_nick"
+ fi
+ unset chat_nick
+ unset chat_channel
+ unset default_command
+ done ;;
+ (*)
+ cd /tmp/noise
+ . $NOISE_pid/environment
+ nick="${chat_nick-$NOISE_pid}"
+
+ echo "/send_to_channel $chat_channel $nick: $*" > $NOISE_linefeed
+
+
+ #echo /wall @@ $* >$NOISE_linefeed
+esac
diff --git a/modules/date b/modules/date
new file mode 100755
index 00000000..8cd1b0c1
--- /dev/null
+++ b/modules/date
@@ -0,0 +1,6 @@
+#! /bin/sh
+case "$1" in
+ (--help) : ;;
+ (*)
+ date --rfc-3339=s
+esac
diff --git a/modules/msg b/modules/echo
index 344dd963..344dd963 100755
--- a/modules/msg
+++ b/modules/echo
diff --git a/modules/join b/modules/join
new file mode 100755
index 00000000..68afcb66
--- /dev/null
+++ b/modules/join
@@ -0,0 +1,15 @@
+#! /bin/sh
+
+case "$1" in
+ (--help) echo set default_command to chat and join channel ;;
+ (*)
+ . /tmp/noise/$NOISE_pid/environment
+ nick="${chat_nick-$NOISE_pid}"
+ echo /send_to_channel "${1-#23}" "$nick" joined the channel >$NOISE_linefeed
+ echo /set default_command chat >$NOISE_linefeed
+ echo /set chat_channel "${1-#23}" >$NOISE_linefeed
+ echo " joined channel ${1-#23}"
+ echo /part to go back to espeak ;;
+
+
+esac
diff --git a/modules/names b/modules/names
new file mode 100755
index 00000000..f5922064
--- /dev/null
+++ b/modules/names
@@ -0,0 +1,22 @@
+#! /bin/sh
+
+case "$1" in
+ (--help) echo send text to everyone with @@ prepended ;;
+ (*)
+ cd /tmp/noise
+ . $NOISE_pid/environment
+ if test "$default_command" != chat ; then exit ; fi
+ nick="${chat_nick-$NOISE_pid}"
+ channel="${1-$chat_channel}"
+ echo "Users in channel $channel"
+ for client in * ; do
+ . $client/environment
+ chat_nick="${chat_nick-$client}"
+ if test "$channel" = "$chat_channel" && test "$default_command" = chat ; then
+ echo "$chat_nick"
+ fi
+ unset chat_nick
+ unset chat_channel
+ unset default_command
+ done
+esac
diff --git a/modules/nick b/modules/nick
new file mode 100755
index 00000000..5ed1e9d9
--- /dev/null
+++ b/modules/nick
@@ -0,0 +1,10 @@
+#! /bin/sh
+
+case "$1" in
+ (--help) echo send text to everyone with @@ prepended ;;
+ (*)
+ . /tmp/noise/$NOISE_pid/environment
+ nick="${chat_nick-$NOISE_pid}"
+ echo /send_to_channel $chat_channel $nick is now known as $1 > $NOISE_linefeed
+ echo /set chat_nick $1 >$NOISE_linefeed;;
+esac
diff --git a/modules/part b/modules/part
new file mode 100755
index 00000000..d35ac501
--- /dev/null
+++ b/modules/part
@@ -0,0 +1,15 @@
+#! /bin/sh
+
+case "$1" in
+ (--help) echo leave chat mode ;;
+ (*)
+ . /tmp/noise/$NOISE_pid/environment
+ nick="${chat_nick-$NOISE_pid}"
+
+ echo "/send_to_channel $chat_channel $nick has quit ${*-no reason}" > $NOISE_linefeed
+
+ echo /set default_command espeak >$NOISE_linefeed
+ echo "disabled chat mode (set back to espeak)" ;;
+
+
+esac
diff --git a/modules/query b/modules/query
new file mode 100755
index 00000000..ceeff8a5
--- /dev/null
+++ b/modules/query
@@ -0,0 +1,23 @@
+#! /bin/sh
+
+case "$1" in
+ (--help) echo send a message to a specific user ;;
+ (*)
+ cd /tmp/noise
+ . $NOISE_pid/environment
+ nick="${chat_nick-$NOISE_pid}"
+ target="$1"
+ shift
+ for client in * ; do
+ . $client/environment
+ if test "$target" = "${chat_nick-$client}" ; then
+ echo "/echo <-- $nick: $*" > $client/linefeed
+ echo "--> $target: $*"
+ exit
+ fi
+ unset chat_channel
+
+ done
+
+ echo "$nick not found"
+esac
diff --git a/modules/send_to_channel b/modules/send_to_channel
new file mode 100755
index 00000000..4a0470af
--- /dev/null
+++ b/modules/send_to_channel
@@ -0,0 +1,17 @@
+#! /bin/sh
+
+case "$1" in
+ (--help) : ;;
+ (*)
+ cd /tmp/noise
+ channel="$1"
+ shift
+ for client in * ; do
+ . $client/environment
+ if test "$channel" = "$chat_channel" && test "$default_command" = chat ; then
+ echo "/echo $*" > $client/linefeed
+ fi
+ unset chat_channel
+
+ done
+esac
diff --git a/modules/sleep b/modules/sleep
new file mode 100755
index 00000000..b8d350f7
--- /dev/null
+++ b/modules/sleep
@@ -0,0 +1,10 @@
+#! /bin/sh
+case "$1" in
+ (--help) echo "pause for NUMBER seconds" ;;
+ (*)
+ if ! echo "$1" | grep -Eq '^([0-9]+(\.[0-9]*)?|[0-9]*\.[0-9]+)$' ; then
+ echo 'FAIL: $1 is not a number'
+ else
+ sleep "$1"
+ fi
+esac
diff --git a/modules/test b/modules/test
index 30444bf7..2c0b8e0d 100755
--- a/modules/test
+++ b/modules/test
@@ -3,7 +3,11 @@
case "$1" in
(--help) echo do some test-module related stuff ;;
(*)
- echo test-module called with following arguments: "$@"
- ## send command for re-evaluation:
- echo /espeak test >$NOISE_linefeed
+
+ echo -n ">> "
+ read TEST
+ if [ $TEST == 'q' ]; then exit; fi
+ echo /wall @@ $TEST >$NOISE_linefeed
+ #sleep 1
+ #sleep 1; echo /test >$NOISE_linefeed &
esac
diff --git a/modules/twitter b/modules/twitter
index e8962657..49d092fb 100755
--- a/modules/twitter
+++ b/modules/twitter
@@ -22,6 +22,7 @@ def shorten(text):
text = text.replace(" years", "y")
text = text.replace(" year", "y")
text = text.replace(" ago", "")
+ text = text.replace("a", "1")
return text
@@ -33,7 +34,7 @@ def parse(text):
escape = ""
if piece.startswith("@"):
escape = ""
- if piece[1:].lower() == "shackspace":
+ if piece[1:].lower() == "shackspam" or piece[1:].lower() == "shackspace":
escape = ""
elif piece.startswith("#"):
@@ -48,16 +49,16 @@ def parse(text):
return new
if len(sys.argv) > 1 and sys.argv[1] == "--help":
- print "read or post to the shackspace twitter timeline"
+ print "read or post to the shackspam twitter timeline"
if len(sys.argv) == 3 and sys.argv[2] == "--verbose":
print "call without parameters to read"
- print "use /twitter [your tweet] to tweet something to the shackspace twitter timeline"
+ print "use /twitter [your tweet] to tweet something to the shackspam twitter timeline"
exit()
-api = twitter.Api(username="shackspace", password="0b0dallaf4lla")
+api = twitter.Api(username="shackspam", password="sh4ckit")
#api.SetXTwitterHeaders("Shackspace UTTERANCE","","0.00.0.01.42")
@@ -93,7 +94,8 @@ else:
a.reverse()
for i in a:
text = i.text
- if i.user.screen_name.lower() == "shackspace":
+ ilen = len(i.user.screen_name) + len(shorten(i.GetRelativeCreatedAt())) + 2
+ if i.user.screen_name.lower() == "shackspace" or i.user.screen_name.lower() == "shackspam":
info = "" + i.user.screen_name + " " + shorten(i.GetRelativeCreatedAt()) + ""
else:
info = "" + i.user.screen_name + " " + shorten(i.GetRelativeCreatedAt()) + ""
@@ -102,12 +104,12 @@ else:
t = text.split(" ")
tmp = ""
for n in t:
- if ((len(tmp) + len(n)) > 80):
+ if ((len(tmp) + len(n)) >= 80):
print parse(tmp).encode("utf8")
- tmp = " " *( len(info)-15)
+ tmp = " " * ilen
tmp += " " + n
- if len(tmp) > (len(info)-15+1):
+ if len(tmp) > ilen:
print parse(tmp).encode("utf8")
diff --git a/modules/wall b/modules/wall
index fa7618fe..7c32d01d 100755
--- a/modules/wall
+++ b/modules/wall
@@ -2,8 +2,7 @@
case "$1" in
(--help) : ;;
(?*)
- for client in /tmp/noise-client-* ; do
- #echo /msg "$*`printf '\a'`" >$client
- echo /msg "$*" >$client
+ for linefeed in /tmp/noise/*/linefeed ; do
+ echo /msg "$*" >$linefeed
done
esac
diff --git a/modules/zeit b/modules/zeit
index 75ffc20a..4c41fa10 100755
--- a/modules/zeit
+++ b/modules/zeit
@@ -9,10 +9,10 @@ case "$1" in
M=`date +%M|sed 's/0*//'`
echo /set pitch 10
case "$lang" in
- (de|'') echo " Es ist $k Uhr $M" >$NOISE_linefeed ;;
+ (de|'') echo "/espeak Es ist $k Uhr $M" ;;
(en|*-en)
test -z "$M" || M="and $M minutes"
- echo " It is $k o clock $M" >$NOISE_linefeed ;;
+ echo "/espeak It is $k o clock $M" ;;
(*) echo "Error: unsupported lang = $lang" >&2
esac
echo /set pitch ${noise_pitch-100}
diff --git a/noise b/noise
index 11976f68..cb4b8531 100755
--- a/noise
+++ b/noise
@@ -29,6 +29,12 @@ noise_set() { # set a variable
eval "export noise_$1='$2' ; $echo \
\"$1 changed from $old to $2\""
fi
+ ## write variable to $env
+ if grep -q "^$1=" "$env" ; then
+ sed -ri "s'^($1)=(.*)\$'\1=\'$2\''" $env
+ else
+ echo "$1='$2'" >>$env
+ fi
;;
esac
}
@@ -44,27 +50,35 @@ fail() {
}
cleanup() {
- rm -f $linefeed
kill $jobs
+ rm -f $linefeed $env
+ rmdir /tmp/noise/$$ 2>/dev/null
+ rmdir /tmp/noise 2>/dev/null
}
qname="`readlink -f "$0"`"
dirname="`dirname "$qname"`"
+export HOME='/home/shack'
if test -d "$dirname/modules" ; then
export NOISE_PATH="${NOISE_PATH+$NOISE_PATH:}$dirname/modules"
export NOISE_PATH="${NOISE_PATH+$NOISE_PATH:}$HOME/noise/modules"
fi
-linefeed="/tmp/noise-client-$$"
+mkdir -vp /tmp/noise/$$
+linefeed="/tmp/noise/$$/linefeed"
+env="/tmp/noise/$$/environment"
trap cleanup EXIT
mkfifo $linefeed
+touch $env
##
##
##
readline() {
{ read && echo "$REPLY" ; } | sed -rn "
s/[']//g
- s:^/([a-z]+)([[:space:]]+(.*))?$:command=\1; args='\3';:p;t
+ s/~%/\n/g
+ s/([^\\])([#<>])/\1\\\\\2/g
+ s:^/([a-z_]+)([[:space:]]+(.*))?$:command=\1; args='\3';:p;t
s@^([[:alnum:]_/+-]+):[[:space:]]*(.*)@command=lang; args='\1 \2';@p;t
s@^\![[:space:]]*(.*)@command=play; args='\1';@p;t
s:.*:command='$noise_default_command'; args='&';:p;t
@@ -73,19 +87,13 @@ readline() {
##
##
##
-export noise_prompt="READY.
-"
-export noise_default_command=espeak
-##
-##
-##
while echo -n "$noise_prompt" && eval "`readline`" ; do
## modcall
for dir in `echo "$NOISE_PATH" | tr : \ ` ; do
module="$dir/$command"
if test -x "$module" ; then
shift
- eval 'NOISE="$0" NOISE_linefeed="$linefeed" "$module"' "$args"
+ eval 'NOISE="$0" NOISE_pid="$$" NOISE_linefeed="$linefeed" "$module"' "$args"
continue 2
fi
done
@@ -110,6 +118,14 @@ EOF
##
##
exec >>$linefeed
+##
+##
+##
+echo '/set prompt "READY.~%"'
+echo '/set default_command espeak'
+##
+##
+##
while read ; do
case $REPLY in
(/quit) echo /quit ; exit ;;
diff --git a/noise-as-shack b/noise-as-shack
index c327bb81..10ae3c1c 100755
--- a/noise-as-shack
+++ b/noise-as-shack
@@ -1,4 +1,4 @@
#! /bin/sh
qname="`readlink -f "$0"`"
dirname="`dirname "$qname"`"
-exec su - shack -c "$dirname"/noise
+exec su - shack -c "env -i TCPREMOTEIP=\"$TCPREMOTEIP\" \"$dirname/noise\""