changeset 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 46fc0bc95195
files config.quotedb.example quotedb.tcl
diffstat 2 files changed, 20 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/config.quotedb.example	Sun Oct 10 20:52:20 2021 +0300
+++ b/config.quotedb.example	Sun Nov 28 04:20:18 2021 +0200
@@ -120,13 +120,15 @@
 
   "sql_error" "Virhe sörkittäessä @name@-tietokantaa. uliskaa."
 
-  "fmt_get"   "#@1@: @2@ (@3@@@4@, @5@)"
+  "fmt_get"   "#@1@: @2@ (@3@/@4@, @5@)"
 
-  "fmt_search" "#@1@: @2@ (@3@@@4@)"
+  "fmt_search" "#@1@: @2@ (@3@/@4@)"
   "no_matches" "@name@-haku ei tuottanut tuloksia."
 
-  "you_voted" "Äänestit @name@ #@1@ -> @2@, arvosana nyt @3@"
-  "vote_updated" "@name@-äänesi #@1@ päivitetty -> @2@, arvosana nyt @3@"
+  "you_voted" "Äänestit @name@ #@1@ @2@, arvosana nyt @3@"
+  "vote_updated" "@name@-äänesi #@1@ päivitetty @2@, arvosana nyt @3@"
+  "vote_up" "+"
+  "vote_down" "-"
 
   "add_success" "@name@-tietokantaa sörkitty (#@1@), kiitos."
 
@@ -147,7 +149,7 @@
   "help_add"       "@cmd@ add <teksti>"
   "help_update"    "@cmd@ update <id> <teksti>"
   "help_delete"    "@cmd@ del <id>"
-  "help_vote"      "@cmd@ vote \[\[<id>\] \[1|-1\]\]"
+  "help_vote"      "@cmd@ vote \[\[<id>\] \[+|-\]\]"
   "help_find"      "@cmd@ find [hakuparametrit] -- \[+\]sana | -sana | %käyttäjänimi"
 
   "quote_deleted"  "@name@ #@1@ poistettu@2@."
--- 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]
   }
 }