dot

packages and services management
Log | Files | Refs | README

commit afcf307e5a6cce59445ad76fce6263afc245bb36
parent ffca5c6fe12f45e171253cf29bfc97dadf6bdf80
Author: josuah <mail@josuah.net>
Date:   Tue, 30 Aug 2016 18:07:46 +0200

irc: Fixed

Diffstat:
Mbin/irc | 49++++++++++++++++++++++++++-----------------------
1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/bin/irc b/bin/irc @@ -34,13 +34,14 @@ write() # connect() { - local srv="$1" user="$NICK" + local srv="$1" + [ -f "$srv/NICK" ] && user="$(tail "$srv/NICK")" [ -z "$user" ] && user="$NICK" mkdir -p "$srv" [ -p "$srv/IN" ] || mkfifo "$srv/IN" # `tee ... RAW` is for debugging, you can remove it. - tail -f "$srv/IN" | nc "$srv" 6667 | tee -a "$srv/RAW" | output "$srv" & + tail -f "$srv/IN" | tee -a "$srv/RAWIN" | nc "$srv" 6667 | tee -a "$srv/RAW" | output "$srv" & write "$srv" "NICK $user" write "$srv" "USER $(whoami) +i * :$FULLNAME" @@ -117,13 +118,13 @@ input() # message = [ ":" prefix SPACE ] command [ params ] crlf # prefix = servername / ( nickname [ [ "!" user ] "@" host ] ) # command = 1*letter / 3digit -# params = *14( SPACE middle ) [ SPACE ":" trailing ] -# =/ 14( SPACE middle ) [ SPACE [ ":" ] trailing ] +# params = *14( SPACE middle ) [ SPACE ":" trail ] +# =/ 14( SPACE middle ) [ SPACE [ ":" ] trail ] # # nospcrlfcl = %x01-09 / %x0B-0C / %x0E-1F / %x21-39 / %x3B-FF # ; any octet except NUL, CR, LF, " " and ":" # middle = nospcrlfcl *( ":" / nospcrlfcl ) -# trailing = *( ":" / " " / nospcrlfcl ) +# trail = *( ":" / " " / nospcrlfcl ) # # SPACE = %x20 ; space character # crlf = %x0D %x0A ; "carriage return" "linefeed" @@ -135,7 +136,7 @@ output() while read msg do # Parse server message - local prefix='' nick='' cmd='' trailing='' sep='' + local prefix='' nick='' cmd='' trail='' sep='' local params='' middle='' chan='' user="$(tail "$srv/NICK")" # Prefix @@ -154,10 +155,10 @@ output() [ -z "${msg##* *}" ] && params="${msg# *}" if [ -z "${msg##:*}" ] then - trailing="${params#:}" + trail="${params#:}" elif [ -z "${msg##*:*}" ] then - trailing="${params#*:}" + trail="${params#*:}" middle="${params%%:*}" else middle="$params" @@ -165,7 +166,7 @@ output() # Channel and extra command action case "$cmd" in - JOIN ) chan="$trailing" ;; + JOIN ) chan="$trail" ;; PART ) chan="$middle" ;; PRIVMSG ) if [ "$middle" = "$user" ] @@ -175,34 +176,36 @@ output() ;; NICK ) chan="SERVER" if [ "$nick" = "$user" ] - then printf '%s\n' "$trailing" > "$srv/NICK" + then printf '%s\n' "$trail" > "$srv/NICK" fi ;; - QUIT | NOTICE | [0-9][0-9][0-9] | * | '' ) chan=SERVER ;; + QUIT | NOTICE | [0-9][0-9][0-9] | * | '' ) + chan=SERVER + ;; esac # Execute action case "$cmd" in PING ) - write "$srv" "PONG $trailing" + write "$srv" "PONG $trail" ;; - QUIT | NICK ) - for chan in "$(ls "$srv/#"*)" "$srv/SERVER" - do print_msg "$nick" "$trailing" "$cmd" "$srv" \ - >> "$srv/$chan" + QUIT | NICK | JOIN ) + for chan in "$srv/#"* "$srv/SERVER" + do chan="${chan#$srv}" + print_msg "$nick" "$trail" "$cmd" "$srv" \ + "$chan" >> "$srv/$chan" done ;; *) - print_msg "$nick" "$trailing" "$cmd" "$srv" \ + print_msg "$nick" "$trail" "$cmd" "$srv" "$chan" \ >> "$srv/$chan" ;; esac # Bot actions - case "$trailing" in + case "$trail" in 'VERSION' ) - write "$srv" - "PRIVMSG $nick :VERSION nc and a script" + write "$srv" "PRIVMSG $nick :VERSION nc + sh" ;; esac done @@ -213,8 +216,8 @@ output() # print_msg() { - local nick="$1" trailing="$2" cmd="$3" srv="$4" last_cmd last_nick - local user="$(tail "$srv/NICK")" + local nick="$1" trail="$2" cmd="$3" srv="$4" chan="$5" + local user="$(tail "$srv/NICK")" last_cmd last_nick case "$cmd" in QUIT ) cmd='<' ;; @@ -238,7 +241,7 @@ print_msg() fi # Print the message - printf '%s\n' "$trailing" | fold -s -w $((78 - $NICK_LEN - ${#cmd})) \ + printf '%s\n' "$trail" | fold -s -w $((78 - $NICK_LEN - ${#cmd})) \ | while read line do printf "%${NICK_LEN}s %1s %s\n" "$nick" "$cmd" "$line"