Mercurial > hg > egg-tcls
comparison quotedb.tcl @ 694:bd7f06c8a515
quotedb: Cleanups. Rename some proc arguments and variables for clarity.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 23 Jun 2023 18:48:38 +0300 |
parents | 5163d582e396 |
children | 14d4d4300623 |
comparison
equal
deleted
inserted
replaced
693:fd45c52d4297 | 694:bd7f06c8a515 |
---|---|
104 return $qrating | 104 return $qrating |
105 } | 105 } |
106 | 106 |
107 | 107 |
108 #------------------------------------------------------------------------- | 108 #------------------------------------------------------------------------- |
109 proc qdb_add {ucmd utable upublic unick uhost uhand uchan utext} { | 109 proc qdb_add {ucmd utable upublic unick uhost uhand uchan uargs} { |
110 global qdb_handle | 110 global qdb_handle |
111 | 111 |
112 if {![qdb_valid_user $ucmd $utable $upublic $unick $uchan $uhand]} { | 112 if {![qdb_valid_user $ucmd $utable $upublic $unick $uchan $uhand]} { |
113 return 0 | 113 return 0 |
114 } | 114 } |
115 | 115 |
116 if {$utext == "" || $utext == {}} { | 116 if {$uargs == "" || $uargs == {}} { |
117 qdb_msg $ucmd $utable $upublic $unick $uchan "help_add" | 117 qdb_msg $ucmd $utable $upublic $unick $uchan "help_add" |
118 return 0 | 118 return 0 |
119 } | 119 } |
120 | 120 |
121 set usql "INSERT INTO $utable (utime,utext,user,host,chan) VALUES ([unixtime], '[utl_escape $utext]', '[utl_escape $uhand]', '[utl_escape $uhost]', '[utl_escape $uchan]')" | 121 set usql "INSERT INTO $utable (utime,utext,user,host,chan) VALUES ([unixtime], '[utl_escape $uargs]', '[utl_escape $uhand]', '[utl_escape $uhost]', '[utl_escape $uchan]')" |
122 if {![qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} { | 122 if {![qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} { |
123 return 0 | 123 return 0 |
124 } | 124 } |
125 | 125 |
126 set quoteID [qdb_handle last_insert_rowid] | 126 set quoteID [qdb_handle last_insert_rowid] |
127 # set numQuotes 0 | 127 # set numQuotes 0 |
128 # set usql "SELECT count(*) AS numQuotes FROM $utable" | 128 # set usql "SELECT count(*) AS numQuotes FROM $utable" |
129 # if {![qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} { return 0 } | 129 # if {![qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} { return 0 } |
130 | 130 |
131 ### Log some data | 131 ### Log some data |
132 qdb_log "Added ${utable} #${quoteID} (${unick}/${uhand}@${uchan}): ${utext}" | 132 qdb_log "Added ${utable} #${quoteID} (${unick}/${uhand}@${uchan}): ${uargs}" |
133 | 133 |
134 ### Report success to user | 134 ### Report success to user |
135 qdb_msg $ucmd $utable $upublic $unick $uchan "add_success" [list $quoteID] | 135 qdb_msg $ucmd $utable $upublic $unick $uchan "add_success" [list $quoteID] |
136 return 1 | 136 return 1 |
137 } | 137 } |
138 | 138 |
139 | 139 |
140 #------------------------------------------------------------------------- | 140 #------------------------------------------------------------------------- |
141 proc qdb_delete {ucmd utable upublic unick uhost uhand uchan utext} { | 141 proc qdb_delete {ucmd utable upublic unick uhost uhand uchan uargs} { |
142 global qdb_handle qdb_max_deltime | 142 global qdb_handle qdb_max_deltime |
143 | 143 |
144 set maxdiff [expr $qdb_max_deltime * 60] | 144 set maxdiff [expr $qdb_max_deltime * 60] |
145 | 145 |
146 if {![qdb_valid_user $ucmd $utable $upublic $unick $uchan $uhand]} { | 146 if {![qdb_valid_user $ucmd $utable $upublic $unick $uchan $uhand]} { |
147 return 0 | 147 return 0 |
148 } | 148 } |
149 | 149 |
150 if {![regexp {^\s*([0-9]+)$} $utext -> unum]} { | 150 if {![regexp {^\s*([0-9]+)$} $uargs -> unum]} { |
151 qdb_msg $ucmd $utable $upublic $unick $uchan "help_delete" | 151 qdb_msg $ucmd $utable $upublic $unick $uchan "help_delete" |
152 return 0 | 152 return 0 |
153 } | 153 } |
154 | 154 |
155 set qoverride [matchattr $uhand n] | 155 set qoverride [matchattr $uhand n] |
185 return 0 | 185 return 0 |
186 } | 186 } |
187 | 187 |
188 | 188 |
189 #------------------------------------------------------------------------- | 189 #------------------------------------------------------------------------- |
190 proc qdb_update {ucmd utable upublic unick uhost uhand uchan utext} { | 190 proc qdb_update {ucmd utable upublic unick uhost uhand uchan uargs} { |
191 global qdb_handle qdb_max_modtime | 191 global qdb_handle qdb_max_modtime |
192 | 192 |
193 set maxdiff [expr $qdb_max_modtime * 60] | 193 set maxdiff [expr $qdb_max_modtime * 60] |
194 | 194 |
195 if {![qdb_valid_user $ucmd $utable $upublic $unick $uchan $uhand]} { | 195 if {![qdb_valid_user $ucmd $utable $upublic $unick $uchan $uhand]} { |
196 return 0 | 196 return 0 |
197 } | 197 } |
198 | 198 |
199 if {![regexp {^\s*([0-9]+)\s+(.+)$} $utext -> unum uquote]} { | 199 if {![regexp {^\s*([0-9]+)\s+(.+)$} $uargs -> unum uquote]} { |
200 qdb_msg $ucmd $utable $upublic $unick $uchan "help_update" | 200 qdb_msg $ucmd $utable $upublic $unick $uchan "help_update" |
201 return 0 | 201 return 0 |
202 } | 202 } |
203 | 203 |
204 set qoverride [matchattr $uhand n] | 204 set qoverride [matchattr $uhand n] |
230 return 0 | 230 return 0 |
231 } | 231 } |
232 | 232 |
233 | 233 |
234 #------------------------------------------------------------------------- | 234 #------------------------------------------------------------------------- |
235 proc qdb_toplist {ucmd utable upublic unick uhost uhand uchan utext unum} { | 235 proc qdb_toplist {ucmd utable upublic unick uhost uhand uchan uargs unum} { |
236 global qdb_handle | 236 global qdb_handle |
237 global qdb_toplist_min qdb_toplist_max | 237 global qdb_toplist_min qdb_toplist_max |
238 | 238 |
239 if {$unum == {} || $unum == ""} { | 239 if {$unum == {} || $unum == ""} { |
240 set unum $qdb_toplist_min | 240 set unum $qdb_toplist_min |
255 return 0 | 255 return 0 |
256 } | 256 } |
257 | 257 |
258 | 258 |
259 #------------------------------------------------------------------------- | 259 #------------------------------------------------------------------------- |
260 proc qdb_vote {ucmd utable upublic unick uhost uhand uchan utext} { | 260 proc qdb_vote {ucmd utable upublic unick uhost uhand uchan uargs} { |
261 global qdb_handle | 261 global qdb_handle |
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 qvote "+" | 267 set qvote "+" |
268 if {$utext == "" || [regexp {^\s*(\+|\-)\s*$} $utext -> qvote]} { | 268 if {$uargs == "" || [regexp {^\s*(\+|\-)\s*$} $uargs -> 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]+)$} $uargs -> uid]} { |
273 } elseif {![regexp {^\s*([0-9]+)\s+(\+|\-)$} $utext -> uid qvote]} { | 273 } elseif {![regexp {^\s*([0-9]+)\s+(\+|\-)$} $uargs -> 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 } | 276 } |
277 | 277 |
278 if {$qvote == "-"} { | 278 if {$qvote == "-"} { |
351 return 0 | 351 return 0 |
352 } | 352 } |
353 | 353 |
354 | 354 |
355 #------------------------------------------------------------------------- | 355 #------------------------------------------------------------------------- |
356 proc qdb_stats {ucmd utable upublic unick uhost uhand uchan utext} { | 356 proc qdb_stats {ucmd utable upublic unick uhost uhand uchan uargs} { |
357 global qdb_handle | 357 global qdb_handle |
358 | 358 |
359 set usql "SELECT count(*) AS nvotes FROM ${utable}_votes" | 359 set usql "SELECT count(*) AS nvotes FROM ${utable}_votes" |
360 qdb_handle eval $usql {} | 360 qdb_handle eval $usql {} |
361 | 361 |
396 return 0 | 396 return 0 |
397 } | 397 } |
398 | 398 |
399 | 399 |
400 #------------------------------------------------------------------------- | 400 #------------------------------------------------------------------------- |
401 proc qdb_find {ucmd utable upublic unick uhost uhand uchan utext} { | 401 proc qdb_find {ucmd utable upublic unick uhost uhand uchan uargs} { |
402 global qdb_handle qdb_showmax_pub qdb_showmax_priv | 402 global qdb_handle qdb_showmax_pub qdb_showmax_priv |
403 | 403 |
404 # Limit results based on public/private | 404 # Limit results based on public/private |
405 if {$upublic == 0} { | 405 if {$upublic == 0} { |
406 set ulimit $qdb_showmax_priv | 406 set ulimit $qdb_showmax_priv |
407 } else { | 407 } else { |
408 set ulimit $qdb_showmax_pub | 408 set ulimit $qdb_showmax_pub |
409 } | 409 } |
410 | 410 |
411 ### Parse the given command | 411 ### Parse the given command |
412 qdb_log "${unick}/${uhand}/${uchan} searched ${utable}: '${utext}'" | 412 qdb_log "${unick}/${uhand}/${uchan} searched ${utable}: '${uargs}'" |
413 | 413 |
414 set fpatlist {} | 414 set fpatlist {} |
415 set ftokens [::textutil::split::splitx $utext {\s+}] | 415 set ftokens [::textutil::split::splitx $uargs {\s+}] |
416 foreach ftoken $ftokens { | 416 foreach ftoken $ftokens { |
417 set fprefix [string range $ftoken 0 0] | 417 set fprefix [string range $ftoken 0 0] |
418 set fpattern [string range $ftoken 1 end] | 418 set fpattern [string range $ftoken 1 end] |
419 | 419 |
420 if {$fprefix == "-"} { | 420 if {$fprefix == "-"} { |