# HG changeset patch # User Matti Hamalainen # Date 1315509414 -10800 # Node ID ce327469582c79509f1b12edacf005e9039fa922 # Parent 415c47fcc51842ea6d0869b09501c93ff820f58c quotedb: Add "update" sub-command for modifying/updating recently added quotes. diff -r 415c47fcc518 -r ce327469582c quotedb.tcl --- a/quotedb.tcl Thu Sep 08 22:16:00 2011 +0300 +++ b/quotedb.tcl Thu Sep 08 22:16:54 2011 +0300 @@ -29,6 +29,7 @@ # Foo. set qdb_max_deltime 15 +set qdb_max_modtime 30 ### ### Search related settings @@ -227,6 +228,43 @@ #------------------------------------------------------------------------- +proc qdb_update {ucmd utable unick uhand uchan utext upublic} { + global quotedb qdb_max_modtime + set maxdiff [expr $qdb_max_modtime * 60] + + if {$uhand == "" || $uhand == {}} { + qdb_msg $upublic $unick $uchan "pyh." + return 0 + } + + if {![regexp {^\s*([0-9]+)\s+(.+)$} $utext umatch unum uquote]} { + qdb_msg $upublic $unick $uchan "$ucmd update " + return 0 + } + + set usql "SELECT utime AS utime FROM $utable WHERE id=$unum AND user='[qdb_escape $uhand]'" + quotedb eval $usql { + set udiff [expr [unixtime] - $utime] + if {$udiff < $maxdiff} { + set usql "UPDATE $utable SET utext='[qdb_escape $uquote]', utime=[unixtime] WHERE id=$unum" + if {![qdb_sql_exec $upublic $unick $uchan $usql]} { + return 0 + } else { + qdb_msg $upublic $unick $uchan "$utable #$unum päivitetty." + return 1 + } + } else { + qdb_msg $upublic $unick $uchan "$utable quote #$unum vanhempi kuin $qdb_max_modtime minuuttia, ei voida päivittää." + return 0 + } + } + + qdb_msg $upublic $unick $uchan "#$unum ei löydy, tai se ei kuulu käyttäjälle '$uhand'." + return 0 +} + + +#------------------------------------------------------------------------- proc qdb_toplist {ucmd utable unick uchan unum upublic} { global quotedb @@ -401,6 +439,9 @@ } elseif {[regexp {^del\s*([0-9]*)$} $utext umatch unum]} { # Delete quote qdb_delete $ucmd $utable $unick $uhand $uchan $unum $upublic + } elseif {[regexp {^update\s*(.*)$} $utext umatch unum]} { + # Modify/update quote + qdb_update $ucmd $utable $unick $uhand $uchan $unum $upublic } elseif {[regexp {^find\s*(.*)$} $utext umatch unum]} { # Find quote(s) qdb_find $ucmd $utable $unick $uhand $uchan $unum $upublic @@ -408,7 +449,7 @@ # Vote qdb_vote $ucmd $utable $unick $uhand $uchan $unum $upublic } else { - qdb_msg $upublic $unick $uchan "$ucmd add |del |find |vote|top3" + qdb_msg $upublic $unick $uchan "$ucmd add |update |del |find |vote|top3" } }