Changeset 1019
- Timestamp:
- 08/23/09 19:22:05 (2 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 10 edited
-
modules/output.tcl (modified) (5 diffs)
-
modules/plugins.tcl (modified) (2 diffs)
-
plugins/en/output_NUMBER.tcl (modified) (4 diffs)
-
plugins/en/output_OWNER.tcl (modified) (4 diffs)
-
plugins/en/output_PLURAL.tcl (modified) (3 diffs)
-
plugins/en/output_REPEAT.tcl (modified) (3 diffs)
-
plugins/en/output_SETTING.tcl (modified) (4 diffs)
-
plugins/en/output_TIME.tcl (modified) (4 diffs)
-
plugins/en/output_VAR.tcl (modified) (4 diffs)
-
plugins/en/output_VERB.tcl (modified) (2 diffs)
-
plugins/en/output_rbot.tcl (added)
-
plugins/en/output_ruser.tcl (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/output.tcl
r1017 r1019 124 124 # our magic output function 125 125 proc bMotionDoAction {channel nick text {moreText ""} {noTypo 0} {urgent 0} } { 126 bMotion_putloglev 5 * "bMotionDoAction($channel,$nick,$text,$moreText,$noTypo )"126 bMotion_putloglev 5 * "bMotionDoAction($channel,$nick,$text,$moreText,$noTypo,$urgent)" 127 127 global bMotionInfo bMotionCache bMotionOriginalInput 128 128 global bMotion_output_delay bMotionSettings BMOTION_SLEEP 129 129 130 130 set bMotion_output_delay 0 131 132 set bMotionCache($channel,last) 1133 131 134 132 #check our global toggle … … 137 135 return 0 138 136 } 137 138 set bMotionCache($channel,last) 1 139 139 140 140 # check if we're asleep … … 151 151 } 152 152 153 if {[bMotion_setting_get "silence"] == 1} { return 0 } 153 if {[bMotion_setting_get "silence"] == 1} { 154 return 0 155 } 154 156 catch { 155 if {$bMotionInfo(adminSilence,$channel) == 1} { return 0 } 156 } 157 158 # TODO: ugly, refactor? 157 if {$bMotionInfo(adminSilence,$channel) == 1} { 158 return 0 159 } 160 } 161 159 162 switch [rand 3] { 160 163 0 { } … … 163 166 } 164 167 168 # Process macros 169 170 set done 0 171 set current_pos 0 172 while {$done == 0} { 173 bMotion_putloglev d * "macro: starting loop with $text and current pos=$current_pos" 174 set current_pos [string first "%" $text $current_pos] 175 if {$current_pos == -1} { 176 # no more matches 177 set done 1 178 continue 179 } 180 bMotion_putloglev d * "macro: found a % at $current_pos" 181 if {$current_pos < [string length $text]} { 182 # this isn't a % at the end of the line 183 if {[string index $text [expr $current_pos + 1]] == "|"} { 184 set current_pos [expr $current_pos + 2] 185 continue 186 } 187 188 #find the element following this % 189 set substring [string range $text $current_pos end] 190 if [regexp -nocase {%([a-z]+)} $text matches macro] { 191 bMotion_putloglev d * "macro: found macro $macro at $current_pos" 192 set plugin [bMotion_plugin_find_output "en" "" 0 10 $macro] 193 if {[llength $plugin] == 1} { 194 # call plugin 195 bMotion_putloglev d * "macro: found matching plugin for macro [lindex $plugin 0]" 196 set result "" 197 catch { 198 set result [[lindex $plugin 0] $channel $text] 199 if {$result == ""} { 200 bMotion_putloglev d * "macro: [lindex $plugin 0] returned nothing, aborting output" 201 return 0 202 } 203 } 204 if {$result == ""} { 205 continue 206 } 207 208 if {$text != $result} { 209 set text $result 210 # reset current pos 211 set current_pos 0 212 continue 213 } else { 214 bMotion_putloglev d * "macro: [lindex $plugin 0] did nothing at position $current_pos in output $text" 215 } 216 } else { 217 bMotion_putloglev d * "macro: unexpectly got too many matching plugins back: $plugin" 218 } 219 220 incr current_pos 221 continue 222 } else { 223 bMotion_putloglev d * "macro: couldn't find a macro in $substring" 224 # skip it 225 incr current_pos 226 continue 227 } 228 } 229 230 # hmm 231 bMotion_putloglev d * "macro: got to end of macro loop o_O" 232 incr current_pos 233 } 165 234 166 235 # Run the plugins :D 167 236 168 237 # First run the core plugins 169 set plugins [bMotion_plugin_find_output $bMotionInfo(language) $channel 0 10]170 if {[llength $plugins] > 0} {171 foreach callback $plugins {172 bMotion_putloglev 1 * "bMotion: output plugin: $callback..."173 set result ""174 catch {175 set result [$callback $channel $text]176 } err177 bMotion_putloglev 3 * "bMotion: returned from output $callback ($result)"178 # TODO: Still used?179 if {$result == ""} {180 return 0181 }182 set text $result183 }184 }238 #set plugins [bMotion_plugin_find_output $bMotionInfo(language) $channel 0 10] 239 #if {[llength $plugins] > 0} { 240 # foreach callback $plugins { 241 # bMotion_putloglev 1 * "bMotion: output plugin: $callback..." 242 # set result "" 243 # catch { 244 # set result [$callback $channel $text] 245 # } err 246 # bMotion_putloglev 3 * "bMotion: returned from output $callback ($result)" 247 # # TODO: Still used? 248 # if {$result == ""} { 249 # return 0 250 # } 251 # set text $result 252 # } 253 #} 185 254 186 255 set text [bMotionDoInterpolation $text $nick $moreText $channel] … … 248 317 set line [bMotionInsertString $line "%2" $moreText] 249 318 set line [bMotionInsertString $line "%percent" "%"] 250 251 bMotion_putloglev 4 * "done misc"252 253 #ruser:254 set loops 0255 while {[regexp "%ruser(\{(\[^\}\]+)\})?" $line matches param condition]} {256 set ruser [bMotionGetRealName [bMotion_choose_random_user $channel 0 $condition] ""]257 if {$condition == ""} {258 set findString "%ruser"259 } else {260 set findString "%ruser$param"261 }262 regsub $findString $line $ruser line263 incr loops264 if {$loops > 10} {265 putlog "bMotion: ALERT! looping too much in %ruser code with $line"266 return ""267 }268 }269 270 #rbot:271 set loops 0272 while {[regexp "%rbot(\{(\[^\}\]+)\})?" $line matches param condition]} {273 set ruser [bMotionGetRealName [bMotion_choose_random_user $channel 1 $condition] ""]274 if {$condition == ""} {275 set findString "%rbot"276 } else {277 set findString "%rbot$param"278 }279 regsub $findString $line $ruser line280 incr loops281 if {$loops > 10} {282 putlog "bMotion: ALERT! looping too much in %rbot code with $line"283 return ""284 }285 }286 319 287 320 bMotion_putloglev 4 * "bMotionDoInterpolation returning: $line" -
trunk/modules/plugins.tcl
r1004 r1019 284 284 # Sorted by priority then name 285 285 # Includes plugins only enabled for the given channel 286 proc bMotion_plugin_find_output { lang { channel "" } { min_priority 0} { max_priority 100 } } {286 proc bMotion_plugin_find_output { lang { channel "" } { min_priority 0} { max_priority 100 } {name "" } } { 287 287 global bMotion_plugins_output botnicks 288 288 global bMotion_plugins_output_perchan … … 296 296 set language [lindex $val $BMOTION_PLUGIN_OUTPUT_LANGUAGE] 297 297 set priority [lindex $val $BMOTION_PLUGIN_OUTPUT_PRIORITY] 298 if {($priority >= $min_priority) && ($priority <= $max_priority)} { 299 if {[string match $lang $language] || ($language == "any")|| ($language == "all")} { 300 if {$enabled == 1} { 301 lappend result [list $callback $priority] 302 } else { 303 bMotion_putloglev 1 * "Searching $key for channel $channel" 304 if {$channel != ""} { 305 catch { 306 set chanlist $bMotion_plugins_output_perchan($key) 307 if {[lsearch $chanlist $channel] > -1} { 308 lappend result [list $callback $priority] 309 bMotion_putloglev d * "Plugin $key is enabled for $channel" 310 } 311 } 298 299 if {($name != "") && ($name != $key)} { 300 bMotion_putloglev 3 * "macro: ignoring $key on name" 301 continue 302 } 303 304 if {!(($priority >= $min_priority) && ($priority <= $max_priority))} { 305 bMotion_putloglev 3 * "macro: ignoring $key on priority" 306 continue 307 } 308 309 if {!([string match $lang $language] && ($language != "any") && ($language != "all"))} { 310 bMotion_putloglev 3 * "macro: ignoring $key on language" 311 bMotion_putloglev 3 * "macro: plugin is $lang, want $language" 312 continue 313 } 314 315 if {$enabled == 1} { 316 lappend result [list $callback $priority] 317 } else { 318 bMotion_putloglev 1 * "Searching $key for channel $channel" 319 if {$channel != ""} { 320 catch { 321 set chanlist $bMotion_plugins_output_perchan($key) 322 if {[lsearch $chanlist $channel] > -1} { 323 lappend result [list $callback $priority] 324 bMotion_putloglev d * "Plugin $key is enabled for $channel" 312 325 } 313 326 } -
trunk/plugins/en/output_NUMBER.tcl
r961 r1019 1 #2 #3 1 # vim: fdm=indent fdn=1 4 2 # … … 6 4 ############################################################################### 7 5 # This is a bMotion plugin 8 # Copyright (C) James Michael Seward 2000-200 86 # Copyright (C) James Michael Seward 2000-2009 9 7 # 10 8 # This program is covered by the GPL, please refer the to LICENCE file in the … … 21 19 bMotion_putloglev 4 * "bMotion_plugin_output_NUMBER $channel $line" 22 20 23 set lastline ""24 25 21 set padding 0 26 while{[regexp "%NUMBER\{(\[0-9\]+)\}(\{(\[0-9\]+)\})?" $line matches numberString paddingOpt padding]} {22 if {[regexp "%NUMBER\{(\[0-9\]+)\}(\{(\[0-9\]+)\})?" $line matches numberString paddingOpt padding]} { 27 23 set var [bMotion_get_number [bMotion_rand_nonzero $numberString]] 28 24 if {$padding > 0} { … … 33 29 set line [bMotionInsertString $line "%NUMBER\\{$numberString\\}(\\{\[0-9\]+\\})?" $var] 34 30 set padding 0 35 36 if {$lastline == $line} {37 putlog "bMotion: ALERT! unable to process %NUMBER in $line (dropping output)"38 set line ""39 break40 }41 set lastline $line42 31 } 43 32 -
trunk/plugins/en/output_OWNER.tcl
r961 r1019 1 #2 #3 1 # vim: fdm=indent fdn=1 4 2 # … … 6 4 ############################################################################### 7 5 # This is a bMotion plugin 8 # Copyright (C) James Michael Seward 2000-200 86 # Copyright (C) James Michael Seward 2000-2009 9 7 # 10 8 # This program is covered by the GPL, please refer the to LICENCE file in the … … 18 16 proc bMotion_plugin_output_OWNER { channel line } { 19 17 20 set previous_line "" 21 22 while {[regexp -nocase "%OWNER\{(.*?)\}" $line matches BOOM]} { 18 if {[regexp -nocase "%OWNER\{(.*?)\}" $line matches BOOM]} { 23 19 set BOOM [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\} $ \\\$ \" \\\" | \\\|} $BOOM] 24 20 … … 26 22 regsub -nocase "%OWNER\{$BOOM\}" $line [bMotionMakePossessive $BOOM] line 27 23 regsub -all "\\\\" $line "" line 28 if {$line == $previous_line} {29 putlog "bMotion: ALERT! looping too much in %OWNER code with $line (no change since last parse)"30 set line ""31 break32 }33 set previous_line $line34 24 } 35 25 return $line -
trunk/plugins/en/output_PLURAL.tcl
r961 r1019 1 #2 #3 1 # vim: fdm=indent fdn=1 4 2 # … … 6 4 ############################################################################### 7 5 # This is a bMotion plugin 8 # Copyright (C) James Michael Seward 2000-200 86 # Copyright (C) James Michael Seward 2000-2009 9 7 # 10 8 # This program is covered by the GPL, please refer the to LICENCE file in the … … 18 16 proc bMotion_plugin_output_PLURAL { channel line } { 19 17 20 set previous_line "" 21 while {[regexp -nocase "%PLURAL\{(.*?)\}" $line matches BOOM]} { 18 if {[regexp -nocase "%PLURAL\{(.*?)\}" $line matches BOOM]} { 22 19 # set line [bMotionInsertString $line "%PLURAL\{$BOOM\}" [bMotionMakePlural $BOOM]] 23 20 regsub -nocase "%PLURAL\{$BOOM\}" $line [bMotionMakePlural $BOOM] line 24 if {$line == $previous_line} {25 putlog "bMotion: ALERT! looping too much in %PLURAL code with $line (no change since last parse)"26 set line ""27 break28 }29 set previous_line $line30 21 } 31 22 return $line -
trunk/plugins/en/output_REPEAT.tcl
r961 r1019 1 #2 #3 1 # vim: fdm=indent fdn=1 4 2 # … … 6 4 ############################################################################### 7 5 # This is a bMotion plugin 8 # Copyright (C) James Michael Seward 2000-200 86 # Copyright (C) James Michael Seward 2000-2009 9 7 # 10 8 # This program is covered by the GPL, please refer the to LICENCE file in the … … 17 15 18 16 proc bMotion_plugin_output_REPEAT { channel line } { 19 set previous_line "" 20 while {[regexp -nocase "%REPEAT\{(.+?)\}" $line matches BOOM]} { 17 if {[regexp -nocase "%REPEAT\{(.+?)\}" $line matches BOOM]} { 21 18 set replacement [bMotionMakeRepeat $BOOM] 22 19 regsub -nocase "%REPEAT\\{$BOOM\\}" $line $replacement line 23 if {$previous_line == $line} {24 putlog "bMotion: ALERT! looping too much in %REPEAT code with $line (no change since last parse)"25 set line ""26 break27 }28 set previous_line $line29 20 } 30 21 return $line -
trunk/plugins/en/output_SETTING.tcl
r961 r1019 1 #2 #3 1 # vim: fdm=indent fdn=1 4 2 # … … 6 4 ############################################################################### 7 5 # This is a bMotion plugin 8 # Copyright (C) James Michael Seward 2000-200 86 # Copyright (C) James Michael Seward 2000-2009 9 7 # 10 8 # This program is covered by the GPL, please refer the to LICENCE file in the … … 19 17 bMotion_putloglev 4 * "bMotion_plugin_output_SETTING $channel $line" 20 18 21 set lastline "" 22 23 while {[regexp "%SETTING\{(.+?)\}" $line matches settingString]} { 19 if {[regexp "%SETTING\{(.+?)\}" $line matches settingString]} { 24 20 set var "" 25 21 if [regexp {([^:]+:[^:]+):([^:]+):([^:]+):([^:]+)} $settingString matches plugin setting ch ni] { … … 31 27 } 32 28 set line [bMotionInsertString $line "%SETTING{$settingString}" $var] 33 34 if {$lastline == $line} {35 putlog "bMotion: ALERT: couldn't parse $line for %SETTING (dropping output)"36 set line ""37 break38 }39 29 } 40 30 -
trunk/plugins/en/output_TIME.tcl
r961 r1019 1 #2 #3 1 # vim: fdm=indent fdn=1 4 2 # … … 6 4 ############################################################################### 7 5 # This is a bMotion plugin 8 # Copyright (C) James Michael Seward 2000-200 86 # Copyright (C) James Michael Seward 2000-2009 9 7 # 10 8 # This program is covered by the GPL, please refer the to LICENCE file in the … … 19 17 bMotion_putloglev 4 * "bMotion_plugin_output_TIME $channel $line" 20 18 21 set lastline "" 22 23 while {[regexp "%TIME\{(\[a-zA-Z0-9 -\]+)\}" $line matches timeString]} { 19 if {[regexp "%TIME\{(\[a-zA-Z0-9 -\]+)\}" $line matches timeString]} { 24 20 bMotion_putloglev 2 * "found timestring $timeString" 25 21 set origtime $timeString … … 29 25 bMotion_putloglev 2 * "using time $var" 30 26 set line [bMotionInsertString $line "%TIME\\{$origtime\\}" $var] 31 32 if {$lastline == $line} {33 # nothing changed34 set line ""35 break36 }37 set lastline $line38 27 } 39 28 -
trunk/plugins/en/output_VAR.tcl
r1016 r1019 1 #2 #3 1 # vim: fdm=indent fdn=1 4 2 # … … 6 4 ############################################################################### 7 5 # This is a bMotion plugin 8 # Copyright (C) James Michael Seward 2000-200 86 # Copyright (C) James Michael Seward 2000-2009 9 7 # 10 8 # This program is covered by the GPL, please refer the to LICENCE file in the … … 32 30 regsub {%VAR\{([^\}]+)\}\{strip\}} $line "%VAR{\\1:strip}" line 33 31 34 set lastloop "" 35 36 while {[regexp -nocase {(%VAR\{([^\}:]+)(:[^\}]+)?\}(\{strip\})?)} $line matches whole_thing abstract options clean]} { 32 if {[regexp -nocase {(%VAR\{([^\}:]+)(:[^\}]+)?\}(\{strip\})?)} $line matches whole_thing abstract options clean]} { 37 33 global $abstract 38 34 #see if we have a new-style abstract available … … 126 122 set line [bMotionInsertString $line "%noun" "%VAR{sillyThings}"] 127 123 } 128 129 if {$lastloop == $line} {130 putlog "bMotion: ALERT! looping too much in %VAR code with $line (no change since last parse)"131 set line "/has a tremendous error while trying to sort something out :("132 break133 }134 set lastloop $line135 124 } 136 125 -
trunk/plugins/en/output_VERB.tcl
r961 r1019 1 #2 #3 1 # vim: fdm=indent fdn=1 4 2 # … … 18 16 proc bMotion_plugin_output_VERB { channel line } { 19 17 20 set previous_line "" 21 22 while {[regexp -nocase "%VERB\{(.*?)\}" $line matches BOOM]} { 18 if {[regexp -nocase "%VERB\{(.*?)\}" $line matches BOOM]} { 23 19 regsub -nocase "%VERB\{$BOOM\}" $line [bMotionMakeVerb $BOOM] line 24 if {$line == $previous_line} {25 putlog "bMotion: ALERT! looping too much in %VERB code with $line (no change since last parse)"26 set line ""27 break28 }29 set previous_line $line30 20 } 31 21
Note: See TracChangeset
for help on using the changeset viewer.
