comparison quotedb.tcl @ 478:32f0aba3ab9b

quotedb: Make more things configurable.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 25 Jan 2019 14:23:36 +0200
parents a8eb80bbffa5
children 0e50c8440ea2
comparison
equal deleted inserted replaced
477:6773d97a3de2 478:32f0aba3ab9b
204 return 0 204 return 0
205 } 205 }
206 206
207 207
208 #------------------------------------------------------------------------- 208 #-------------------------------------------------------------------------
209 proc qdb_toplist {ucmd utable unick uchan unum upublic} { 209 proc qdb_toplist {utable unick uchan unum upublic} {
210 global qdb_handle qdb_msg_toplist_limit qdb_msg_toplist_fmt 210 global qdb_handle qdb_msg_toplist_limit qdb_msg_toplist_fmt
211 211
212 if {$unum < 2 || $unum > 5} { 212 if {$unum < 2 || $unum > 5} {
213 qdb_msg $upublic $unick $uchan $qdb_msg_toplist_limit [list 2 5] 213 qdb_msg $upublic $unick $uchan $qdb_msg_toplist_limit [list 2 5]
214 return 0 214 return 0
286 } 286 }
287 } 287 }
288 288
289 289
290 #------------------------------------------------------------------------- 290 #-------------------------------------------------------------------------
291 proc qdb_get {ucmd utable unick uchan uindex upublic} { 291 proc qdb_get {ufmt utable unick uchan uindex upublic} {
292 global qdb_handle qdb_msg_no_matches 292 global qdb_handle qdb_msg_no_matches
293 293
294 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" 294 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"
295 if {$uindex >= 0} { 295 if {$uindex >= 0} {
296 append usql " WHERE ${utable}.id=$uindex GROUP BY ${utable}.id" 296 append usql " WHERE ${utable}.id=$uindex GROUP BY ${utable}.id"
305 qdb_log "$unick invalid qdb_get $utable index value." 305 qdb_log "$unick invalid qdb_get $utable index value."
306 return 0 306 return 0
307 } 307 }
308 308
309 qdb_handle eval $usql { 309 qdb_handle eval $usql {
310 qdb_msg $upublic $unick $uchan "#${quoteID}: $utext ($uuser@[utl_ctime $utime], $uvote)" 310 if {$ufmt != ""} {
311 qdb_msg $upublic $unick $uchan $ufmt [list $quoteID $utext $uuser [utl_ctime $utime] $uvote]
312 } else {
313 qdb_msg $upublic $unick $uchan "#${quoteID}: $utext ($uuser@[utl_ctime $utime], $uvote)"
314 }
311 return 1 315 return 1
312 } 316 }
313 317
314 qdb_msg $upublic $unick $uchan $qdb_msg_no_matches [list $unick] 318 qdb_msg $upublic $unick $uchan $qdb_msg_no_matches [list $unick]
315 return 0 319 return 0
316 } 320 }
317 321
318 322
319 #------------------------------------------------------------------------- 323 #-------------------------------------------------------------------------
320 proc qdb_stats {ucmd utable unick uchan upublic} { 324 proc qdb_stats {utable unick uchan upublic} {
321 global qdb_handle 325 global qdb_handle qdb_msg_stats
322 326
323 set usql "SELECT count(*) AS nvotes FROM ${utable}_votes" 327 set usql "SELECT count(*) AS nvotes FROM ${utable}_votes"
324 qdb_handle eval $usql {} 328 qdb_handle eval $usql {}
325 329
326 set usql "SELECT count(*) AS nquotes FROM ${utable}" 330 set usql "SELECT count(*) AS nquotes FROM ${utable}"
327 qdb_handle eval $usql {} 331 qdb_handle eval $usql {}
328 332
329 qdb_msg $upublic $unick $uchan "${utable}-tilastot: ${nquotes} quotea, ${nvotes} annettua ääntä." 333 qdb_msg $upublic $unick $uchan $qdb_msg_stats [list $utable $nquotes $nvotes]
330 return 0 334 return 0
331 } 335 }
332 336
333 337
334 #------------------------------------------------------------------------- 338 #-------------------------------------------------------------------------
335 proc qdb_find {ucmd utable unick uhand uchan utext upublic} { 339 proc qdb_find {utable unick uhand uchan utext upublic} {
336 global qdb_handle qdb_showmax_pub qdb_showmax_priv qdb_msg_no_matches qdb_msg_search_fmt 340 global qdb_handle qdb_showmax_pub qdb_showmax_priv qdb_msg_no_matches qdb_msg_search_fmt
337 341
338 if {$upublic == 0} { 342 if {$upublic == 0} {
339 set ulimit $qdb_showmax_priv 343 set ulimit $qdb_showmax_priv
340 } else { 344 } else {
383 return 1 387 return 1
384 } 388 }
385 389
386 390
387 #------------------------------------------------------------------------- 391 #-------------------------------------------------------------------------
388 proc qdb_command {ucmd utable unick uhost uhand uchan utext upublic} { 392 proc qdb_command {ucmd utable unick uhost uhand uchan utext upublic ufmt_get} {
389 global qdb_msg_help qdb_channels 393 global qdb_msg_help qdb_channels
390 394
391 if {$upublic && ![utl_match_delim_list $qdb_channels $uchan]} { 395 if {$upublic && ![utl_match_delim_list $qdb_channels $uchan]} {
392 return 0 396 return 0
393 } 397 }
394 398
395 set utext [string trim $utext] 399 set utext [string trim $utext]
396 400
397 if {$utext == "" || $utext == {}} { 401 if {$utext == "" || $utext == {}} {
398 # No arguments, assume random query 402 # No arguments, assume random query
399 qdb_get $ucmd $utable $unick $uchan -1 $upublic 403 qdb_get $ufmt_get $utable $unick $uchan -1 $upublic
400 } elseif {[regexp {^(stat|stats|tilasto|tilastot)$} $utext umatch]} { 404 } elseif {[regexp {^(stat|stats|tilasto|tilastot)$} $utext umatch]} {
401 # Statistics 405 # Statistics
402 qdb_stats $ucmd $utable $unick $uchan $upublic 406 qdb_stats $utable $unick $uchan $upublic
403 } elseif {[regexp {^(last|latest|uusin|viimeisin)$} $utext umatch]} { 407 } elseif {[regexp {^(last|latest|uusin|viimeisin)$} $utext umatch]} {
404 # Latest added 408 # Latest added
405 qdb_get $ucmd $utable $unick $uchan -2 $upublic 409 qdb_get $ufmt_get $utable $unick $uchan -2 $upublic
406 } elseif {[regexp {^([0-9]+)$} $utext umatch unum]} { 410 } elseif {[regexp {^([0-9]+)$} $utext umatch unum]} {
407 # Numeric argument, assume index query 411 # Numeric argument, assume index query
408 qdb_get $ucmd $utable $unick $uchan $unum $upublic 412 qdb_get $ufmt_get $utable $unick $uchan $unum $upublic
409 } elseif {[regexp {^top\s*([0-9]+)$} $utext umatch unum]} { 413 } elseif {[regexp {^top\s*([0-9]+)$} $utext umatch unum]} {
410 # Toplist of quotes 414 # Toplist of quotes
411 qdb_toplist $ucmd $utable $unick $uchan $unum $upublic 415 qdb_toplist $utable $unick $uchan $unum $upublic
412 } elseif {[regexp {^add\s*(.*)$} $utext umatch unum]} { 416 } elseif {[regexp {^add\s*(.*)$} $utext umatch unum]} {
413 # Add quote 417 # Add quote
414 qdb_add $ucmd $utable $unick $uhost $uhand $uchan $unum $upublic 418 qdb_add $ucmd $utable $unick $uhost $uhand $uchan $unum $upublic
415 } elseif {[regexp {^del\s*([0-9]*)$} $utext umatch unum]} { 419 } elseif {[regexp {^del\s*([0-9]*)$} $utext umatch unum]} {
416 # Delete quote 420 # Delete quote
418 } elseif {[regexp {^update\s*(.*)$} $utext umatch unum]} { 422 } elseif {[regexp {^update\s*(.*)$} $utext umatch unum]} {
419 # Modify/update quote 423 # Modify/update quote
420 qdb_update $ucmd $utable $unick $uhand $uchan $unum $upublic 424 qdb_update $ucmd $utable $unick $uhand $uchan $unum $upublic
421 } elseif {[regexp {^find\s*(.*)$} $utext umatch unum]} { 425 } elseif {[regexp {^find\s*(.*)$} $utext umatch unum]} {
422 # Find quote(s) 426 # Find quote(s)
423 qdb_find $ucmd $utable $unick $uhand $uchan $unum $upublic 427 qdb_find $utable $unick $uhand $uchan $unum $upublic
424 } elseif {[regexp {^vote\s*(.*)$} $utext umatch unum]} { 428 } elseif {[regexp {^vote\s*(.*)$} $utext umatch unum]} {
425 # Vote 429 # Vote
426 qdb_vote $ucmd $utable $unick $uhand $uchan $unum $upublic 430 qdb_vote $ucmd $utable $unick $uhand $uchan $unum $upublic
427 } else { 431 } else {
428 # Help/usage 432 # Help/usage