diff quotedb.tcl @ 478:32f0aba3ab9b

quotedb: Make more things configurable.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 25 Jan 2019 14:23:36 +0200
parents a8eb80bbffa5
children 0e50c8440ea2
line wrap: on
line diff
--- a/quotedb.tcl	Sun Dec 30 04:17:27 2018 +0200
+++ b/quotedb.tcl	Fri Jan 25 14:23:36 2019 +0200
@@ -206,7 +206,7 @@
 
 
 #-------------------------------------------------------------------------
-proc qdb_toplist {ucmd utable unick uchan unum upublic} {
+proc qdb_toplist {utable unick uchan unum upublic} {
   global qdb_handle qdb_msg_toplist_limit qdb_msg_toplist_fmt
 
   if {$unum < 2 || $unum > 5} {
@@ -288,7 +288,7 @@
 
 
 #-------------------------------------------------------------------------
-proc qdb_get {ucmd utable unick uchan uindex upublic} {
+proc qdb_get {ufmt utable unick uchan uindex upublic} {
   global qdb_handle qdb_msg_no_matches
 
   set usql "SELECT total(${utable}_votes.vote) AS uvote, ${utable}.id AS quoteID, ${utable}.utext AS utext, ${utable}.utime AS utime, ${utable}.user AS uuser FROM ${utable} LEFT JOIN ${utable}_votes ON ${utable}_votes.urlid = ${utable}.id"
@@ -307,7 +307,11 @@
   }
 
   qdb_handle eval $usql {
-    qdb_msg $upublic $unick $uchan "#${quoteID}: $utext ($uuser@[utl_ctime $utime], $uvote)"
+    if {$ufmt != ""} {
+      qdb_msg $upublic $unick $uchan $ufmt [list $quoteID $utext $uuser [utl_ctime $utime] $uvote]
+    } else {
+      qdb_msg $upublic $unick $uchan "#${quoteID}: $utext ($uuser@[utl_ctime $utime], $uvote)"
+    }
     return 1
   }
 
@@ -317,8 +321,8 @@
 
 
 #-------------------------------------------------------------------------
-proc qdb_stats {ucmd utable unick uchan upublic} {
-  global qdb_handle
+proc qdb_stats {utable unick uchan upublic} {
+  global qdb_handle qdb_msg_stats
 
   set usql "SELECT count(*) AS nvotes FROM ${utable}_votes"
   qdb_handle eval $usql {}
@@ -326,13 +330,13 @@
   set usql "SELECT count(*) AS nquotes FROM ${utable}"
   qdb_handle eval $usql {}
 
-  qdb_msg $upublic $unick $uchan "${utable}-tilastot: ${nquotes} quotea, ${nvotes} annettua ääntä."
+  qdb_msg $upublic $unick $uchan $qdb_msg_stats [list $utable $nquotes $nvotes]
   return 0
 }
 
 
 #-------------------------------------------------------------------------
-proc qdb_find {ucmd utable unick uhand uchan utext upublic} {
+proc qdb_find {utable unick uhand uchan utext upublic} {
   global qdb_handle qdb_showmax_pub qdb_showmax_priv qdb_msg_no_matches qdb_msg_search_fmt
 
   if {$upublic == 0} {
@@ -385,7 +389,7 @@
 
 
 #-------------------------------------------------------------------------
-proc qdb_command {ucmd utable unick uhost uhand uchan utext upublic} {
+proc qdb_command {ucmd utable unick uhost uhand uchan utext upublic ufmt_get} {
   global qdb_msg_help qdb_channels
 
   if {$upublic && ![utl_match_delim_list $qdb_channels $uchan]} {
@@ -396,19 +400,19 @@
 
   if {$utext == "" || $utext == {}} {
     # No arguments, assume random query
-    qdb_get $ucmd $utable $unick $uchan -1 $upublic
+    qdb_get $ufmt_get $utable $unick $uchan -1 $upublic
   } elseif {[regexp {^(stat|stats|tilasto|tilastot)$} $utext umatch]} {
     # Statistics
-    qdb_stats $ucmd $utable $unick $uchan $upublic
+    qdb_stats $utable $unick $uchan $upublic
   } elseif {[regexp {^(last|latest|uusin|viimeisin)$} $utext umatch]} {
     # Latest added
-    qdb_get $ucmd $utable $unick $uchan -2 $upublic
+    qdb_get $ufmt_get $utable $unick $uchan -2 $upublic
   } elseif {[regexp {^([0-9]+)$} $utext umatch unum]} {
     # Numeric argument, assume index query
-    qdb_get $ucmd $utable $unick $uchan $unum $upublic
+    qdb_get $ufmt_get $utable $unick $uchan $unum $upublic
   } elseif {[regexp {^top\s*([0-9]+)$} $utext umatch unum]} {
     # Toplist of quotes
-    qdb_toplist $ucmd $utable $unick $uchan $unum $upublic
+    qdb_toplist $utable $unick $uchan $unum $upublic
   } elseif {[regexp {^add\s*(.*)$} $utext umatch unum]} {
     # Add quote
     qdb_add $ucmd $utable $unick $uhost $uhand $uchan $unum $upublic
@@ -420,7 +424,7 @@
     qdb_update $ucmd $utable $unick $uhand $uchan $unum $upublic
   } elseif {[regexp {^find\s*(.*)$} $utext umatch unum]} {
     # Find quote(s)
-    qdb_find $ucmd $utable $unick $uhand $uchan $unum $upublic
+    qdb_find $utable $unick $uhand $uchan $unum $upublic
   } elseif {[regexp {^vote\s*(.*)$} $utext umatch unum]} {
     # Vote
     qdb_vote $ucmd $utable $unick $uhand $uchan $unum $upublic