changeset 426:84d3d7abeb8a

Add utl_msg_do() function into utillib and refactor out similar things in quotedb and weather scripts.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 08 Jan 2017 04:04:35 +0200
parents e5810c52d376
children 86f39989df4b
files quotedb.tcl utillib.tcl weather.tcl
diffstat 3 files changed, 16 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/quotedb.tcl	Sun Jan 08 03:57:05 2017 +0200
+++ b/quotedb.tcl	Sun Jan 08 04:04:35 2017 +0200
@@ -48,24 +48,14 @@
   }
 }
 
-
-proc qdb_msg_do {apublic anick achan amsg} {
+proc qdb_msg {apublic anick achan amsg {aargs {}}} {
   global qdb_preferredmsg
-
-  if {$apublic == 0} {
-    putserv "$qdb_preferredmsg $anick :$amsg" 
-  } else {
-    putserv "$qdb_preferredmsg $achan :$amsg"
-  }
-}
-
-proc qdb_msg {apublic anick achan amsg {aargs {}}} {
   set narg 1
   foreach marg $aargs {
     set amsg [string map [list "%$narg" $marg] $amsg]
     incr narg
   }
-  qdb_msg_do $apublic $anick $achan $amsg
+  utl_msg_do $qdb_preferredmsg $apublic $anick $achan $amsg
 }
 
 
@@ -300,10 +290,7 @@
   }
 
   qdb_handle eval $usql {
-    set qtmp [utl_str_split "#${quoteID}: $utext ($uuser@[qdb_ctime $utime], $uvote)" 450]
-    foreach qstr $qtmp {
-      qdb_msg $upublic $unick $uchan $qstr
-    }
+    qdb_msg $upublic $unick $uchan "#${quoteID}: $utext ($uuser@[utl_ctime $utime], $uvote)"
     return 1
   }
 
--- a/utillib.tcl	Sun Jan 08 03:57:05 2017 +0200
+++ b/utillib.tcl	Sun Jan 08 04:04:35 2017 +0200
@@ -63,6 +63,17 @@
 }
 
 
+proc utl_msg_do {upreferredmsg upublic unick uchan umsg} {
+  foreach uline [utl_str_split $umsg 450] {
+    if {$apublic == 1} {
+      putserv "$upreferredmsg $uchan :$ulineg"
+    } else {
+      putserv "$upreferredmsg $unick :$uline"
+    }
+  }
+}
+
+
 proc utl_ctime {utime} {
   if {$utime == "" || $utime == "*"} {
     set utime 0
--- a/weather.tcl	Sun Jan 08 03:57:05 2017 +0200
+++ b/weather.tcl	Sun Jan 08 04:04:35 2017 +0200
@@ -41,23 +41,14 @@
 }
 
 
-proc weather_msg_do {apublic anick achan amsg} {
+proc weather_msg {apublic anick achan amsg {aargs {}}} {
   global weather_preferredmsg
-  if {$apublic == 1} {
-    putserv "$weather_preferredmsg $achan :$amsg"
-  } else {
-    putserv "$weather_preferredmsg $anick :$amsg"
-  }
-}
-
-
-proc weather_msg {apublic anick achan amsg {aargs {}}} {
   set narg 1
   foreach marg $aargs {
     set amsg [string map [list "%$narg" $marg] $amsg]
     incr narg
   }
-  weather_msg_do $apublic $anick $achan $amsg
+  utl_msg_do $weather_preferredmsg $apublic $anick $achan $amsg
 }