Mercurial > hg > egg-tcls
comparison 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 |
comparison
equal
deleted
inserted
replaced
683:7897b795480b | 684:5163d582e396 |
---|---|
262 | 262 |
263 if {![qdb_valid_user $ucmd $utable $upublic $unick $uchan $uhand]} { | 263 if {![qdb_valid_user $ucmd $utable $upublic $unick $uchan $uhand]} { |
264 return 0 | 264 return 0 |
265 } | 265 } |
266 | 266 |
267 set uvote 1 | 267 set qvote "+" |
268 if {$utext == "" || [regexp {^\s*(-?1)\s*$} $utext -> uvote]} { | 268 if {$utext == "" || [regexp {^\s*(\+|\-)\s*$} $utext -> qvote]} { |
269 set usql "SELECT max(id) AS qid FROM ${utable}" | 269 set usql "SELECT max(id) AS qid FROM ${utable}" |
270 set uid 0 | 270 set uid 0 |
271 qdb_handle eval $usql { set uid $qid } | 271 qdb_handle eval $usql { set uid $qid } |
272 } elseif {[regexp {^\s*([0-9]+)$} $utext -> uid]} { | 272 } elseif {[regexp {^\s*([0-9]+)$} $utext -> uid]} { |
273 } elseif {![regexp {^\s*([0-9]+)\s+(-1|1)$} $utext -> uid uvote]} { | 273 } elseif {![regexp {^\s*([0-9]+)\s+(\+|\-)$} $utext -> uid qvote]} { |
274 qdb_msg $ucmd $utable $upublic $unick $uchan "help_vote" | 274 qdb_msg $ucmd $utable $upublic $unick $uchan "help_vote" |
275 return 0 | 275 return 0 |
276 } | |
277 | |
278 if {$qvote == "-"} { | |
279 set qvote [qdb_qm $utable "vote_down"] | |
280 set uvote -1 | |
281 } else { | |
282 set qvote [qdb_qm $utable "vote_up"] | |
283 set uvote 1 | |
276 } | 284 } |
277 | 285 |
278 # Check if given quote ID exists. | 286 # Check if given quote ID exists. |
279 set uresults 0 | 287 set uresults 0 |
280 set usql "SELECT id AS qid FROM ${utable} WHERE id=$uid" | 288 set usql "SELECT id AS qid FROM ${utable} WHERE id=$uid" |
290 # Yes, update the previous vote | 298 # Yes, update the previous vote |
291 set usql "UPDATE ${utable}_votes SET vote=$uvote WHERE id=$qid" | 299 set usql "UPDATE ${utable}_votes SET vote=$uvote WHERE id=$qid" |
292 if {[qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} { | 300 if {[qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} { |
293 set urating [qdb_get_rating_for_id $utable $uid] | 301 set urating [qdb_get_rating_for_id $utable $uid] |
294 qdb_log "${uhand} changed vote to ${uvote} on #${uid} / ${utable}, total ${urating}" | 302 qdb_log "${uhand} changed vote to ${uvote} on #${uid} / ${utable}, total ${urating}" |
295 qdb_msg $ucmd $utable $upublic $unick $uchan "vote_updated" [list $uid $uvote $urating] | 303 qdb_msg $ucmd $utable $upublic $unick $uchan "vote_updated" [list $uid $qvote $urating] |
296 return 1 | 304 return 1 |
297 } else { | 305 } else { |
298 return 0 | 306 return 0 |
299 } | 307 } |
300 } | 308 } |
302 # No previous votes, insert new | 310 # No previous votes, insert new |
303 set usql "INSERT INTO ${utable}_votes (user,urlid,vote) VALUES ('[utl_escape $uhand]',$uid,$uvote)" | 311 set usql "INSERT INTO ${utable}_votes (user,urlid,vote) VALUES ('[utl_escape $uhand]',$uid,$uvote)" |
304 if {[qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} { | 312 if {[qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} { |
305 set urating [qdb_get_rating_for_id $utable $uid] | 313 set urating [qdb_get_rating_for_id $utable $uid] |
306 qdb_log "${uhand} voted ${uvote} on #${uid} / ${utable}, total ${urating}" | 314 qdb_log "${uhand} voted ${uvote} on #${uid} / ${utable}, total ${urating}" |
307 qdb_msg $ucmd $utable $upublic $unick $uchan "you_voted" [list $uid $uvote $urating] | 315 qdb_msg $ucmd $utable $upublic $unick $uchan "you_voted" [list $uid $qvote $urating] |
308 } | 316 } |
309 } | 317 } |
310 | 318 |
311 | 319 |
312 #------------------------------------------------------------------------- | 320 #------------------------------------------------------------------------- |