Changeset 929
- Timestamp:
- 30/06/2008 15:35:13 (3 months ago)
- Location:
- trunk/modules
- Files:
-
- 2 modified
-
output.tcl (modified) (27 diffs)
-
system.tcl (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/output.tcl
r926 r929 1 1 #bMotion - Output functions 2 #3 # $Id$4 2 # 5 3 # vim: fdm=indent fdn=1 … … 24 22 ############################################################################### 25 23 26 # init our counters27 bMotion_counter_init "output" "lines"28 bMotion_counter_init "output" "irclines"29 30 24 set bMotion_output_delay 0 31 25 26 # 27 # pick a random element from a list 32 28 proc pickRandom { list } { 33 29 bMotion_putloglev 5 * "pickRandom ($list)" … … 35 31 } 36 32 33 # 34 # get the pronoun for our gender 37 35 proc getPronoun {} { 38 36 bMotion_putloglev 5 * "getPronoun" 39 global bMotionInfo 40 if {$bMotionInfo(gender) == "male"} { return "himself" } 41 if {$bMotionInfo(gender) == "female"} { return "herself" } 42 return "itself" 43 } 44 37 set gender [bMotion_setting_get "gender"] 38 39 switch $gender { 40 "male" { 41 return "himself" 42 } 43 "female" { 44 return "herself" 45 } 46 default { 47 return "its" 48 } 49 } 50 } 51 52 # 53 # get "his" or "hers" for our gender 45 54 proc getHisHers {} { 46 55 bMotion_putloglev 5 * "getHisHers" 47 global bMotionInfo 48 if {$bMotionInfo(gender) == "male"} { return "his" } 49 if {$bMotionInfo(gender) == "female"} { return "hers" } 50 return "its" 51 } 52 56 57 set gender [bMotion_setting_get "gender"] 58 59 switch $gender { 60 "male" { 61 return "his" 62 } 63 "female" { 64 return "hers" 65 } 66 default { 67 return "its" 68 } 69 } 70 } 71 72 # 73 # get "her" or "her" for our gender 53 74 proc getHisHer {} { 54 75 bMotion_putloglev 5 * "getHisHer" 55 global bMotionInfo 56 if {$bMotionInfo(gender) == "male"} { return "his" } 57 if {$bMotionInfo(gender) == "female"} { return "her" } 58 return "it" 59 } 60 61 76 77 set gender [bMotion_setting_get "gender"] 78 79 switch $gender { 80 "male" { 81 return "his" 82 } 83 "female" { 84 return "her" 85 } 86 default { 87 return "it" 88 } 89 } 90 } 91 92 # 93 # get "he" or "she" for our gender 62 94 proc getHeShe {} { 63 95 bMotion_putloglev 5 * "getHeShe" 64 global bMotionInfo 65 if {$bMotionInfo(gender) == "male"} { return "he" } 66 if {$bMotionInfo(gender) == "female"} { return "she" } 67 return "it" 68 } 69 70 96 97 set gender [bMotion_setting_get "gender"] 98 99 switch $gender { 100 "male" { 101 return "he" 102 } 103 "female" { 104 return "she" 105 } 106 default { 107 return "it" 108 } 109 } 110 } 111 112 # 113 # do a /me action 71 114 proc mee {channel action {urgent 0} } { 72 115 bMotion_putloglev 5 * "mee ($channel, $action, $urgent)" … … 79 122 } 80 123 81 82 # # bMotionDoAction ###########################################################124 # 125 # our magic output function 83 126 proc bMotionDoAction {channel nick text {moreText ""} {noTypo 0} {urgent 0} } { 84 127 bMotion_putloglev 5 * "bMotionDoAction($channel,$nick,$text,$moreText,$noTypo)" … … 97 140 98 141 # check if we're asleep 99 if { $bMotionSettings(asleep)== $BMOTION_SLEEP(ASLEEP)} {100 return 0142 if {[bMotion_setting_get "asleep"] == $BMOTION_SLEEP(ASLEEP)} { 143 return 0 101 144 } 102 145 … … 109 152 } 110 153 111 if { $bMotionInfo(silence)== 1} { return 0 }154 if {[bMotion_setting_get "silence"] == 1} { return 0 } 112 155 catch { 113 156 if {$bMotionInfo(adminSilence,$channel) == 1} { return 0 } 114 157 } 115 158 116 bMotion_counter_incr "output" "lines" 117 159 # TODO: ugly, refactor? 118 160 switch [rand 3] { 119 161 0 { } … … 172 214 } 173 215 bMotion_plugins_settings_set "output:typos" "typos" "" "" "" 174 175 176 216 } 177 217 return 0 … … 192 232 } 193 233 234 235 # 236 # replace things on lines 194 237 proc bMotionDoInterpolation { line nick moreText { channel "" } } { 195 238 bMotion_putloglev 5 * "bMotionDoInterpolation: line = $line, nick = $nick, moreText = $moreText, channel = $channel" … … 340 383 } 341 384 385 # 386 # more replacements in a line 387 # TODO: why was this separate? 342 388 proc bMotionInterpolation2 { line } { 343 389 bMotion_putloglev 5 * "bMotionInterpolation2 ($line)" … … 348 394 set BOOM [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\} $ \\\$ \" \\\" | \\\|} $BOOM] 349 395 350 incr loops 351 if {$loops > 10} { 352 putlog "bMotion: ALERT! looping too much in %OWNER code with $line" 353 set line "/has a tremendous error while trying to sort something out :(" 354 } 355 # set line [bMotionInsertString $line "%OWNER\{$BOOM\}" [bMotionMakePossessive $BOOM]] 356 regsub -nocase "%OWNER\{$BOOM\}" $line [bMotionMakePossessive $BOOM] line 357 regsub -all "\\\\" $line "" line 358 } 359 360 set loops 0 361 while {[regexp -nocase "%VERB\{(.*?)\}" $line matches BOOM]} { 362 incr loops 363 if {$loops > 10} { 364 putlog "bMotion: ALERT! looping too much in %VERB code with $line" 365 set line "/has a tremendous error while trying to sort something out :(" 366 } 367 # set line [bMotionInsertString $line "%VERB\{$BOOM\}" [bMotionMakeVerb $BOOM]] 368 regsub -nocase "%VERB\{$BOOM\}" $line [bMotionMakeVerb $BOOM] line 369 } 370 371 set loops 0 372 while {[regexp -nocase "%PLURAL\{(.*?)\}" $line matches BOOM]} { 373 incr loops 374 if {$loops > 10} { 375 putlog "bMotion: ALERT! looping too much in %PLURAL code with $line" 376 set line "/has a tremendous error while trying to sort something out :(" 377 } 378 # set line [bMotionInsertString $line "%PLURAL\{$BOOM\}" [bMotionMakePlural $BOOM]] 379 regsub -nocase "%PLURAL\{$BOOM\}" $line [bMotionMakePlural $BOOM] line 380 } 381 382 set loops 0 383 while {[regexp -nocase "%REPEAT\{(.+?)\}" $line matches BOOM]} { 384 incr loops 385 if {$loops > 10} { 386 putlog "bMotion: ALERT! looping too much in %REPEAT code with $line" 387 set line "/has a tremendous error while trying to sort something out :(" 388 } 389 set replacement [bMotionMakeRepeat $BOOM] 390 regsub -nocase "%REPEAT\\{$BOOM\\}" $line $replacement line 391 } 392 393 return $line 394 } 395 396 incr loops 397 if {$loops > 10} { 398 putlog "bMotion: ALERT! looping too much in %OWNER code with $line" 399 set line "/has a tremendous error while trying to sort something out :(" 400 } 401 # set line [bMotionInsertString $line "%OWNER\{$BOOM\}" [bMotionMakePossessive $BOOM]] 402 regsub -nocase "%OWNER\{$BOOM\}" $line [bMotionMakePossessive $BOOM] line 403 regsub -all "\\\\" $line "" line 404 } 405 406 set loops 0 407 while {[regexp -nocase "%VERB\{(.*?)\}" $line matches BOOM]} { 408 incr loops 409 if {$loops > 10} { 410 putlog "bMotion: ALERT! looping too much in %VERB code with $line" 411 set line "/has a tremendous error while trying to sort something out :(" 412 } 413 # set line [bMotionInsertString $line "%VERB\{$BOOM\}" [bMotionMakeVerb $BOOM]] 414 regsub -nocase "%VERB\{$BOOM\}" $line [bMotionMakeVerb $BOOM] line 415 } 416 417 set loops 0 418 while {[regexp -nocase "%PLURAL\{(.*?)\}" $line matches BOOM]} { 419 incr loops 420 if {$loops > 10} { 421 putlog "bMotion: ALERT! looping too much in %PLURAL code with $line" 422 set line "/has a tremendous error while trying to sort something out :(" 423 } 424 # set line [bMotionInsertString $line "%PLURAL\{$BOOM\}" [bMotionMakePlural $BOOM]] 425 regsub -nocase "%PLURAL\{$BOOM\}" $line [bMotionMakePlural $BOOM] line 426 } 427 428 set loops 0 429 while {[regexp -nocase "%REPEAT\{(.+?)\}" $line matches BOOM]} { 430 incr loops 431 if {$loops > 10} { 432 putlog "bMotion: ALERT! looping too much in %REPEAT code with $line" 433 set line "/has a tremendous error while trying to sort something out :(" 434 } 435 set replacement [bMotionMakeRepeat $BOOM] 436 regsub -nocase "%REPEAT\\{$BOOM\\}" $line $replacement line 437 } 438 439 return $line 440 } 441 442 # 443 # Process a line 444 # TODO: why is this separate or at least such a mess :) 396 445 proc bMotionSayLine {channel nick line {moreText ""} {noTypo 0} {urgent 0} } { 397 446 bMotion_putloglev 5 * "bMotionSayLine: channel = $channel, nick = $nick, line = $line, moreText = $moreText, noTypo = $noTypo" … … 402 451 403 452 #TODO: Put %ruser and %rbot back in here 453 # XXX: is the above TODO still valid? 404 454 405 455 #if it's a bot , put it on the queue on the remote bot … … 408 458 set dobreak 0 409 459 if {$botcmd == "bot"} { 410 #random460 #random 411 461 bMotion_putloglev 1 * "bMotion: %bot detected" 412 462 regexp {%bot\[([[:digit:]]+),(@[^,]+,)?(.+)\]} $line matches chance condition cmd … … 420 470 } 421 471 } else { 422 #non-random423 regexp {%BOT\[(@[^,]+,)?(.+)\]} $line matches condition cmd472 #non-random 473 regexp {%BOT\[(@[^,]+,)?(.+)\]} $line matches condition cmd 424 474 } 425 475 … … 509 559 #we try an admin plugin 510 560 if [info exists bMotionOriginalInput] { 511 if [string match -nocase $bMotionOriginalInput $line] { 512 bMotion_putloglev 1 * "my output matches the trigger, dropping" 561 if [string match -nocase $bMotionOriginalInput $line] { 562 bMotion_putloglev 1 * "my output matches the trigger, dropping" 563 return 0 564 } 565 } 566 567 set line [bMotionInsertString $line "%slash" "/"] 568 569 global bMotion_output_delay 570 571 if [regexp "^/" $line] { 572 #it's an action 573 mee $channel [string range $line 1 end] $urgent 574 } else { 575 if {$urgent} { 576 bMotion_queue_add_now [chandname2name $channel] $line 577 } else { 578 bMotion_queue_add [chandname2name $channel] $line $bMotion_output_delay 579 } 580 } 513 581 return 0 514 } 515 } 516 517 set line [bMotionInsertString $line "%slash" "/"] 518 519 global bMotion_output_delay 520 521 if [regexp "^/" $line] { 522 #it's an action 523 mee $channel [string range $line 1 end] $urgent 524 } else { 525 if {$urgent} { 526 bMotion_queue_add_now [chandname2name $channel] $line 527 } else { 528 bMotion_queue_add [chandname2name $channel] $line $bMotion_output_delay 529 } 530 } 531 return 0 532 } 533 582 } 583 584 # 585 # Helper function to swap one thing (like a macro) for another 534 586 proc bMotionInsertString {line swapout toInsert} { 535 587 bMotion_putloglev 5 * "bMotionInsertString ($line, $swapout, $toInsert)" … … 548 600 } 549 601 602 # 603 # Get random chars as would be made by shift-numberkeys 550 604 proc bMotionGetColenChars {} { 551 605 bMotion_putloglev 5 * "bMotionGetColenChars" … … 569 623 } 570 624 625 # 626 # make a smiley representing our mood 627 # TOOD: still used? 571 628 proc makeSmiley { mood } { 572 629 bMotion_putloglev 5 * "makeSmiley" … … 589 646 } 590 647 591 ## Wash nick 592 # Attempt to clean a nickname up to a proper name 593 # 648 # 649 # Attempt to clean a nickname up to a proper name 594 650 proc bMotionWashNick { nick } { 595 651 bMotion_putloglev 5 * "bMotionWashNick ($nick)" … … 603 659 } 604 660 661 # 662 # replace a nick with one of someone's IRL names 663 # TODO: no longer used? if not, delete 605 664 proc OLDbMotionGetRealName { nick { host "" }} { 606 665 bMotion_putloglev 5 * "bMotion: OLDbMotionGetRealName($nick,$host)" … … 641 700 } 642 701 702 # 703 # replace a nick with one of someone's IRL names 643 704 proc bMotionGetRealName { nick { host "" }} { 644 705 bMotion_putloglev 5 * "bMotion: bMotionGetRealName($nick,$host)" … … 679 740 } 680 741 742 # 743 # 681 744 proc bMotionTransformNick { target nick {host ""} } { 682 745 bMotion_putloglev 5 * "bMotionTransformNick($target, $nick, $host)" … … 688 751 } 689 752 753 # 754 # 690 755 proc bMotionTransformTarget { target {host ""} } { 691 756 bMotion_putloglev 5 * "bMotionTransformTarget($target, $host)" … … 863 928 } 864 929 930 # 931 # turn a name into the posessive form 865 932 proc bMotionMakePossessive { text { altMode 0 }} { 866 933 bMotion_putloglev 5 * "bMotionMakePossessive ($text, $altMode)" … … 889 956 } 890 957 958 # 959 # Function which powers %REPEAT 891 960 proc bMotionMakeRepeat { text } { 892 961 bMotion_putloglev 5 * "bMotionMakeRepeat ($text)" … … 906 975 } 907 976 977 # 978 # remove preceeding fluff from a noun 908 979 proc bMotion_strip_article { text } { 909 980 bMotion_putloglev 5 * "bMotion_strip_article ($text)" … … 912 983 } 913 984 985 # 986 # verbs a noun (like that) 914 987 proc bMotionMakeVerb { text } { 915 988 bMotion_putloglev 5 * "bMotionMakeVerb ($text)" … … 927 1000 return $text 928 1001 } 1002 1003 # 1004 # not sure! 929 1005 proc chr c { 930 1006 if {[string length $c] > 1 } { error "chr: arg should be a single char"} … … 935 1011 } 936 1012 937 1013 # 1014 # pluralise a noun by the simple rules of English 938 1015 proc bMotionMakePlural { text } { 939 1016 bMotion_putloglev 5 * "bMotionMakePlural ($text)" -
trunk/modules/system.tcl
r908 r929 23 23 24 24 25 ### init our counters <<<1 26 bMotion_counter_init "system" "randomstuff" 27 28 29 ### Set up the binds <<<1 30 31 #General IRC events <<<2 25 26 ### Set up the binds 27 28 #General IRC events 32 29 bind join - *!*@* bMotion_event_onjoin 33 30 bind mode - * bMotion_event_mode … … 38 35 bind ctcp - ACTION bMotion_event_action 39 36 40 #bMotion IRC events <<<237 #bMotion IRC events 41 38 bind pub - "!mood" pubm_moodhandler 42 39 bind pub - "!bminfo" bMotionInfo … … 47 44 bind pub - .bmotion bMotionAdminHandler2 48 45 49 #DCC commands <<<246 #DCC commands 50 47 bind dcc m mood moodhandler 51 48 bind dcc m bmotion* bMotion_dcc_command … … 56 53 bind time - "* * * * *" bMotion_check_tired2 57 54 58 # ## bMotion_update_chanlist <<<155 # 59 56 # rebuilds our channel list based on which channels are +bmotion 60 57 proc bMotion_update_chanlist { } { … … 68 65 } 69 66 } 70 ### Initalise some variables per channel <<<1 67 68 # 69 # Initalise some variables per channel 71 70 bMotion_update_chanlist 71 72 72 foreach chan $bMotionChannels { 73 73 set bMotionLastEvent($chan) [clock seconds] … … 76 76 #used to make the bot a bit more intelligent (perhaps) at conversations 77 77 set bMotionCache($chan,last) 0 78 #channel mood tracker 79 #set bMotionCache($chan,mood) 0 80 } 81 82 ### bMotionStats <<<1 78 } 79 80 # bMotionStats 81 # TODO: retire this 83 82 proc bMotionStats {nick host handle channel text} { 84 83 global bMotionInfo botnicks bMotionSettings cvsinfo botnick … … 113 112 114 113 115 114 # 116 115 # check if a channel is active enough for randomy things 117 116 proc bMotion_is_active_enough { channel { limit 0 } } { … … 143 142 } 144 143 144 # 145 145 # check if every channel we can see is idle enough for us to go away 146 146 proc bMotion_random_away {} { … … 193 193 } 194 194 195 # 195 196 # periodically sprout randomness (or go /away if idle enough) 196 197 proc doRandomStuff {} { … … 265 266 } 266 267 267 ### bMotionSaySomethingRandom <<<1 268 # 269 # Output random gibberish 268 270 proc bMotionSaySomethingRandom {channel {busy 0}} { 269 271 global randomStuff stonedRandomStuff mood bMotionInfo bMotionCache … … 303 305 304 306 305 ### bMotionSetRandomAway <<<1 307 # 308 #set myself away with a random message 306 309 proc bMotionSetRandomAway {} { 307 #set myself away with a random message308 310 global randomAways bMotionInfo bMotionSettings bMotionChannels 309 311 … … 321 323 } 322 324 323 ### bMotionSetRandomBack <<<1 325 # 326 # set myself back 324 327 proc bMotionSetRandomBack {} { 325 328 #set myself back … … 343 346 } 344 347 345 ### bMotionTalkingToMe <<<1 348 # 349 # check if a line looks like it's addressed to me 346 350 proc bMotionTalkingToMe { text } { 347 351 global botnicks … … 367 371 } 368 372 369 # ## bMotionSilence <<<1370 # Makes the botshut up373 # 374 # We need to shut up 371 375 proc bMotionSilence {nick host channel} { 372 376 global bMotionInfo silenceAways bMotionSettings … … 384 388 } 385 389 386 # ## bMotionUnSilence <<<1387 # Undoes the shut up command390 # 391 # Enough shutting up for now 388 392 proc bMotionUnSilence {} { 389 393 # Timer for silence expires … … 395 399 } 396 400 397 ### bMotionLike <<<1401 ### bMotionLike 398 402 proc bMotionLike {nick { host "" }} { 399 403 global bMotionInfo mood bMotionSettings … … 463 467 } 464 468 465 ### bMotionGetGender <<<1469 ### bMotionGetGender 466 470 proc bMotionGetGender { nick host } { 467 471 set host "$nick!$host" … … 474 478 } 475 479 476 ### getHour <<<1480 ### getHour 477 481 proc getHour {} { 478 482 return [clock format [clock seconds] -format "%H"] … … 480 484 481 485 482 ### bMotion_dcc_command <<<1486 ### bMotion_dcc_command 483 487 proc bMotion_dcc_command { handle idx arg } { 484 488 global bMotionInfo … … 564 568 } 565 569 566 ### bMotion_dcc_help <<<1570 ### bMotion_dcc_help 567 571 proc bMotion_dcc_help { handle idx arg } { 568 572 putidx $idx "Please use .bmotion help" … … 572 576 573 577 ### new admin plugins ("management") 574 ### bMotionAdminHandler2 <<<1578 ### bMotionAdminHandler2 575 579 proc bMotionAdminHandler2 {nick host handle channel text} { 576 580 global botnicks bMotionInfo botnick bMotionSettings … … 631 635 632 636 633 ### bMotion_putadmin <<<1637 ### bMotion_putadmin 634 638 proc bMotion_putadmin { text } { 635 639 … … 656 660 } 657 661 658 ### bMotionAdminHandler <<<1662 ### bMotionAdminHandler 659 663 #TODO: is this ever used now? 660 664 proc bMotionAdminHandler {nick host handle channel text} {
