Mercurial > hg > egg-tcls
changeset 539:c9dc79874939
utillib: Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 07 Jul 2020 22:08:43 +0300 |
parents | f07c972e269a |
children | 3174701325c0 |
files | utillib.tcl |
diffstat | 1 files changed, 24 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/utillib.tcl Tue Jul 07 21:59:30 2020 +0300 +++ b/utillib.tcl Tue Jul 07 22:08:43 2020 +0300 @@ -79,34 +79,45 @@ # Send IRC message with given message type, splitting the # string to fit to IRCNet (etc.) max message length. proc utl_msg_do {upreferredmsg upublic unick uchan umsg} { - foreach uline [utl_str_split $umsg 450] { - if {$upublic == 1} { - putserv "$upreferredmsg $uchan :$uline" - } else { - putserv "$upreferredmsg $unick :$uline" + # Split message per line + foreach qmsg [split $umsg "\n"] { + # Split each line to fit max message limit + foreach uline [utl_str_split $qmsg 445] { + if {$upublic == 1} { + putserv "$upreferredmsg $uchan :$uline" + } else { + putserv "$upreferredmsg $unick :$uline" + } } } } +# Substitute @n@ -> uvalues{n} in the ustr +proc utl_str_map_values {ustr {uvalues {}}} { + set narg 1 + foreach marg $uvalues { + set ustr [string map [list "@$narg@" $marg] $ustr] + incr narg + } + return $ustr +} + + proc utl_msg_args {upreferredmsg upublic unick uchan umsg {uargs {}}} { - # Map constant tokens + # Replace named tokens set umsg [string map [list "@nick@" $unick] $umsg] set umsg [string map [list "@chan@" $uchan] $umsg] - # Map numeric tokens - set narg 1 - foreach marg $uargs { - set umsg [string map [list "@$narg@" $marg] $umsg] - incr narg - } + # Replace numeric tokens + set umsg [utl_str_map_values $umsg $uargs] utl_msg_do $upreferredmsg $upublic $unick $uchan $umsg } -# Return formatted time for given UNIX timestamp +# Return formatted time string for given UNIX timestamp proc utl_ctime {utime} { if {$utime == "" || $utime == "*"} { set utime 0