diff quotedb.tcl @ 684:5163d582e396

quotedb: Change voting a bit.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 28 Nov 2021 04:20:18 +0200
parents 7897b795480b
children bd7f06c8a515
line wrap: on
line diff
--- a/quotedb.tcl	Sun Oct 10 20:52:20 2021 +0300
+++ b/quotedb.tcl	Sun Nov 28 04:20:18 2021 +0200
@@ -264,17 +264,25 @@
     return 0
   }
 
-  set uvote 1
-  if {$utext == "" || [regexp {^\s*(-?1)\s*$} $utext -> uvote]} {
+  set qvote "+"
+  if {$utext == "" || [regexp {^\s*(\+|\-)\s*$} $utext -> qvote]} {
     set usql "SELECT max(id) AS qid FROM ${utable}"
     set uid 0
     qdb_handle eval $usql { set uid $qid }
   } elseif {[regexp {^\s*([0-9]+)$} $utext -> uid]} {
-  } elseif {![regexp {^\s*([0-9]+)\s+(-1|1)$} $utext -> uid uvote]} {
+  } elseif {![regexp {^\s*([0-9]+)\s+(\+|\-)$} $utext -> uid qvote]} {
     qdb_msg $ucmd $utable $upublic $unick $uchan "help_vote"
     return 0
   }
 
+  if {$qvote == "-"} {
+    set qvote [qdb_qm $utable "vote_down"]
+    set uvote -1
+  } else {
+    set qvote [qdb_qm $utable "vote_up"]
+    set uvote 1
+  }
+
   # Check if given quote ID exists.
   set uresults 0
   set usql "SELECT id AS qid FROM ${utable} WHERE id=$uid"
@@ -292,7 +300,7 @@
     if {[qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} {
       set urating [qdb_get_rating_for_id $utable $uid]
       qdb_log "${uhand} changed vote to ${uvote} on #${uid} / ${utable}, total ${urating}"
-      qdb_msg $ucmd $utable $upublic $unick $uchan "vote_updated" [list $uid $uvote $urating]
+      qdb_msg $ucmd $utable $upublic $unick $uchan "vote_updated" [list $uid $qvote $urating]
       return 1
     } else {
       return 0
@@ -304,7 +312,7 @@
   if {[qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} {
     set urating [qdb_get_rating_for_id $utable $uid]
     qdb_log "${uhand} voted ${uvote} on #${uid} / ${utable}, total ${urating}"
-    qdb_msg $ucmd $utable $upublic $unick $uchan "you_voted" [list $uid $uvote $urating]
+    qdb_msg $ucmd $utable $upublic $unick $uchan "you_voted" [list $uid $qvote $urating]
   }
 }