Changeset 929

Show
Ignore:
Timestamp:
30/06/2008 15:35:13 (3 months ago)
Author:
james
Message:

tidy up

Location:
trunk/modules
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/output.tcl

    r926 r929  
    11#bMotion - Output functions 
    2 # 
    3 # $Id$ 
    42# 
    53# vim: fdm=indent fdn=1 
     
    2422############################################################################### 
    2523 
    26 # init our counters 
    27 bMotion_counter_init "output" "lines" 
    28 bMotion_counter_init "output" "irclines" 
    29  
    3024set bMotion_output_delay 0 
    3125 
     26# 
     27# pick a random element from a list 
    3228proc pickRandom { list } { 
    3329        bMotion_putloglev 5 * "pickRandom ($list)" 
     
    3531} 
    3632 
     33# 
     34# get the pronoun for our gender 
    3735proc getPronoun {} { 
    3836        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 
    4554proc getHisHers {} { 
    4655        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 
    5374proc getHisHer {} { 
    5475        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 
    6294proc getHeShe {} { 
    6395        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 
    71114proc mee {channel action {urgent 0} } { 
    72115        bMotion_putloglev 5 * "mee ($channel, $action, $urgent)" 
     
    79122} 
    80123 
    81  
    82 ## bMotionDoAction ########################################################### 
     124# 
     125# our magic output function 
    83126proc bMotionDoAction {channel nick text {moreText ""} {noTypo 0} {urgent 0} } { 
    84127        bMotion_putloglev 5 * "bMotionDoAction($channel,$nick,$text,$moreText,$noTypo)" 
     
    97140 
    98141        # check if we're asleep 
    99         if {$bMotionSettings(asleep) == $BMOTION_SLEEP(ASLEEP)} { 
    100         return 0 
     142        if {[bMotion_setting_get "asleep"] == $BMOTION_SLEEP(ASLEEP)} { 
     143                return 0 
    101144        } 
    102145 
     
    109152        } 
    110153 
    111         if {$bMotionInfo(silence) == 1} { return 0 } 
     154        if {[bMotion_setting_get "silence"] == 1} { return 0 } 
    112155        catch { 
    113156                if {$bMotionInfo(adminSilence,$channel) == 1} { return 0 } 
    114157        } 
    115158 
    116         bMotion_counter_incr "output" "lines" 
    117  
     159        # TODO: ugly, refactor? 
    118160        switch [rand 3] { 
    119161                0 { } 
     
    172214                        } 
    173215                        bMotion_plugins_settings_set "output:typos" "typos" "" "" "" 
    174  
    175  
    176216                } 
    177217                return 0 
     
    192232} 
    193233 
     234 
     235#  
     236# replace things on lines 
    194237proc bMotionDoInterpolation { line nick moreText { channel "" } } { 
    195238        bMotion_putloglev 5 * "bMotionDoInterpolation: line = $line, nick = $nick, moreText = $moreText, channel = $channel" 
     
    340383} 
    341384 
     385# 
     386# more replacements in a line 
     387# TODO: why was this separate? 
    342388proc bMotionInterpolation2 { line } { 
    343389        bMotion_putloglev 5 * "bMotionInterpolation2 ($line)" 
     
    348394                set BOOM [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\} $ \\\$ \" \\\" | \\\|} $BOOM] 
    349395 
    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 :) 
    396445proc bMotionSayLine {channel nick line {moreText ""} {noTypo 0} {urgent 0} } { 
    397446        bMotion_putloglev 5 * "bMotionSayLine: channel = $channel, nick = $nick, line = $line, moreText = $moreText, noTypo = $noTypo" 
     
    402451 
    403452        #TODO: Put %ruser and %rbot back in here 
     453        # XXX: is the above TODO still valid? 
    404454 
    405455        #if it's a bot , put it on the queue on the remote bot 
     
    408458                set dobreak 0 
    409459                if {$botcmd == "bot"} { 
    410                         #random 
     460                #random 
    411461                        bMotion_putloglev 1 * "bMotion: %bot detected" 
    412462                        regexp {%bot\[([[:digit:]]+),(@[^,]+,)?(.+)\]} $line matches chance condition cmd 
     
    420470                        } 
    421471                } else { 
    422                         #non-random 
    423                         regexp {%BOT\[(@[^,]+,)?(.+)\]} $line matches condition cmd 
     472                #non-random 
     473                regexp {%BOT\[(@[^,]+,)?(.+)\]} $line matches condition cmd 
    424474                } 
    425475 
     
    509559        #we try an admin plugin 
    510560        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        } 
    513581        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 
    534586proc bMotionInsertString {line swapout toInsert} { 
    535587        bMotion_putloglev 5 * "bMotionInsertString ($line, $swapout, $toInsert)" 
     
    548600} 
    549601 
     602# 
     603# Get random chars as would be made by shift-numberkeys 
    550604proc bMotionGetColenChars {} { 
    551605        bMotion_putloglev 5 * "bMotionGetColenChars" 
     
    569623} 
    570624 
     625# 
     626# make a smiley representing our mood 
     627# TOOD: still used? 
    571628proc makeSmiley { mood } { 
    572629        bMotion_putloglev 5 * "makeSmiley" 
     
    589646} 
    590647 
    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 
    594650proc bMotionWashNick { nick } { 
    595651        bMotion_putloglev 5 * "bMotionWashNick ($nick)" 
     
    603659} 
    604660 
     661# 
     662# replace a nick with one of someone's IRL names 
     663# TODO: no longer used? if not, delete 
    605664proc OLDbMotionGetRealName { nick { host "" }} { 
    606665        bMotion_putloglev 5 * "bMotion: OLDbMotionGetRealName($nick,$host)" 
     
    641700} 
    642701 
     702# 
     703# replace a nick with one of someone's IRL names 
    643704proc bMotionGetRealName { nick { host "" }} { 
    644705        bMotion_putloglev 5 * "bMotion: bMotionGetRealName($nick,$host)" 
     
    679740} 
    680741 
     742# 
     743# 
    681744proc bMotionTransformNick { target nick {host ""} } { 
    682745        bMotion_putloglev 5 * "bMotionTransformNick($target, $nick, $host)" 
     
    688751} 
    689752 
     753# 
     754# 
    690755proc bMotionTransformTarget { target {host ""} } { 
    691756        bMotion_putloglev 5 * "bMotionTransformTarget($target, $host)" 
     
    863928} 
    864929 
     930# 
     931# turn a name into the posessive form 
    865932proc bMotionMakePossessive { text { altMode 0 }} { 
    866933        bMotion_putloglev 5 * "bMotionMakePossessive ($text, $altMode)" 
     
    889956} 
    890957 
     958# 
     959# Function which powers %REPEAT 
    891960proc bMotionMakeRepeat { text } { 
    892961        bMotion_putloglev 5 * "bMotionMakeRepeat ($text)" 
     
    906975} 
    907976 
     977# 
     978# remove preceeding fluff from a noun 
    908979proc bMotion_strip_article { text } { 
    909980        bMotion_putloglev 5 * "bMotion_strip_article ($text)" 
     
    912983} 
    913984 
     985# 
     986# verbs a noun (like that) 
    914987proc bMotionMakeVerb { text } { 
    915988        bMotion_putloglev 5 * "bMotionMakeVerb ($text)" 
     
    9271000        return $text 
    9281001} 
     1002 
     1003# 
     1004# not sure! 
    9291005proc chr c { 
    9301006        if {[string length $c] > 1 } { error "chr: arg should be a single char"} 
     
    9351011} 
    9361012 
    937  
     1013# 
     1014# pluralise a noun by the simple rules of English 
    9381015proc bMotionMakePlural { text } { 
    9391016        bMotion_putloglev 5 * "bMotionMakePlural ($text)" 
  • trunk/modules/system.tcl

    r908 r929  
    2323 
    2424 
    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  
    3229bind join - *!*@* bMotion_event_onjoin 
    3330bind mode - * bMotion_event_mode 
     
    3835bind ctcp - ACTION bMotion_event_action 
    3936 
    40 #bMotion IRC events <<<2 
     37#bMotion IRC events  
    4138bind pub - "!mood" pubm_moodhandler 
    4239bind pub - "!bminfo" bMotionInfo 
     
    4744bind pub - .bmotion bMotionAdminHandler2 
    4845 
    49 #DCC commands <<<2 
     46#DCC commands  
    5047bind dcc m mood moodhandler 
    5148bind dcc m bmotion* bMotion_dcc_command 
     
    5653bind time - "* * * * *" bMotion_check_tired2 
    5754 
    58 ### bMotion_update_chanlist <<<1 
     55# 
    5956# rebuilds our channel list based on which channels are +bmotion 
    6057proc bMotion_update_chanlist { } { 
     
    6865        } 
    6966} 
    70 ### Initalise some variables per channel <<<1 
     67 
     68# 
     69# Initalise some variables per channel  
    7170bMotion_update_chanlist 
     71 
    7272foreach chan $bMotionChannels { 
    7373        set bMotionLastEvent($chan) [clock seconds] 
     
    7676        #used to make the bot a bit more intelligent (perhaps) at conversations 
    7777        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 
    8382proc bMotionStats {nick host handle channel text} { 
    8483        global bMotionInfo botnicks bMotionSettings cvsinfo botnick 
     
    113112 
    114113 
    115  
     114# 
    116115# check if a channel is active enough for randomy things 
    117116proc bMotion_is_active_enough { channel { limit 0 } } { 
     
    143142} 
    144143 
     144# 
    145145# check if every channel we can see is idle enough for us to go away 
    146146proc bMotion_random_away {} { 
     
    193193} 
    194194 
     195# 
    195196# periodically sprout randomness (or go /away if idle enough) 
    196197proc doRandomStuff {} { 
     
    265266} 
    266267 
    267 ### bMotionSaySomethingRandom <<<1 
     268# 
     269# Output random gibberish 
    268270proc bMotionSaySomethingRandom {channel {busy 0}} { 
    269271        global randomStuff stonedRandomStuff mood bMotionInfo bMotionCache 
     
    303305 
    304306 
    305 ### bMotionSetRandomAway <<<1 
     307# 
     308#set myself away with a random message 
    306309proc bMotionSetRandomAway {} { 
    307         #set myself away with a random message 
    308310        global randomAways bMotionInfo bMotionSettings bMotionChannels 
    309311 
     
    321323} 
    322324 
    323 ### bMotionSetRandomBack <<<1 
     325# 
     326# set myself back 
    324327proc bMotionSetRandomBack {} { 
    325328        #set myself back 
     
    343346} 
    344347 
    345 ### bMotionTalkingToMe <<<1 
     348# 
     349# check if a line looks like it's addressed to me 
    346350proc bMotionTalkingToMe { text } { 
    347351        global botnicks 
     
    367371} 
    368372 
    369 ### bMotionSilence <<<1 
    370 # Makes the bot shut up 
     373# 
     374# We need to shut up 
    371375proc bMotionSilence {nick host channel} { 
    372376        global bMotionInfo silenceAways bMotionSettings 
     
    384388} 
    385389 
    386 ### bMotionUnSilence <<<1 
    387 # Undoes the shut up command 
     390# 
     391# Enough shutting up for now 
    388392proc bMotionUnSilence {} { 
    389393        # Timer for silence expires 
     
    395399} 
    396400 
    397 ### bMotionLike <<<1 
     401### bMotionLike  
    398402proc bMotionLike {nick { host "" }} { 
    399403        global bMotionInfo mood bMotionSettings 
     
    463467} 
    464468 
    465 ### bMotionGetGender <<<1 
     469### bMotionGetGender  
    466470proc bMotionGetGender { nick host } { 
    467471        set host "$nick!$host" 
     
    474478} 
    475479 
    476 ### getHour <<<1 
     480### getHour  
    477481proc getHour {} { 
    478482        return [clock format [clock seconds] -format "%H"] 
     
    480484 
    481485 
    482 ### bMotion_dcc_command <<<1 
     486### bMotion_dcc_command  
    483487proc bMotion_dcc_command { handle idx arg } { 
    484488        global bMotionInfo 
     
    564568} 
    565569 
    566 ### bMotion_dcc_help <<<1 
     570### bMotion_dcc_help  
    567571proc bMotion_dcc_help { handle idx arg } { 
    568572        putidx $idx "Please use .bmotion help" 
     
    572576 
    573577### new admin plugins ("management") 
    574 ### bMotionAdminHandler2 <<<1 
     578### bMotionAdminHandler2  
    575579proc bMotionAdminHandler2 {nick host handle channel text} { 
    576580        global botnicks bMotionInfo botnick bMotionSettings 
     
    631635 
    632636 
    633 ### bMotion_putadmin <<<1 
     637### bMotion_putadmin  
    634638proc bMotion_putadmin { text } { 
    635639 
     
    656660} 
    657661 
    658 ### bMotionAdminHandler <<<1 
     662### bMotionAdminHandler  
    659663#TODO: is this ever used now? 
    660664proc bMotionAdminHandler {nick host handle channel text} {