Mercurial > hg > egg-tcls
comparison quotedb.tcl @ 55:f7ccab2a5811
quotedb: Add qdb_split function for splitting long strings nicely to substrings of specified length as a list. Use the function to send overly long quotes correctly to IRC.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 08 Sep 2011 17:49:50 +0300 |
parents | 301df7d15861 |
children | aff22ba168b0 |
comparison
equal
deleted
inserted
replaced
54:301df7d15861 | 55:f7ccab2a5811 |
---|---|
121 qdb_log "$uerrmsg on SQL:\n$usql" | 121 qdb_log "$uerrmsg on SQL:\n$usql" |
122 qdb_msg $upublic $unick $uchan "virhe sörkittäessä tietokantaa. uliskaa." | 122 qdb_msg $upublic $unick $uchan "virhe sörkittäessä tietokantaa. uliskaa." |
123 return 0 | 123 return 0 |
124 } | 124 } |
125 return 1 | 125 return 1 |
126 } | |
127 | |
128 proc qdb_split {str maxlen} { | |
129 set pos 0 | |
130 set len [string length $str] | |
131 set ulen 0 | |
132 set ustr "" | |
133 set result {} | |
134 while {$pos < $len} { | |
135 set end [string wordend $str $pos] | |
136 set new [expr $end - $pos + 1] | |
137 if {$ulen + $new < $maxlen} { | |
138 set ustr "$ustr[string range $str $pos $end]" | |
139 set ulen [expr $ulen + $new] | |
140 } else { | |
141 set ustr "$ustr[string range $str $pos $end]" | |
142 lappend result $ustr | |
143 set ustr "" | |
144 set ulen 0 | |
145 } | |
146 set pos [expr $end + 1] | |
147 } | |
148 if {$ustr != ""} { | |
149 lappend result $ustr | |
150 } | |
151 return $result | |
126 } | 152 } |
127 | 153 |
128 | 154 |
129 #------------------------------------------------------------------------- | 155 #------------------------------------------------------------------------- |
130 proc qdb_add {utable unick uhost uhand uchan utext upublic} { | 156 proc qdb_add {utable unick uhost uhand uchan utext upublic} { |
290 set usql "$usql GROUP BY ${utable}.id ORDER BY RANDOM() LIMIT 1" | 316 set usql "$usql GROUP BY ${utable}.id ORDER BY RANDOM() LIMIT 1" |
291 qdb_log "$unick get random $utable" | 317 qdb_log "$unick get random $utable" |
292 } | 318 } |
293 | 319 |
294 quotedb eval $usql { | 320 quotedb eval $usql { |
295 qdb_msg $upublic $unick $uchan "#${quoteID}: $utext ($uuser, $uvote)" | 321 set qtmp [qdb_split "#${quoteID}: $utext ($uuser, $uvote)" 450] |
322 foreach qstr $qtmp { | |
323 qdb_msg $upublic $unick $uchan $qstr | |
324 } | |
296 return 1 | 325 return 1 |
297 } | 326 } |
298 | 327 |
299 qdb_msg $upublic $unick $uchan "ei löydy." | 328 qdb_msg $upublic $unick $uchan "ei löydy." |
300 return 0 | 329 return 0 |