changeset 528:20a1b0f39f71

utillib: Add new helper functions.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 07 Jul 2020 14:20:55 +0300
parents 461be6f596bd
children 3046ee0e574d
files utillib.tcl
diffstat 1 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/utillib.tcl	Tue Jul 07 14:20:36 2020 +0300
+++ b/utillib.tcl	Tue Jul 07 14:20:55 2020 +0300
@@ -68,6 +68,14 @@
 }
 
 
+proc utl_valid_user {uhand} {
+  if {$uhand != "" && $uhand != "{}" && $uhand != "*"} {
+    return 1
+  }
+  return 0
+}
+
+
 # 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} {
@@ -81,6 +89,23 @@
 }
 
 
+proc utl_msg_args {upreferredmsg upublic unick uchan umsg {uargs {}}} {
+
+  # Map constant 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
+  }
+
+  utl_msg_do $upreferredmsg $upublic $unick $uchan $umsg
+}
+
+
 # Return formatted time for given UNIX timestamp
 proc utl_ctime {utime} {
   if {$utime == "" || $utime == "*"} {