| 60 | | global bMotion_plugins_simple plugins bMotion_testing bMotion_noplugins |
| 61 | | |
| 62 | | if {$bMotion_testing == 0} { |
| 63 | | catch { |
| 64 | | set test $bMotion_plugins_simple($id) |
| 65 | | bMotion_putloglev d * "bMotion: ALERT! Simple plugin $id is defined more than once" |
| 66 | | return 0 |
| 67 | | } |
| 68 | | } |
| 69 | | if [bMotion_plugin_check_allowed "simple:$id"] { |
| 70 | | set bMotion_plugins_simple($id) "${match}Š${chance}Š${response}Š${language}" |
| 71 | | bMotion_putloglev 2 * "bMotion: added simple plugin: $id" |
| 72 | | append plugins "$id," |
| 73 | | return 1 |
| 74 | | } |
| 75 | | bMotion_putloglev d * "bMotion: ignoring disallowed plugin simple:$id" |
| | 60 | global bMotion_plugins_simple plugins bMotion_testing bMotion_noplugins |
| | 61 | |
| | 62 | if {$bMotion_testing == 0} { |
| | 63 | catch { |
| | 64 | set test $bMotion_plugins_simple($id) |
| | 65 | bMotion_putloglev d * "bMotion: ALERT! Simple plugin $id is defined more than once" |
| | 66 | return 0 |
| | 67 | } |
| | 68 | } |
| | 69 | if [bMotion_plugin_check_allowed "simple:$id"] { |
| | 70 | set bMotion_plugins_simple($id) "${match}Š${chance}Š${response}Š${language}" |
| | 71 | bMotion_putloglev 2 * "bMotion: added simple plugin: $id" |
| | 72 | append plugins "$id," |
| | 73 | return 1 |
| | 74 | } |
| | 75 | bMotion_putloglev d * "bMotion: ignoring disallowed plugin simple:$id" |
| 82 | | bMotion_putloglev 3 * "bMotion_plugin_find_simple: text = $text, lang = $lang" |
| 83 | | global bMotion_plugins_simple botnicks |
| 84 | | set s [lsort [array names bMotion_plugins_simple]] |
| 85 | | |
| 86 | | foreach key $s { |
| 87 | | if {$key == "dummy"} { continue } |
| 88 | | set val $bMotion_plugins_simple($key) |
| 89 | | set blah [split $val "Š"] |
| 90 | | set rexp [lindex $blah 0] |
| 91 | | set chance [lindex $blah 1] |
| 92 | | set response [lindex $blah 2] |
| 93 | | set language [lindex $blah 3] |
| 94 | | if {[string match $lang $language] || ($language == "any")} { |
| 95 | | set rexp [bMotionInsertString $rexp "%botnicks" "${botnicks}"] |
| 96 | | if [regexp -nocase $rexp $text] { |
| 97 | | set c [rand 100] |
| 98 | | bMotion_putloglev 4 * "simple plugin $key matches" |
| 99 | | if {[bMotion_plugins_settings_get "system" "last_simple" "" ""] == $key} { |
| 100 | | bMotion_putloglev 3 * "trying to trigger same simple plugin twice in a row, aborting" |
| 101 | | return "" |
| 102 | | } |
| 103 | | bMotion_plugins_settings_set "system" "last_simple" "" "" $key |
| 104 | | if {$chance > $c} { |
| 105 | | bMotion_putloglev 4 * " `- firing" |
| 106 | | return $response |
| 107 | | } |
| 108 | | } |
| 109 | | } |
| 110 | | } |
| 111 | | return "" |
| | 82 | bMotion_putloglev 3 * "bMotion_plugin_find_simple: text = $text, lang = $lang" |
| | 83 | global bMotion_plugins_simple botnicks |
| | 84 | set s [lsort [array names bMotion_plugins_simple]] |
| | 85 | |
| | 86 | foreach key $s { |
| | 87 | if {$key == "dummy"} { continue } |
| | 88 | set val $bMotion_plugins_simple($key) |
| | 89 | set blah [split $val "Š"] |
| | 90 | set rexp [lindex $blah 0] |
| | 91 | set chance [lindex $blah 1] |
| | 92 | set response [lindex $blah 2] |
| | 93 | set language [lindex $blah 3] |
| | 94 | if {[string match $lang $language] || ($language == "any")} { |
| | 95 | set rexp [bMotionInsertString $rexp "%botnicks" "${botnicks}"] |
| | 96 | if [regexp -nocase $rexp $text] { |
| | 97 | set c [rand 100] |
| | 98 | bMotion_putloglev 4 * "simple plugin $key matches" |
| | 99 | if {[bMotion_plugins_settings_get "system" "last_simple" "" ""] == $key} { |
| | 100 | bMotion_putloglev 3 * "trying to trigger same simple plugin twice in a row, aborting" |
| | 101 | return "" |
| | 102 | } |
| | 103 | bMotion_plugins_settings_set "system" "last_simple" "" "" $key |
| | 104 | if {$chance > $c} { |
| | 105 | bMotion_putloglev 4 * " `- firing" |
| | 106 | return $response |
| | 107 | } |
| | 108 | } |
| | 109 | } |
| | 110 | } |
| | 111 | return "" |
| 138 | | global bMotion_plugins_management |
| 139 | | set s [array startsearch bMotion_plugins_management] |
| 140 | | |
| 141 | | while {[set key [array nextelement bMotion_plugins_management $s]] != ""} { |
| 142 | | if {$key == "dummy"} { continue } |
| 143 | | set val $bMotion_plugins_management($key) |
| 144 | | set blah [split $val "Š"] |
| 145 | | set rexp [lindex $blah 0] |
| 146 | | set flags [lindex $blah 1] |
| 147 | | set callback [lindex $blah 2] |
| 148 | | if [regexp -nocase $rexp $text] { |
| 149 | | array donesearch bMotion_plugins_management $s |
| 150 | | return "${flags}Š$callback" |
| 151 | | } |
| 152 | | } |
| 153 | | array donesearch bMotion_plugins_management $s |
| 154 | | return "" |
| | 138 | global bMotion_plugins_management |
| | 139 | set s [array startsearch bMotion_plugins_management] |
| | 140 | |
| | 141 | while {[set key [array nextelement bMotion_plugins_management $s]] != ""} { |
| | 142 | if {$key == "dummy"} { continue } |
| | 143 | set val $bMotion_plugins_management($key) |
| | 144 | set blah [split $val "Š"] |
| | 145 | set rexp [lindex $blah 0] |
| | 146 | set flags [lindex $blah 1] |
| | 147 | set callback [lindex $blah 2] |
| | 148 | if [regexp -nocase $rexp $text] { |
| | 149 | array donesearch bMotion_plugins_management $s |
| | 150 | return "${flags}Š$callback" |
| | 151 | } |
| | 152 | } |
| | 153 | array donesearch bMotion_plugins_management $s |
| | 154 | return "" |
| 159 | | global bMotion_plugins_management |
| 160 | | set s [array startsearch bMotion_plugins_management] |
| 161 | | |
| 162 | | while {[set key [array nextelement bMotion_plugins_management $s]] != ""} { |
| 163 | | if {$key == "dummy"} { continue } |
| 164 | | if [string match -nocase $name $key] { |
| 165 | | set blah [split $bMotion_plugins_management($key) "Š"] |
| 166 | | set helpcallback [lindex $blah 3] |
| 167 | | array donesearch bMotion_plugins_management $s |
| 168 | | return $helpcallback |
| 169 | | } |
| 170 | | } |
| 171 | | array donesearch bMotion_plugins_management $s |
| 172 | | return "" |
| | 159 | global bMotion_plugins_management |
| | 160 | set s [array startsearch bMotion_plugins_management] |
| | 161 | |
| | 162 | while {[set key [array nextelement bMotion_plugins_management $s]] != ""} { |
| | 163 | if {$key == "dummy"} { continue } |
| | 164 | if [string match -nocase $name $key] { |
| | 165 | set blah [split $bMotion_plugins_management($key) "Š"] |
| | 166 | set helpcallback [lindex $blah 3] |
| | 167 | array donesearch bMotion_plugins_management $s |
| | 168 | return $helpcallback |
| | 169 | } |
| | 170 | } |
| | 171 | array donesearch bMotion_plugins_management $s |
| | 172 | return "" |
| 208 | | foreach key $s { |
| 209 | | if {$key == "dummy"} { continue } |
| 210 | | set val $bMotion_plugins_complex($key) |
| 211 | | set blah [split $val "Š"] |
| 212 | | set rexp [lindex $blah 0] |
| 213 | | set chance [lindex $blah 1] |
| 214 | | set callback [lindex $blah 2] |
| 215 | | set language [lindex $blah 3] |
| 216 | | if {[string match $lang $language] || ($language == "any") || ($language == "all")} { |
| 217 | | set rexp [bMotionInsertString $rexp "%botnicks" "${botnicks}"] |
| 218 | | if [regexp -nocase $rexp $text] { |
| 219 | | set c [rand 100] |
| | 208 | foreach key $s { |
| | 209 | if {$key == "dummy"} { continue } |
| | 210 | set val $bMotion_plugins_complex($key) |
| | 211 | set blah [split $val "Š"] |
| | 212 | set rexp [lindex $blah 0] |
| | 213 | set chance [lindex $blah 1] |
| | 214 | set callback [lindex $blah 2] |
| | 215 | set language [lindex $blah 3] |
| | 216 | if {[string match $lang $language] || ($language == "any") || ($language == "all")} { |
| | 217 | set rexp [bMotionInsertString $rexp "%botnicks" "${botnicks}"] |
| | 218 | if [regexp -nocase $rexp $text] { |
| | 219 | set c [rand 100] |
| 254 | | proc bMotion_plugin_find_output { lang } { |
| 255 | | global bMotion_plugins_output botnicks |
| 256 | | set s [array startsearch bMotion_plugins_output] |
| 257 | | set result [list] |
| 258 | | |
| 259 | | while {[set key [array nextelement bMotion_plugins_output $s]] != ""} { |
| 260 | | if {$key == "dummy"} { continue } |
| 261 | | set val $bMotion_plugins_output($key) |
| 262 | | set blah [split $val "Š"] |
| 263 | | set callback [lindex $blah 0] |
| 264 | | set enabled [lindex $blah 1] |
| 265 | | set language [lindex $blah 2] |
| 266 | | if {[string match $lang $language] || ($language == "any")|| ($language == "all")} { |
| 267 | | if {$enabled == 1} { |
| 268 | | lappend result $callback |
| 269 | | } |
| 270 | | } |
| 271 | | } |
| 272 | | array donesearch bMotion_plugins_output $s |
| 273 | | return $result |
| | 255 | proc bMotion_plugin_find_output { lang { channel "" } } { |
| | 256 | global bMotion_plugins_output botnicks |
| | 257 | global bMotion_plugins_output_perchan |
| | 258 | set s [array startsearch bMotion_plugins_output] |
| | 259 | set result [list] |
| | 260 | |
| | 261 | while {[set key [array nextelement bMotion_plugins_output $s]] != ""} { |
| | 262 | if {$key == "dummy"} { continue } |
| | 263 | set val $bMotion_plugins_output($key) |
| | 264 | set blah [split $val "Š"] |
| | 265 | set callback [lindex $blah 0] |
| | 266 | set enabled [lindex $blah 1] |
| | 267 | set language [lindex $blah 2] |
| | 268 | if {[string match $lang $language] || ($language == "any")|| ($language == "all")} { |
| | 269 | if {$enabled == 1} { |
| | 270 | lappend result $callback |
| | 271 | } else { |
| | 272 | bMotion_putloglev 1 * "Searching $key for channel $channel" |
| | 273 | if {$channel != ""} { |
| | 274 | catch { |
| | 275 | set chanlist $bMotion_plugins_output_perchan($key) |
| | 276 | if {[lsearch $chanlist $channel] > -1} { |
| | 277 | lappend result $callback |
| | 278 | bMotion_putloglev d * "Plugin $key is enabled for $channel" |
| | 279 | } |
| | 280 | } |
| | 281 | } |
| | 282 | } |
| | 283 | } |
| | 284 | } |
| | 285 | array donesearch bMotion_plugins_output $s |
| | 286 | return $result |
| | 287 | } |
| | 288 | |
| | 289 | proc bMotion_plugin_set_output { id enabled } { |
| | 290 | global bMotion_plugins_output |
| | 291 | |
| | 292 | if {($enabled == 0) || ($enabled == 1)} { |
| | 293 | set details $bMotion_plugins_output($id) |
| | 294 | set blah [split $details "Š"] |
| | 295 | set callback [lindex $blah 0] |
| | 296 | set language [lindex $blah 2] |
| | 297 | |
| | 298 | set bMotion_plugins_output($id) "$callbackŠ$enabledŠ$language" |
| | 299 | return 1 |
| | 300 | } |
| | 301 | return 0 |
| | 302 | } |
| | 303 | |
| | 304 | proc bMotion_plugin_set_output_channel { id channel enabled } { |
| | 305 | global bMotion_plugins_output_perchan |
| | 306 | set channel [string tolower $channel] |
| | 307 | |
| | 308 | set current [list] |
| | 309 | catch { |
| | 310 | set current $bMotion_plugins_output_perchan($id) |
| | 311 | } |
| | 312 | if {$enabled == 1} { |
| | 313 | set current [lappend current $channel] |
| | 314 | } else { |
| | 315 | set index [lsearch $current $channel] |
| | 316 | if {$index > -1} { |
| | 317 | set current [lreplace $current $index $index] |
| | 318 | } |
| | 319 | } |
| | 320 | set current [lsort -unique $current] |
| | 321 | |
| | 322 | set bMotion_plugins_output_perchan($id) $current |
| | 323 | return 1 |
| 301 | | global bMotion_plugins_action_simple botnicks |
| 302 | | set s [lsort [array names bMotion_plugins_action_simple]] |
| 303 | | |
| 304 | | foreach key $s { |
| 305 | | if {$key == "dummy"} { continue } |
| 306 | | set val $bMotion_plugins_action_simple($key) |
| 307 | | set blah [split $val "Š"] |
| 308 | | set rexp [lindex $blah 0] |
| 309 | | set chance [lindex $blah 1] |
| 310 | | set response [lindex $blah 2] |
| 311 | | set language [lindex $blah 3] |
| 312 | | if {[string match $lang $language] || ($language == "any")|| ($language == "all")} { |
| 313 | | set rexp [bMotionInsertString $rexp "%botnicks" "${botnicks}"] |
| 314 | | if [regexp -nocase $rexp $text] { |
| 315 | | set c [rand 100] |
| 316 | | if {$chance > $c} { |
| 317 | | return $response |
| 318 | | } |
| 319 | | } |
| 320 | | } |
| 321 | | } |
| 322 | | return "" |
| | 351 | global bMotion_plugins_action_simple botnicks |
| | 352 | set s [lsort [array names bMotion_plugins_action_simple]] |
| | 353 | |
| | 354 | foreach key $s { |
| | 355 | if {$key == "dummy"} { continue } |
| | 356 | set val $bMotion_plugins_action_simple($key) |
| | 357 | set blah [split $val "Š"] |
| | 358 | set rexp [lindex $blah 0] |
| | 359 | set chance [lindex $blah 1] |
| | 360 | set response [lindex $blah 2] |
| | 361 | set language [lindex $blah 3] |
| | 362 | if {[string match $lang $language] || ($language == "any")|| ($language == "all")} { |
| | 363 | set rexp [bMotionInsertString $rexp "%botnicks" "${botnicks}"] |
| | 364 | if [regexp -nocase $rexp $text] { |
| | 365 | set c [rand 100] |
| | 366 | if {$chance > $c} { |
| | 367 | return $response |
| | 368 | } |
| | 369 | } |
| | 370 | } |
| | 371 | } |
| | 372 | return "" |
| 348 | | global bMotion_plugins_action_complex botnicks |
| 349 | | set s [lsort [array names bMotion_plugins_action_complex]] |
| 350 | | set result [list] |
| 351 | | |
| 352 | | foreach key $s { |
| 353 | | if {$key == "dummy"} { continue } |
| 354 | | set val $bMotion_plugins_action_complex($key) |
| 355 | | set blah [split $val "Š"] |
| 356 | | set rexp [lindex $blah 0] |
| 357 | | set chance [lindex $blah 1] |
| 358 | | set callback [lindex $blah 2] |
| 359 | | set language [lindex $blah 3] |
| 360 | | if {[string match $language $lang] || ($language == "any")|| ($language == "all")} { |
| 361 | | set rexp [bMotionInsertString $rexp "%botnicks" "${botnicks}"] |
| 362 | | if [regexp -nocase $rexp $text] { |
| 363 | | bMotion_putloglev 4 * "matched: $key" |
| 364 | | set c [rand 100] |
| 365 | | if {$chance > $c} { |
| 366 | | lappend result $callback |
| 367 | | } |
| 368 | | } |
| 369 | | } |
| 370 | | } |
| 371 | | return $result |
| | 398 | global bMotion_plugins_action_complex botnicks |
| | 399 | set s [lsort [array names bMotion_plugins_action_complex]] |
| | 400 | set result [list] |
| | 401 | |
| | 402 | foreach key $s { |
| | 403 | if {$key == "dummy"} { continue } |
| | 404 | set val $bMotion_plugins_action_complex($key) |
| | 405 | set blah [split $val "Š"] |
| | 406 | set rexp [lindex $blah 0] |
| | 407 | set chance [lindex $blah 1] |
| | 408 | set callback [lindex $blah 2] |
| | 409 | set language [lindex $blah 3] |
| | 410 | if {[string match $language $lang] || ($language == "any")|| ($language == "all")} { |
| | 411 | set rexp [bMotionInsertString $rexp "%botnicks" "${botnicks}"] |
| | 412 | if [regexp -nocase $rexp $text] { |
| | 413 | bMotion_putloglev 4 * "matched: $key" |
| | 414 | set c [rand 100] |
| | 415 | if {$chance > $c} { |
| | 416 | lappend result $callback |
| | 417 | } |
| | 418 | } |
| | 419 | } |
| | 420 | } |
| | 421 | return $result |
| 378 | | #pass a string in the format "type:plugin,type:plugin,..." |
| 379 | | if {$depends == ""} { |
| 380 | | return 1 |
| 381 | | } |
| 382 | | |
| 383 | | set result 1 |
| 384 | | |
| 385 | | set blah [split $depends ","] |
| 386 | | foreach depend $blah { |
| 387 | | set blah2 [split $depend ":"] |
| 388 | | set t [lindex $blah2 0] |
| 389 | | set id [lindex $blah2 1] |
| 390 | | set a "bMotion_plugins_$t" |
| 391 | | upvar #0 $a ar |
| 392 | | bMotion_putloglev 1 * "bMotion: checking $a for $id ..." |
| 393 | | set temp [array names ar $id] |
| 394 | | if {[llength $temp] == 0} { |
| 395 | | set result 0 |
| 396 | | bMotion_putloglev d * "bMotion: Missing dependency $t:$id" |
| 397 | | } |
| 398 | | } |
| 399 | | return $result |
| | 428 | #pass a string in the format "type:plugin,type:plugin,..." |
| | 429 | if {$depends == ""} { |
| | 430 | return 1 |
| | 431 | } |
| | 432 | |
| | 433 | set result 1 |
| | 434 | |
| | 435 | set blah [split $depends ","] |
| | 436 | foreach depend $blah { |
| | 437 | set blah2 [split $depend ":"] |
| | 438 | set t [lindex $blah2 0] |
| | 439 | set id [lindex $blah2 1] |
| | 440 | set a "bMotion_plugins_$t" |
| | 441 | upvar #0 $a ar |
| | 442 | &nb |