X-Git-Url: http://git.plutz.net/?p=httpchat;a=blobdiff_plain;f=channel.sh;fp=channel.sh;h=0f1bda7ecd6cb2285c9db1522f9fbaeea43a2a1d;hp=b930620ab610a93653cfe14186842f7ac98f38cb;hb=7481a68367b471a6a5058817342340a3e069e581;hpb=b0674d5fc925ab90c4bea072b0986a43be2471ef diff --git a/channel.sh b/channel.sh index b930620..0f1bda7 100755 --- a/channel.sh +++ b/channel.sh @@ -28,6 +28,28 @@ case $(POST action) in ;; esac +nicklist(){ + local nickfile="${chatfile%/channel}/nicks" + case $1 in + enter) + trap 'sed -i -E "/^${SESSION_KEY%%-*} $$ /d" "$nickfile"' INT QUIT + sed -i -E "/^${SESSION_KEY%%-*} /d" "$nickfile" + printf '%s %i %s\n' "${SESSION_KEY%%-*}" "$$" "$nickname" >>"$nickfile" + ;; + leave) + sed -i -E "/^${SESSION_KEY%%-*} $$ /d" "$nickfile" + ;; + esac + + nicklist='NICKNAMES: ' + while read -r s p nick; do + nicklist="${nicklist}/$nick/" + done <"$nickfile" + if ! tail -n20 "$chatfile" |grep -qxF "$nicklist"; then + printf '%s\n' "$nicklist" >>"$chatfile" + fi +} + if [ ! -f "$chatfile" ]; then yield_page create <<-EOF [form #nonexist method="POST" @@ -36,6 +58,8 @@ if [ ! -f "$chatfile" ]; then ] EOF else + nicklist enter + printf '%s: %s\r\n' Refresh 1 { printf ' [form #channel method="POST" @@ -50,14 +74,26 @@ else printf '[div #chat' tail --pid $$ -n50 -f "$chatfile" \ | sed -nuE ' - /^[^ ]+ [^ ]+ [^ ]+$/{ + /^[0-9-]{10}_[0-9:]{8}+ [^ ]+ [^ ]+$/{ h; s;^([^ ]+) ([^ ]+) ([^ ]+)$;\1;; s;.*_;;; s;.+;[p .message [span .date &];p; g; s;^([^ ]+) ([^ ]+) ([^ ]+)$;a\2;; bESC; :A s;.;;; s;(.)(.+);[span .nick [span .indicator \1]\2];p; g; s;^([^ ]+) ([^ ]+) ([^ ]+)$;b\3;; bESC; :B s;.;;; s;.+;[span .message &]];p; + b; + } + /^NICKNAMES: .*/{ + s;^NICKNAMES: ;;; h; s;^.*$;[div .nicklist [h2 Nicknames];p; g; + :NICKLIST + h; s;^/([^/]+)/.*$;c\1;; bESC :C + s;^.([^?])(.*)$;[a .nick href="/~\1\2" \1\2];p; + s;^.(\?)(.*)$;[span .nick [span .indcator \1]\2];p; + g; s;/[^/]+/;;; /.+/bNICKLIST s;^.*$;];p; + b; } b; :ESC '"$UNSTRING"' '"$SHESCAPE"' - /^a/bA; /^b/bB; + /^a/bA; /^b/bB; /^c/bC; ' } |yield_page channel + + nicklist leave fi