comparison quotedb.tcl @ 465:ba7ed8f6d2ab

quotedb: Add get latest quote feature.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 22 Feb 2018 20:15:20 +0200
parents 6acd372d36da
children a8eb80bbffa5
comparison
equal deleted inserted replaced
464:506977ea9d0c 465:ba7ed8f6d2ab
293 293
294 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" 294 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"
295 if {$uindex >= 0} { 295 if {$uindex >= 0} {
296 append usql " WHERE ${utable}.id=$uindex GROUP BY ${utable}.id" 296 append usql " WHERE ${utable}.id=$uindex GROUP BY ${utable}.id"
297 qdb_log "$unick searched $utable #$uindex" 297 qdb_log "$unick searched $utable #$uindex"
298 } else { 298 } elseif {$uindex == -1} {
299 append usql " GROUP BY ${utable}.id ORDER BY RANDOM() LIMIT 1" 299 append usql " GROUP BY ${utable}.id ORDER BY RANDOM() LIMIT 1"
300 qdb_log "$unick get random $utable" 300 qdb_log "$unick get random $utable"
301 } elseif {$uindex == -2} {
302 append usql " GROUP BY ${utable}.id ORDER BY ${utable}.id DESC LIMIT 1"
303 qdb_log "$unick get latest $utable"
304 } else {
305 qdb_log "$unick invalid qdb_get $utable index value."
306 return 0
301 } 307 }
302 308
303 qdb_handle eval $usql { 309 qdb_handle eval $usql {
304 qdb_msg $upublic $unick $uchan "#${quoteID}: $utext ($uuser@[utl_ctime $utime], $uvote)" 310 qdb_msg $upublic $unick $uchan "#${quoteID}: $utext ($uuser@[utl_ctime $utime], $uvote)"
305 return 1 311 return 1
374 set utext [string trim $utext] 380 set utext [string trim $utext]
375 381
376 if {$utext == "" || $utext == {}} { 382 if {$utext == "" || $utext == {}} {
377 # No arguments, assume random query 383 # No arguments, assume random query
378 qdb_get $ucmd $utable $unick $uchan -1 $upublic 384 qdb_get $ucmd $utable $unick $uchan -1 $upublic
385 } elseif {[regexp {^(last|latest|uusin|viimeisin)$} $utext umatch]} {
386 # Latest added
387 qdb_get $ucmd $utable $unick $uchan -2 $upublic
379 } elseif {[regexp {^([0-9]+)$} $utext umatch unum]} { 388 } elseif {[regexp {^([0-9]+)$} $utext umatch unum]} {
380 # Numeric argument, assume index query 389 # Numeric argument, assume index query
381 qdb_get $ucmd $utable $unick $uchan $unum $upublic 390 qdb_get $ucmd $utable $unick $uchan $unum $upublic
382 } elseif {[regexp {^top\s*([0-9]+)$} $utext umatch unum]} { 391 } elseif {[regexp {^top\s*([0-9]+)$} $utext umatch unum]} {
383 # Toplist of quotes 392 # Toplist of quotes
396 qdb_find $ucmd $utable $unick $uhand $uchan $unum $upublic 405 qdb_find $ucmd $utable $unick $uhand $uchan $unum $upublic
397 } elseif {[regexp {^vote\s*(.*)$} $utext umatch unum]} { 406 } elseif {[regexp {^vote\s*(.*)$} $utext umatch unum]} {
398 # Vote 407 # Vote
399 qdb_vote $ucmd $utable $unick $uhand $uchan $unum $upublic 408 qdb_vote $ucmd $utable $unick $uhand $uchan $unum $upublic
400 } else { 409 } else {
410 # Help/usage
401 qdb_msg $upublic $unick $uchan $qdb_msg_help [list $ucmd] 411 qdb_msg $upublic $unick $uchan $qdb_msg_help [list $ucmd]
402 } 412 }
403 } 413 }
404 414
405 #------------------------------------------------------------------------- 415 #-------------------------------------------------------------------------