# HG changeset patch # User Matti Hamalainen # Date 1548419016 -7200 # Node ID 32f0aba3ab9bcac7bacaefb908ef9abba3567868 # Parent 6773d97a3de2bc541dea2bc66a356b5548b3d161 quotedb: Make more things configurable. diff -r 6773d97a3de2 -r 32f0aba3ab9b config.quotedb.example --- a/config.quotedb.example Sun Dec 30 04:17:27 2018 +0200 +++ b/config.quotedb.example Fri Jan 25 14:23:36 2019 +0200 @@ -77,6 +77,7 @@ set qdb_msg_not_found "%1 #%2 ei löydy, tai se ei kuulu käyttäjälle '%3'." +set qdb_msg_stats "%1-tilastot: %2 quotea, %3 annettua ääntä." set qdb_msg_help "%1 add |update |del |find |vote \[ <1|-1>\]|top3" @@ -88,21 +89,21 @@ # Bind !quote -command for table "quotedb" bind pub - !quote quote_pub_cmd bind msg - !quote quote_msg_cmd -proc quote_pub_cmd {unick uhost uhand uchan utext} { qdb_command "!quote" "quotedb" $unick $uhost $uhand $uchan $utext 1 } -proc quote_msg_cmd {unick uhost uhand utext} { qdb_command "quote" "quotedb" $unick $uhost $uhand "" $utext 0 } +proc quote_pub_cmd {unick uhost uhand uchan utext} { qdb_command "!quote" "quotedb" $unick $uhost $uhand $uchan $utext 1 ""} +proc quote_msg_cmd {unick uhost uhand utext} { qdb_command "!quote" "quotedb" $unick $uhost $uhand "" $utext 0 ""} bind pub - !spede spede_pub_cmd bind msg - !spede spede_msg_cmd -proc spede_pub_cmd {unick uhost uhand uchan utext} { qdb_command "!spede" "spededb" $unick $uhost $uhand $uchan $utext 1 } -proc spede_msg_cmd {unick uhost uhand utext} { qdb_command "spede" "spededb" $unick $uhost $uhand "" $utext 0 } +proc spede_pub_cmd {unick uhost uhand uchan utext} { qdb_command "!spede" "spededb" $unick $uhost $uhand $uchan $utext 1 ""} +proc spede_msg_cmd {unick uhost uhand utext} { qdb_command "!spede" "spededb" $unick $uhost $uhand "" $utext 0 ""} bind pub - !mn mn_pub_cmd bind msg - !mn mn_msg_cmd -proc mn_pub_cmd {unick uhost uhand uchan utext} { qdb_command "!mn" "mndb" $unick $uhost $uhand $uchan $utext 1 } -proc mn_msg_cmd {unick uhost uhand utext} { qdb_command "mn" "mndb" $unick $uhost $uhand "" $utext 0 } +proc mn_pub_cmd {unick uhost uhand uchan utext} { qdb_command "!mn" "mndb" $unick $uhost $uhand $uchan $utext 1 ""} +proc mn_msg_cmd {unick uhost uhand utext} { qdb_command "!mn" "mndb" $unick $uhost $uhand "" $utext 0 ""} bind pub - !tuksu tuksu_pub_cmd bind msg - !tuksu tuksu_msg_cmd -proc tuksu_pub_cmd {unick uhost uhand uchan utext} { qdb_command "!tuksu" "tuksudb" $unick $uhost $uhand $uchan $utext 1 } -proc tuksu_msg_cmd {unick uhost uhand utext} { qdb_command "tuksu" "tuksudb" $unick $uhost $uhand "" $utext 0 } +proc tuksu_pub_cmd {unick uhost uhand uchan utext} { qdb_command "!tuksu" "tuksudb" $unick $uhost $uhand $uchan $utext 1 ""} +proc tuksu_msg_cmd {unick uhost uhand utext} { qdb_command "!tuksu" "tuksudb" $unick $uhost $uhand "" $utext 0 ""} diff -r 6773d97a3de2 -r 32f0aba3ab9b quotedb.tcl --- a/quotedb.tcl Sun Dec 30 04:17:27 2018 +0200 +++ b/quotedb.tcl Fri Jan 25 14:23:36 2019 +0200 @@ -206,7 +206,7 @@ #------------------------------------------------------------------------- -proc qdb_toplist {ucmd utable unick uchan unum upublic} { +proc qdb_toplist {utable unick uchan unum upublic} { global qdb_handle qdb_msg_toplist_limit qdb_msg_toplist_fmt if {$unum < 2 || $unum > 5} { @@ -288,7 +288,7 @@ #------------------------------------------------------------------------- -proc qdb_get {ucmd utable unick uchan uindex upublic} { +proc qdb_get {ufmt utable unick uchan uindex upublic} { global qdb_handle qdb_msg_no_matches 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" @@ -307,7 +307,11 @@ } qdb_handle eval $usql { - qdb_msg $upublic $unick $uchan "#${quoteID}: $utext ($uuser@[utl_ctime $utime], $uvote)" + if {$ufmt != ""} { + qdb_msg $upublic $unick $uchan $ufmt [list $quoteID $utext $uuser [utl_ctime $utime] $uvote] + } else { + qdb_msg $upublic $unick $uchan "#${quoteID}: $utext ($uuser@[utl_ctime $utime], $uvote)" + } return 1 } @@ -317,8 +321,8 @@ #------------------------------------------------------------------------- -proc qdb_stats {ucmd utable unick uchan upublic} { - global qdb_handle +proc qdb_stats {utable unick uchan upublic} { + global qdb_handle qdb_msg_stats set usql "SELECT count(*) AS nvotes FROM ${utable}_votes" qdb_handle eval $usql {} @@ -326,13 +330,13 @@ set usql "SELECT count(*) AS nquotes FROM ${utable}" qdb_handle eval $usql {} - qdb_msg $upublic $unick $uchan "${utable}-tilastot: ${nquotes} quotea, ${nvotes} annettua ääntä." + qdb_msg $upublic $unick $uchan $qdb_msg_stats [list $utable $nquotes $nvotes] return 0 } #------------------------------------------------------------------------- -proc qdb_find {ucmd utable unick uhand uchan utext upublic} { +proc qdb_find {utable unick uhand uchan utext upublic} { global qdb_handle qdb_showmax_pub qdb_showmax_priv qdb_msg_no_matches qdb_msg_search_fmt if {$upublic == 0} { @@ -385,7 +389,7 @@ #------------------------------------------------------------------------- -proc qdb_command {ucmd utable unick uhost uhand uchan utext upublic} { +proc qdb_command {ucmd utable unick uhost uhand uchan utext upublic ufmt_get} { global qdb_msg_help qdb_channels if {$upublic && ![utl_match_delim_list $qdb_channels $uchan]} { @@ -396,19 +400,19 @@ if {$utext == "" || $utext == {}} { # No arguments, assume random query - qdb_get $ucmd $utable $unick $uchan -1 $upublic + qdb_get $ufmt_get $utable $unick $uchan -1 $upublic } elseif {[regexp {^(stat|stats|tilasto|tilastot)$} $utext umatch]} { # Statistics - qdb_stats $ucmd $utable $unick $uchan $upublic + qdb_stats $utable $unick $uchan $upublic } elseif {[regexp {^(last|latest|uusin|viimeisin)$} $utext umatch]} { # Latest added - qdb_get $ucmd $utable $unick $uchan -2 $upublic + qdb_get $ufmt_get $utable $unick $uchan -2 $upublic } elseif {[regexp {^([0-9]+)$} $utext umatch unum]} { # Numeric argument, assume index query - qdb_get $ucmd $utable $unick $uchan $unum $upublic + qdb_get $ufmt_get $utable $unick $uchan $unum $upublic } elseif {[regexp {^top\s*([0-9]+)$} $utext umatch unum]} { # Toplist of quotes - qdb_toplist $ucmd $utable $unick $uchan $unum $upublic + qdb_toplist $utable $unick $uchan $unum $upublic } elseif {[regexp {^add\s*(.*)$} $utext umatch unum]} { # Add quote qdb_add $ucmd $utable $unick $uhost $uhand $uchan $unum $upublic @@ -420,7 +424,7 @@ 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 + qdb_find $utable $unick $uhand $uchan $unum $upublic } elseif {[regexp {^vote\s*(.*)$} $utext umatch unum]} { # Vote qdb_vote $ucmd $utable $unick $uhand $uchan $unum $upublic