| 25 | | #check our global toggle |
| 26 | | global bMotionGlobal bMotionInfo |
| 27 | | if {$bMotionGlobal == 0} { |
| 28 | | return 0 |
| 29 | | } |
| 30 | | |
| 31 | | if [matchattr $handle J] { |
| 32 | | return 0 |
| 33 | | } |
| 34 | | |
| 35 | | set channel [string tolower $channel] |
| 36 | | |
| 37 | | #ignore other bots |
| 38 | | if {[matchattr $handle b] && (![matchattr $handle I])} { |
| 39 | | set bMotionCache($channel,last) 0 |
| 40 | | return 0 |
| 41 | | } |
| 42 | | |
| 43 | | bMotion_putloglev 4 * "entering bMotionDoEventResponse: $type $nick $host $handle $channel $text" |
| 44 | | if { ![regexp -nocase "nick|join|quit|part|split" $type] } { |
| 45 | | return 0 |
| 46 | | } |
| 47 | | |
| 48 | | global bMotionInfo |
| 49 | | set response [bMotion_plugin_find_irc_event $text $type $bMotionInfo(language)] |
| 50 | | if {[llength $response] > 0} { |
| 51 | | foreach callback $response { |
| | 25 | #check our global toggle |
| | 26 | global bMotionGlobal bMotionInfo |
| | 27 | if {$bMotionGlobal == 0} { |
| | 28 | return 0 |
| | 29 | } |
| | 30 | |
| | 31 | if [matchattr $handle J] { |
| | 32 | return 0 |
| | 33 | } |
| | 34 | |
| | 35 | set channel [string tolower $channel] |
| | 36 | |
| | 37 | #ignore other bots |
| | 38 | if {[matchattr $handle b] && (![matchattr $handle I])} { |
| | 39 | set bMotionCache($channel,last) 0 |
| | 40 | return 0 |
| | 41 | } |
| | 42 | |
| | 43 | bMotion_putloglev 4 * "entering bMotionDoEventResponse: $type $nick $host $handle $channel $text" |
| | 44 | if { ![regexp -nocase "nick|join|quit|part|split" $type] } { |
| | 45 | return 0 |
| | 46 | } |
| | 47 | |
| | 48 | global bMotionInfo |
| | 49 | set response [bMotion_plugin_find_irc_event $text $type $bMotionInfo(language)] |
| | 50 | if {[llength $response] > 0} { |
| | 51 | foreach callback $response { |
| 141 | | set nick [bMotion_cleanNick $nick $handle] |
| 142 | | |
| 143 | | bMotion_plugins_settings_set "system" "lastleft" $channel "" $nick |
| 144 | | |
| 145 | | if {$bMotionInfo(brig) != ""} { |
| 146 | | #check if that person was in the brig |
| 147 | | regexp -nocase "(.+)@(.+)" $bMotionInfo(brig) pop brigNick brigChannel |
| 148 | | if [string match -nocase $nick $brigNick] { |
| 149 | | set bMotionInfo(brig) "" |
| 150 | | bMotionDoAction $brigChannel "" "Curses! They escaped from the brig." |
| 151 | | return 0 |
| 152 | | } |
| 153 | | } |
| 154 | | set result [bMotionDoEventResponse "quit" $nick $host $handle $channel $reason ] |
| | 141 | set nick [bMotion_cleanNick $nick $handle] |
| | 142 | |
| | 143 | bMotion_plugins_settings_set "system" "lastleft" $channel "" $nick |
| | 144 | |
| | 145 | if {$bMotionInfo(brig) != ""} { |
| | 146 | #check if that person was in the brig |
| | 147 | regexp -nocase "(.+)@(.+)" $bMotionInfo(brig) pop brigNick brigChannel |
| | 148 | if [string match -nocase $nick $brigNick] { |
| | 149 | set bMotionInfo(brig) "" |
| | 150 | bMotionDoAction $brigChannel "" "Curses! They escaped from the brig." |
| | 151 | return 0 |
| | 152 | } |
| | 153 | } |
| | 154 | set result [bMotionDoEventResponse "quit" $nick $host $handle $channel $reason ] |
| 159 | | #check our global toggle |
| 160 | | global bMotionGlobal bMotionPluginHistory |
| 161 | | if {$bMotionGlobal == 0} { |
| 162 | | return 0 |
| 163 | | } |
| 164 | | |
| 165 | | ## Global definitions ## |
| 166 | | global mood botnick |
| 167 | | global bMotionLastEvent bMotionSettings botnicks bMotionCache bMotionInfo |
| 168 | | global bMotionThisText bMotionOriginalInput bMotionOriginalNick |
| 169 | | |
| 170 | | if [matchattr $handle J] { |
| 171 | | return 0 |
| 172 | | } |
| 173 | | |
| 174 | | set bMotionOriginalNick $nick |
| 175 | | |
| 176 | | set channel [string tolower $channel] |
| 177 | | |
| 178 | | #ignore other bots |
| 179 | | if {[matchattr $handle b] && (![matchattr $handle I])} { |
| 180 | | set bMotionCache($channel,last) 0 |
| 181 | | return 0 |
| 182 | | } |
| | 159 | #check our global toggle |
| | 160 | global bMotionGlobal bMotionPluginHistory |
| | 161 | if {$bMotionGlobal == 0} { |
| | 162 | return 0 |
| | 163 | } |
| | 164 | |
| | 165 | ## Global definitions ## |
| | 166 | global mood botnick |
| | 167 | global bMotionLastEvent bMotionSettings botnicks bMotionCache bMotionInfo |
| | 168 | global bMotionThisText bMotionOriginalInput bMotionOriginalNick |
| | 169 | |
| | 170 | if [matchattr $handle J] { |
| | 171 | return 0 |
| | 172 | } |
| | 173 | |
| | 174 | set bMotionOriginalNick $nick |
| | 175 | |
| | 176 | set channel [string tolower $channel] |
| | 177 | |
| | 178 | #ignore other bots |
| | 179 | if {[matchattr $handle b] && (![matchattr $handle I])} { |
| | 180 | set bMotionCache($channel,last) 0 |
| | 181 | return 0 |
| | 182 | } |
| 198 | | |
| 199 | | bMotion_putloglev 4 * "bMotion: entering bMotion_event_main with nick: $nick host: $host handle: $handle chan: $channel text: $text" |
| 200 | | |
| 201 | | set bMotionOriginalInput $text |
| 202 | | |
| 203 | | #filter bold, etc codes out |
| 204 | | regsub -all "\002" $text "" text |
| 205 | | regsub -all "\022" $text "" text |
| 206 | | regsub -all "\037" $text "" text |
| | 198 | |
| | 199 | bMotion_putloglev 4 * "bMotion: entering bMotion_event_main with nick: $nick host: $host handle: $handle chan: $channel text: $text" |
| | 200 | |
| | 201 | bMotion_queue_dupecheck $text $channel |
| | 202 | |
| | 203 | set bMotionOriginalInput $text |
| | 204 | |
| | 205 | #filter bold, etc codes out |
| | 206 | regsub -all "\002" $text "" text |
| | 207 | regsub -all "\022" $text "" text |
| | 208 | regsub -all "\037" $text "" text |
| 218 | | #does this look like a paste? |
| 219 | | if [regexp -nocase {^[([]?[0-9]{2}[-:.][0-9]{2}. ?[[<(]?[%@+]?[a-z0-9` ]+[@+%]?. \w+} $text] { |
| 220 | | return 0 |
| 221 | | } |
| 222 | | |
| 223 | | ## Update the channel idle tracker |
| 224 | | set bMotionLastEvent($channel) [clock seconds] |
| 225 | | |
| 226 | | #don't let people break us |
| 227 | | if {![matchattr $handle n]} { |
| 228 | | if [regexp -nocase "%(pronoun|me|noun|colen|percent|VAR|\\|)" $text] { |
| 229 | | regsub -all "%" $text "%percent" text |
| 230 | | } |
| 231 | | } |
| 232 | | regsub -all "\</" $text "%slash" text |
| 233 | | |
| 234 | | #If this isn't just a smiley of some kind, trim smilies |
| 235 | | if {[string length $text] >= ([string length $botnick] + 4)} { |
| 236 | | regsub -all -nocase {[;:=]-?[()d<>/sp9x]} $text "" text |
| 237 | | regsub -all {([\-^])_*[\-^];*} $text "" text |
| | 220 | #does this look like a paste? |
| | 221 | if [regexp -nocase {^[([]?[0-9]{2}[-:.][0-9]{2}. ?[[<(]?[%@+]?[a-z0-9` ]+[@+%]?. \w+} $text] { |
| | 222 | return 0 |
| | 223 | } |
| | 224 | |
| | 225 | ## Update the channel idle tracker |
| | 226 | set bMotionLastEvent($channel) [clock seconds] |
| | 227 | |
| | 228 | #don't let people break us |
| | 229 | if {![matchattr $handle n]} { |
| | 230 | if [regexp -nocase "%(pronoun|me|noun|colen|percent|VAR|\\|)" $text] { |
| | 231 | regsub -all "%" $text "%percent" text |
| | 232 | } |
| | 233 | } |
| | 234 | regsub -all "\</" $text "%slash" text |
| | 235 | |
| | 236 | #If this isn't just a smiley of some kind, trim smilies |
| | 237 | if {[string length $text] >= ([string length $botnick] + 4)} { |
| | 238 | regsub -all -nocase {[;:=]-?[()d<>/sp9x]} $text "" text |
| | 239 | regsub -all {([\-^])_*[\-^];*} $text "" text |
| 239 | | } |
| 240 | | |
| 241 | | #Trim stuff |
| 242 | | set text [string trim $text] |
| 243 | | |
| 244 | | ## Dump double+ spaces |
| 245 | | regsub -all " +" $text " " text |
| 246 | | |
| 247 | | ## Update the last-talked flag for the join system |
| 248 | | bMotion_plugins_settings_set "system:join" "lasttalk" $channel "" 0 |
| 249 | | |
| 250 | | set bMotionThisText $text |
| 251 | | |
| 252 | | #if we spoke last, add "$botnick: " if it's not in the line |
| 253 | | if {![regexp -nocase $botnicks $text] && ([bMotion_did_i_speak_last $channel] || ([bMotion_setting_get "bitlbee"] == "1"))} { |
| 254 | | if [regexp {^[^:]+:.+} $text] { |
| 255 | | #since our nick isn't in the line and they're addressing someone, drop this line |
| 256 | | return 0 |
| 257 | | } |
| 258 | | set text "${botnick}: $text" |
| 259 | | } |
| 260 | | |
| 261 | | if {[bMotion_setting_get "bitlbee"] == "1"} { |
| 262 | | bMotion_putloglev d * "bitlbee incoming from $nick: $text" |
| 263 | | } |
| 264 | | |
| 265 | | #check for someone breaking the loop of lastSpoke |
| 266 | | if {[regexp -nocase "(i'm not talking to|not) you" $text] && $bMotionCache($channel,last)} { |
| 267 | | bMotionDoAction $channel $nick "oh" |
| 268 | | set bMotionCache($channel,last) 0 |
| 269 | | return 0 |
| 270 | | } |
| 271 | | set bMotionCache($channel,last) 0 |
| 272 | | |
| 273 | | #Run the simple plugins |
| 274 | | set response [bMotion_plugin_find_simple $text $bMotionInfo(language)] |
| 275 | | if {$response != ""} { |
| 276 | | bMotion_flood_add $nick "" $text |
| 277 | | if [bMotion_flood_check $nick] { return 0 } |
| 278 | | set nick [bMotionGetRealName $nick $host] |
| 279 | | bMotionDoAction $channel $nick [pickRandom $response] |
| 280 | | return 0 |
| 281 | | } |
| 282 | | |
| 283 | | #Run the complex plugins |
| 284 | | set response [bMotion_plugin_find_complex $text $bMotionInfo(language)] |
| 285 | | if {[llength $response] > 0} { |
| 286 | | #set nick [bMotionGetRealName $nick $host] |
| 287 | | bMotion_putloglev 1 * "going to run plugins: $response" |
| 288 | | foreach callback $response { |
| | 241 | } |
| | 242 | |
| | 243 | #Trim stuff |
| | 244 | set text [string trim $text] |
| | 245 | |
| | 246 | ## Dump double+ spaces |
| | 247 | regsub -all " +" $text " " text |
| | 248 | |
| | 249 | ## Update the last-talked flag for the join system |
| | 250 | bMotion_plugins_settings_set "system:join" "lasttalk" $channel "" 0 |
| | 251 | |
| | 252 | set bMotionThisText $text |
| | 253 | |
| | 254 | #if we spoke last, add "$botnick: " if it's not in the line |
| | 255 | if {![regexp -nocase $botnicks $text] && ([bMotion_did_i_speak_last $channel] || ([bMotion_setting_get "bitlbee"] == "1"))} { |
| | 256 | if [regexp {^[^:]+:.+} $text] { |
| | 257 | #since our nick isn't in the line and they're addressing someone, drop this line |
| | 258 | return 0 |
| | 259 | } |
| | 260 | set text "${botnick}: $text" |
| | 261 | } |
| | 262 | |
| | 263 | if {[bMotion_setting_get "bitlbee"] == "1"} { |
| | 264 | bMotion_putloglev d * "bitlbee incoming from $nick: $text" |
| | 265 | } |
| | 266 | |
| | 267 | #check for someone breaking the loop of lastSpoke |
| | 268 | if {[regexp -nocase "(i'm not talking to|not) you" $text] && $bMotionCache($channel,last)} { |
| | 269 | bMotionDoAction $channel $nick "oh" |
| | 270 | set bMotionCache($channel,last) 0 |
| | 271 | return 0 |
| | 272 | } |
| | 273 | set bMotionCache($channel,last) 0 |
| | 274 | |
| | 275 | #Run the simple plugins |
| | 276 | set response [bMotion_plugin_find_simple $text $bMotionInfo(language)] |
| | 277 | if {$response != ""} { |
| | 278 | bMotion_flood_add $nick "" $text |
| | 279 | if [bMotion_flood_check $nick] { return 0 } |
| | 280 | set nick [bMotionGetRealName $nick $host] |
| | 281 | bMotionDoAction $channel $nick [pickRandom $response] |
| | 282 | return 0 |
| | 283 | } |
| | 284 | |
| | 285 | #Run the complex plugins |
| | 286 | set response [bMotion_plugin_find_complex $text $bMotionInfo(language)] |
| | 287 | if {[llength $response] > 0} { |
| | 288 | #set nick [bMotionGetRealName $nick $host] |
| | 289 | bMotion_putloglev 1 * "going to run plugins: $response" |
| | 290 | foreach callback $response { |
| 306 | | bMotion_putloglev 2 * "bMotion: `-$callback returned $result, breaking out..." |
| 307 | | break |
| 308 | | } |
| 309 | | } |
| 310 | | } |
| 311 | | |
| 312 | | #Check for all caps |
| 313 | | regsub -all {[^A-Za-z]} $text "" textChars |
| 314 | | regsub -all {[a-z]} $textChars "" textLowerChars |
| 315 | | if {(([string length $textChars] > 4) && ([expr [string length $textLowerChars] / [string length $textChars]] > 0.9)) || |
| 316 | | [regexp ".+!{4,}" $text]} { |
| 317 | | global blownAways |
| 318 | | if {[rand 60] >= 55} { |
| 319 | | bMotionDoAction $channel $nick "%VAR{blownAways}" |
| 320 | | return 0 |
| 321 | | } |
| 322 | | } |
| 323 | | |
| 324 | | #Reload config files |
| | 308 | bMotion_putloglev 2 * "bMotion: `-$callback returned $result, breaking out..." |
| | 309 | break |
| | 310 | } |
| | 311 | } |
| | 312 | } |
| | 313 | |
| | 314 | #Check for all caps |
| | 315 | regsub -all {[^A-Za-z]} $text "" textChars |
| | 316 | regsub -all {[a-z]} $textChars "" textLowerChars |
| | 317 | if {(([string length $textChars] > 4) && ([expr [string length $textLowerChars] / [string length $textChars]] > 0.9)) || |
| | 318 | [regexp ".+!{4,}" $text]} { |
| | 319 | global blownAways |
| | 320 | if {[rand 60] >= 55} { |
| | 321 | bMotionDoAction $channel $nick "%VAR{blownAways}" |
| | 322 | return 0 |
| | 323 | } |
| | 324 | } |
| | 325 | |
| | 326 | #Reload config files |
| 326 | | if [regexp -nocase "${botnicks},?:? re(hash|load)( your config files?)?" $text] { |
| 327 | | #putlog "bMotion: $nick asked me to rehash in $channel" |
| 328 | | global bMotion_testing bMotionRoot |
| 329 | | |
| 330 | | if [matchattr $handle m] { |
| 331 | | #check we're not going to die |
| 332 | | catch { |
| 333 | | bMotion_putloglev d * "bMotion: Testing new code..." |
| 334 | | set bMotion_testing 1 |
| 335 | | source "$bMotionRoot/bMotion.tcl" |
| 336 | | } msg |
| 337 | | |
| 338 | | if {$msg != ""} { |
| 339 | | putlog "bMotion: FATAL: Cannot rehash due to error: $msg" |
| 340 | | putserv "NOTICE $nick :FATAL: Cannot rehash: $msg" |
| 341 | | putchan $channel "A tremendous error occurred!" |
| 342 | | return 0 |
| 343 | | } else { |
| 344 | | bMotion_putloglev d * "bMotion: New code ok, rehashing..." |
| 345 | | bMotion_plugins_settings_set "system" "rehash" "" "" $channel |
| 346 | | set bMotion_testing 0 |
| 347 | | if {[matchattr $handle m]} { |
| 348 | | putchan $channel [bMotionDoInterpolation "%VAR{rehashes}" "" ""] |
| 349 | | rehash |
| 350 | | return 0 |
| 351 | | } |
| 352 | | } |
| 353 | | } else { |
| 354 | | #don't respond here because there's no flood protection |
| 355 | | return 0 |
| 356 | | } |
| 357 | | } |
| | 328 | if [regexp -nocase "${botnicks},?:? re(hash|load)( your config files?)?" $text] { |
| | 329 | #putlog "bMotion: $nick asked me to rehash in $channel" |
| | 330 | global bMotion_testing bMotionRoot |
| | 331 | |
| | 332 | if [matchattr $handle m] { |
| | 333 | #check we're not going to die |
| | 334 | catch { |
| | 335 | bMotion_putloglev d * "bMotion: Testing new code..." |
| | 336 | set bMotion_testing 1 |
| | 337 | source "$bMotionRoot/bMotion.tcl" |
| | 338 | } msg |
| | 339 | |
| | 340 | if {$msg != ""} { |
| | 341 | putlog "bMotion: FATAL: Cannot rehash due to error: $msg" |
| | 342 | putserv "NOTICE $nick :FATAL: Cannot rehash: $msg" |
| | 343 | putchan $channel "A tremendous error occurred!" |
| | 344 | return 0 |
| | 345 | } else { |
| | 346 | bMotion_putloglev d * "bMotion: New code ok, rehashing..." |
| | 347 | bMotion_plugins_settings_set "system" "rehash" "" "" $channel |
| | 348 | set bMotion_testing 0 |
| | 349 | if {[matchattr $handle m]} { |
| | 350 | putchan $channel [bMotionDoInterpolation "%VAR{rehashes}" "" ""] |
| | 351 | rehash |
| | 352 | return 0 |
| | 353 | } |
| | 354 | } |
| | 355 | } else { |
| | 356 | #don't respond here because there's no flood protection |
| | 357 | return 0 |
| | 358 | } |
| | 359 | } |
| 386 | | if [regexp -nocase "^${botnicks}:?,? (silence|shut up|be quiet|go away)" $text] { |
| 387 | | driftFriendship $nick -10 |
| 388 | | bMotionSilence $nick $host $channel |
| 389 | | return 0 |
| 390 | | } |
| 391 | | |
| 392 | | if [regexp -nocase "(silence|shut up|be quiet|go away),?;? ${botnicks}" $text] { |
| 393 | | driftFriendship $nick -10 |
| 394 | | bMotionSilence $nick $host $channel |
| 395 | | return 0 |
| 396 | | } |
| | 388 | if [regexp -nocase "^${botnicks}:?,? (silence|shut up|be quiet|go away)" $text] { |
| | 389 | driftFriendship $nick -10 |
| | 390 | bMotionSilence $nick $host $channel |
| | 391 | return 0 |
| | 392 | } |
| | 393 | |
| | 394 | if [regexp -nocase "(silence|shut up|be quiet|go away),?;? ${botnicks}" $text] { |
| | 395 | driftFriendship $nick -10 |
| | 396 | bMotionSilence $nick $host $channel |
| | 397 | return 0 |
| | 398 | } |