changeset 465:ba7ed8f6d2ab

quotedb: Add get latest quote feature.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 22 Feb 2018 20:15:20 +0200
parents 506977ea9d0c
children a8eb80bbffa5
files quotedb.tcl
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/quotedb.tcl	Wed Feb 07 19:01:36 2018 +0200
+++ b/quotedb.tcl	Thu Feb 22 20:15:20 2018 +0200
@@ -295,9 +295,15 @@
   if {$uindex >= 0} {
     append usql " WHERE ${utable}.id=$uindex GROUP BY ${utable}.id"
     qdb_log "$unick searched $utable #$uindex"
-  } else {
+  } elseif {$uindex == -1} {
     append usql " GROUP BY ${utable}.id ORDER BY RANDOM() LIMIT 1"
     qdb_log "$unick get random $utable"
+  } elseif {$uindex == -2} {
+    append usql " GROUP BY ${utable}.id ORDER BY ${utable}.id DESC LIMIT 1"
+    qdb_log "$unick get latest $utable"
+  } else {
+    qdb_log "$unick invalid qdb_get $utable index value."
+    return 0
   }
 
   qdb_handle eval $usql {
@@ -376,6 +382,9 @@
   if {$utext == "" || $utext == {}} {
     # No arguments, assume random query
     qdb_get $ucmd $utable $unick $uchan -1 $upublic
+  } elseif {[regexp {^(last|latest|uusin|viimeisin)$} $utext umatch]} {
+    # Latest added
+    qdb_get $ucmd $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
@@ -398,6 +407,7 @@
     # Vote
     qdb_vote $ucmd $utable $unick $uhand $uchan $unum $upublic
   } else {
+    # Help/usage
     qdb_msg $upublic $unick $uchan $qdb_msg_help [list $ucmd]
   }
 }