From: Romano <unobe@cpan.org>
To: 9front@9front.org
Subject: Re: [9front] Re: [patch] format messages for ircrc
Date: Tue, 05 May 2020 07:43:35 +0000 [thread overview]
Message-ID: <26E4B111-656D-433B-B9A5-5D64A8DD47BF@cpan.org> (raw)
In-Reply-To: <29C755ECA38798261162073E8677BA15@eigenstate.org>
Thanks Ori!
I've updated the patch and tested it: see below (and it's also at http://okturing.com/src/8458/body). Note that 512 is the # of characters including the hostname (63 chars), command, the actual text message, and the final CR&LF required by the protocol. So the # of characters allowed per message text is 447, which I mention in the man page.
On Mon, May 4, 2020, at 8:38 PM, ori@eigenstate.org wrote:
> > Ping. Perhaps the -l option is too much.
>
> Agreed -- I'd compute it. That would probably look something like:
>
> linelen = `{hoc -e '510 - '`{echo 'PRIVMSG '^$target^' :' | wc -c }}
>
> Another small bit of nitpicking (I'd be ok with committing it as is, but
> I may as well register my preferences:
>
> > + msg=($msg^'
> > +PRIVMSG '^$target^' :'^$"cmd)
>
>
> I'd do this somewhere near the start of the program:
>
> nl='
> '
>
> And construct strings using it like this:
>
> msg=($msg^$nl^'PRIVMSG '^$target^' :'^$"cmd)
>
> Other than that, this looks fine to me.
>
diff -r 0ee17db5d86b rc/bin/ircrc
--- a/rc/bin/ircrc Sat May 02 17:32:01 2020 +0200
+++ b/rc/bin/ircrc Tue May 05 00:36:54 2020 -0700
@@ -49,71 +49,86 @@
echo QUIT : Leaving... > $netdir/data
exit
}
- msg=()
- out=()
- switch ($cmd(1)) {
- case /!
- eval `{mshift $cmd} | while(rc=`{read})echo 'PRIVMSG '^$target^' :' $rc | tee $netdir/data
- case /M
- msg = (MODE `{mshift $cmd})
- case /N
+ do_cmd
+ }
+}
+
+fn do_cmd {
+ msg=()
+ out=()
+ switch ($cmd(1)) {
+ case /!
+ eval `{mshift $cmd} | while(rc=`{read})echo 'PRIVMSG '^$target^' :' $rc | tee $netdir/data
+ case /M
+ msg = (MODE `{mshift $cmd})
+ case /N
+ cmd = `{mshift $cmd}
+ if (! ~ $#cmd 0)
+ msg = (NOTICE $cmd(1) : `{mshift $cmd})
+ case /T
+ msg = (TOPIC `{mshift $cmd})
+ case /W
+ msg = (WHOIS `{mshift $cmd})
+ case /a
+ msg = (AWAY : `{mshift $cmd})
+ case /j
+ if (~ $#cmd 2) {
+ target=$cmd(2)
+ title
+ msg = (JOIN `{mshift $cmd})
+ if(~ $target *,*)
+ target = `{echo $target | awk -F',' '{print $NF}'}
+ }
+ case /l
+ msg = (LIST `{mshift $cmd})
+ case /m
+ cmd = `{mshift $cmd}
+ if (! ~ $#cmd 0) {
+ target_orig=$target
+ target = $cmd(1)
cmd = `{mshift $cmd}
- if (! ~ $#cmd 0)
- msg = (NOTICE $cmd(1) : `{mshift $cmd})
- case /T
- msg = (TOPIC `{mshift $cmd})
- case /W
- msg = (WHOIS `{mshift $cmd})
- case /a
- msg = (AWAY : `{mshift $cmd})
- case /j
- if (~ $#cmd 2) {
- target=$cmd(2)
- title
- msg = (JOIN `{mshift $cmd})
- if(~ $target *,*)
- target = `{echo $target | awk -F',' '{print $NF}'}
- }
- case /l
- msg = (LIST `{mshift $cmd})
- case /m
- cmd = `{mshift $cmd}
- if (! ~ $#cmd 0) {
- to = $cmd(1)
- cmd = `{mshift $cmd}
- out = '('^$to^') ⇐ '^$"cmd
- msg = 'PRIVMSG '^$to^' :'^$"cmd
- }
- case /n
- nick = `{mshift $cmd}
- msg = (NICK $nick)
- case /p
- cmd = `{mshift $cmd}
- if (! ~ $#cmd 0)
- msg = (PART $cmd(1) : `{mshift $cmd})
- case /q
- msg = `{mshift $cmd}
- case /t
- target = `{mshift $cmd}
- title
- case /u
- msg = (USERS `{mshift $cmd})
- case /w
- msg = (WHO `{mshift $cmd})
- case /x
- echo QUIT : Leaving... > $netdir/data
- exit
- case /*
- echo unknown command
- case *
- msg = 'PRIVMSG '^$target^' :'^$"cmd
- out = '('^$target^') ⇐ '^$"cmd
+ send_msg
+ target=$target_orig
}
- if (! ~ $#msg 0)
- echo $msg > $netdir/data
- if (! ~ $#out 0)
- echo `{etime}^' '^$out
+ case /n
+ nick = `{mshift $cmd}
+ msg = (NICK $nick)
+ case /p
+ cmd = `{mshift $cmd}
+ if (! ~ $#cmd 0)
+ msg = (PART $cmd(1) : `{mshift $cmd})
+ case /q
+ msg = `{mshift $cmd}
+ case /t
+ target = `{mshift $cmd}
+ title
+ case /u
+ msg = (USERS `{mshift $cmd})
+ case /w
+ msg = (WHO `{mshift $cmd})
+ case /x
+ echo QUIT : Leaving... > $netdir/data
+ exit
+ case /*
+ echo unknown command
+ case *
+ send_msg
}
+ if (! ~ $#msg 0)
+ echo $msg > $netdir/data
+ if (! ~ $#out 0)
+ echo `{etime}^' '^$out
+}
+
+fn send_msg {
+ prefixmsg='PRIVMSG '^$target^' :'
+ prefixout='('^$target^') ⇐ '
+ linelen=`{hoc -e 447^'-'^`{echo -n $prefixmsg | wc -c} }
+ ifs_orig=$ifs
+ ifs='\x04'
+ msg=`{echo -n $cmd | fmt -l $linelen | awk '{ printf "%s%s\n", ENVIRON["prefixmsg"], $0 }' }
+ out=`{echo $msg | sed s/$prefixmsg/$prefixout/ }
+ ifs=$ifs_orig
}
fn misc {
diff -r 0ee17db5d86b sys/man/1/ircrc
--- a/sys/man/1/ircrc Sat May 02 17:32:01 2020 +0200
+++ b/sys/man/1/ircrc Tue May 05 00:36:54 2020 -0700
@@ -152,6 +152,10 @@
command.
Control-D also sends this command.
.PP
+Any message containing more than the protocol's maximum allowed characters (447) is chunked into multiple messages using
+.I fmt(1)
+.
+.PP
See RFC 1459 and RFC 2812 for detailed information about
IRC commands.
.SH EXAMPLES
next prev parent reply other threads:[~2020-05-05 7:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-21 8:13 Romano
2020-05-05 3:08 ` Romano
2020-05-05 3:38 ` [9front] " ori
2020-05-05 7:43 ` Romano [this message]
2020-06-13 0:09 ` Romano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=26E4B111-656D-433B-B9A5-5D64A8DD47BF@cpan.org \
--to=unobe@cpan.org \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).