Changeset 961

Show
Ignore:
Timestamp:
27/09/2008 18:31:43 (2 months ago)
Author:
james
Message:

new output plugin arrangement!

Location:
trunk
Files:
9 added
25 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/abstracts/en/abstracts.tcl

    r953 r961  
    32633263        "middle earth" 
    32643264        "the heart of the world" 
    3265         "bree" 
     3265        "behind the fridge" 
     3266        "down the back of the sofa" 
     3267        "up my cavernous arse" 
     3268        "up your cavernous arse" 
     3269        "up %OWNER{%ruser} cavernous arse" 
    32663270} 
    32673271 
     
    32923296        "\[%%\] I love %ruser%|%VAR{wrong_infoline}" 
    32933297        "\[%%\] Just call me %VAR{sillyThings}%|%VAR{wrong_infoline}" 
     3298} 
     3299 
     3300# someone we don't know joins the channel 
     3301bMotion_abstract_register "unknown_joins" { 
     3302        "%VAR{ranjoins}" 
    32943303} 
    32953304 
     
    40684077        "Day %NUMBER{500} %VAR{bb_time}: %ruser is in the diary room, talking to Big Brother about %VAR{bb_diary}" 
    40694078        "Day %NUMBER{500} %VAR{bb_time}: %ruser has hidden %OWNER{%ruser} %VAR{bb_posession} in %VAR{bb_hide}" 
    4070 } 
     4079        "Day %NUMBER{500} %VAR{bb_time}: %ruser has been crying in the %VAR{bb_room} for %NUMBER{100} minutes" 
     4080        "Day %NUMBER{500} %VAR{bb_time}: %ruser had a dream about %VAR{nightmare}. %ruser hides in the %VAR{bb_room}" 
     4081} 
     4082 
     4083bMotion_abstract_register "bb_room" { 
     4084        "diary room" 
     4085        "kitchen" 
     4086        "dining area" 
     4087        "lounge" 
     4088        "garden" 
     4089        "roof" 
     4090} 
     4091 
    40714092bMotion_abstract_register "bb_time" { 
    40724093        "%TIME{now}" 
     
    42414262        "%daytime!%|%VAR{todays_episode}" 
    42424263        "%daytime%|%VAR{todays_episode}" 
     4264        "%VAR{bb_stuff}" 
    42434265} 
    42444266 
     
    43464368} 
    43474369 
     4370bMotion_abstract_register "noun_prefix" { 
     4371        "space" 
     4372        "surprise" 
     4373        "lovely" 
     4374        "minging" 
     4375        "nice" 
     4376        "horrible" 
     4377} 
     4378 
    43484379source "$bMotionModules/abstracts/en/randomstuff.tcl" 
  • trunk/modules/abstracts/en/randomstuff.tcl

    r959 r961  
    66### Used when the channel is not 'active' (default > 300s since last line) 
    77bMotion_abstract_register "randomStuff" { 
     8        "/washes %hisher %VAR{bodypart}" 
    89        "%BOT\[<%me> good news everyone, I'm a horse's butt!\]%|i am? that doesn't sound like good news at all %VAR{unsmiles}" 
    910        "too bad %ruser's not around... i'll have to eat this raw dripping ham by myself" 
     
    454455### Used when the channel is 'active' (default < 300 sec since last line) 
    455456bMotion_abstract_register "activeRandomStuff" { 
     457        "that's nice dear" 
    456458        "very good, give me surprised and pleased" 
    457459        "impossible%|you are already at full cock now" 
  • trunk/modules/events.tcl

    r954 r961  
    348348                        set bMotion_testing 0 
    349349                        if {[matchattr $handle m]} { 
    350                                 putchan $channel [bMotionDoInterpolation "%VAR{rehashes}" "" ""] 
     350                                putchan $channel [bMotion_abstract_get "rehashes"] 
    351351                                rehash 
    352352                                return 0 
  • trunk/modules/output.tcl

    r954 r961  
    163163        } 
    164164 
    165         #do this first now 
     165 
     166        # Run the plugins :D 
     167 
     168        # 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                        } err 
     177                        bMotion_putloglev 3 * "bMotion: returned from output $callback ($result)" 
     178                        # TODO: Still used? 
     179                        if {$result == ""} { 
     180                                return 0 
     181                        } 
     182                        set text $result 
     183                } 
     184        } 
     185 
    166186        set text [bMotionDoInterpolation $text $nick $moreText $channel] 
    167187 
    168         set multiPart 0 
    169         if [string match "*%|*" $text] { 
    170                 set multiPart 1 
    171                 # we have many things to do 
    172                 set thingsToSay "" 
    173                 set loopCount 0 
    174                 set blah 0 
    175  
    176                 #make sure we get the last section 
    177                 set text "$text%|" 
    178  
    179                 while {[string match "*%|*" $text]} { 
    180                         set origtext $text 
    181                         set sentence [string range $text 0 [expr [string first "%|" $text] -1]] 
    182                         if {$sentence != ""} { 
    183                                 if {$blah == 0} { 
    184                                         set thingsToSay [list $sentence] 
    185                                         set blah 1 
    186                                 } else { 
    187                                         lappend thingsToSay $sentence 
     188        # now the rest 
     189        if {$noTypo == 0} { 
     190                set plugins [bMotion_plugin_find_output $bMotionInfo(language) $channel 11] 
     191                if {[llength $plugins] > 0} { 
     192                        foreach callback $plugins { 
     193                                bMotion_putloglev 1 * "bMotion: output plugin: $callback..." 
     194                                set result "" 
     195                                catch { 
     196                                        set result [$callback $channel $text] 
     197                                } err 
     198                                bMotion_putloglev 3 * "bMotion: returned from output $callback ($result)" 
     199                                if {$result == ""} { 
     200                                        return 0 
    188201                                } 
    189                         } 
    190                         set text [string range $text [expr [string first "%|" $text] + 2] end] 
    191                         if {$text == $origtext} { 
    192                                 putlog "bMotion ALERT! Bailed in bMotionDoAction with $text. Lost output." 
    193                                 return 0 
    194                         } 
    195                 } 
    196         } 
    197  
    198         if {$multiPart == 1} { 
    199                 foreach lineIn $thingsToSay { 
    200                         set temp [bMotionSayLine $channel $nick $lineIn $moreText $noTypo $urgent] 
    201                         if {$temp == 1} { 
    202                                 bMotion_putloglev 1 * "bMotion: bMotionSayLine returned 1, skipping rest of output" 
    203                                 #1 stops continuation after a failed %bot[n,] 
    204                                 break 
    205                         } 
    206                         set typosDone [bMotion_plugins_settings_get "output:typos" "typosDone" "" ""] 
    207                         bMotion_putloglev 2 * "bMotion: typosDone (multipart) is !$typosDone!" 
    208                         if {$typosDone != ""} { 
    209                                 bMotion_plugins_settings_set "output:typos" "typosDone" "" "" "" 
    210                                 if [rand 2] { 
    211                                         bMotionDoAction $channel "" "%VAR{typoFix}" "" 1 
    212                                 } 
    213                                 bMotion_plugins_settings_set "output:typos" "typos" "" "" "" 
    214                         } 
    215                 } 
     202                                set text $result 
     203                        } 
     204                } 
     205        } 
     206 
     207        #make sure the line wasn't set to blank by a plugin (may be trying to block output) 
     208        set line [string trim $text] 
     209        if {$line == ""} { 
    216210                return 0 
    217211        } 
    218212 
    219         bMotionSayLine $channel $nick $text $moreText $noTypo $urgent 
    220         set typosDone [bMotion_plugins_settings_get "output:typos" "typosDone" "" ""] 
    221         bMotion_putloglev 2 * "bMotion: typosDone is !$typosDone!" 
    222         if {$typosDone != ""} { 
    223                 bMotion_plugins_settings_set "output:typos" "typosDone" "" "" "" 
    224                 if [rand 2] { 
    225                         bMotionDoAction $channel "" "%VAR{typoFix}" "" 1 
    226                 } 
    227                 bMotion_plugins_settings_set "output:typos" "typos" "" "" "" 
    228         } 
    229  
     213        # Explode line into lines 
     214        # We map %| to NUL and split on that, since [split] can't 
     215        # handle multichar boundaries 
     216        set lines [split [string map [list "%|" \x00] $line] \x00] 
     217 
     218        foreach lineIn $lines { 
     219                set temp [bMotionSayLine $channel $nick $lineIn $moreText $noTypo $urgent] 
     220                if {$temp == 1} { 
     221                        bMotion_putloglev 1 * "bMotion: bMotionSayLine returned 1, skipping rest of output" 
     222                        #1 stops continuation after a failed %bot[n,] 
     223                        break 
     224                } 
     225                #set typosDone [bMotion_plugins_settings_get "output:typos" "typosDone" "" ""] 
     226                #bMotion_putloglev 2 * "bMotion: typosDone is !$typosDone!" 
     227                ## TODO: fix this 
     228                #if {$typosDone != ""} { 
     229                #       bMotion_plugins_settings_set "output:typos" "typosDone" "" "" "" 
     230                #       if [rand 2] { 
     231                #               bMotionDoAction $channel "" "%VAR{typoFix}" "" 1 
     232                #       } 
     233                #       bMotion_plugins_settings_set "output:typos" "typos" "" "" "" 
     234                #} 
     235        } 
    230236        return 0 
    231237} 
     
    238244        global botnick bMotionCache 
    239245 
    240         if [string match "*%noun*" $line] { 
    241                 set line [bMotionInsertString $line "%noun" "%VAR{sillyThings}"] 
    242         } 
    243  
    244         #set loops 0 
    245         bMotion_putloglev 4 * "doing VAR processing" 
    246         set lastloop "" 
    247         while {[regexp -nocase {%VAR\{([^\}]+)\}(\{strip\})?} $line matches BOOM clean]} { 
    248                 global $BOOM 
    249                 #see if we have a new-style abstract available 
    250                 set newText [bMotion_abstract_get $BOOM] 
    251                 set replacement "" 
    252                 if {$newText == ""} { 
    253                         bMotion_putloglev d * "abstract '$BOOM' doesn't exist in new abstracts system!" 
    254                         #insert old style 
    255                         set var [subst $$BOOM] 
    256                         set replacement [pickRandom $var] 
    257                 } else { 
    258                         set replacement $newText 
    259                 } 
    260                 if {$clean != ""} { 
    261                         set replacement [bMotion_strip_article $replacement] 
    262                 } 
    263                 regsub -nocase "%VAR\{$BOOM\}$clean" $line $replacement line 
    264                 if [string match "*%noun*" $line] { 
    265                         set line [bMotionInsertString $line "%noun" "%VAR{sillyThings}"] 
    266                 } 
    267                 if {$lastloop == $line} { 
    268                         putlog "bMotion: ALERT! looping too much in %VAR code with $line (no change since last parse)" 
    269                         set line "/has a tremendous error while trying to sort something out :(" 
    270                         break 
    271                 } 
    272                 set lastloop $line 
    273         } 
    274  
    275         set loops 0 
    276         bMotion_putloglev 4 * "doing SETTING processing" 
    277         while {[regexp "%SETTING\{(.+?)\}" $line matches settingString]} { 
    278                 set var "" 
    279                 if [regexp {([^:]+:[^:]+):([^:]+):([^:]+):([^:]+)} $settingString matches plugin setting ch ni] { 
    280                         set var [bMotion_plugins_settings_get $plugin $setting $ch $ni] 
    281                 } 
    282                 incr loops 
    283                 if {$loops > 10} { 
    284                         putlog "bMotion: ALERT! looping too much in %SETTING code with $line" 
    285                         set line "/has a tremendous error while trying to infer the meaning of life :(" 
    286                 } 
    287                 if {$var == ""} { 
    288                         putlog "bMotion: ALERT! couldn't find setting $settingString (dropping output)" 
    289                         return "" 
    290                 } 
    291                 set line [bMotionInsertString $line "%SETTING{$settingString}" $var] 
    292         } 
    293  
    294         set loops 0 
    295         bMotion_putloglev 4 * "doing NUMBER processing" 
    296         set padding 0 
    297         while {[regexp "%NUMBER\{(\[0-9\]+)\}(\{(\[0-9\]+)\})?" $line matches numberString paddingOpt padding]} { 
    298                 set var [bMotion_get_number [bMotion_rand_nonzero $numberString]] 
    299                 if {$padding > 0} { 
    300                         set fmt "%0$padding" 
    301                         append fmt "u" 
    302                         set var [format $fmt $var] 
    303                 } 
    304                 incr loops 
    305                 if {$loops > 10} { 
    306                         putlog "bMotion: ALERT! looping too much in %NUMBER code with $line" 
    307                         set line "/has a tremendous error while trying to think of a number :(" 
    308                 } 
    309                 set line [bMotionInsertString $line "%NUMBER\\{$numberString\\}(\\{\[0-9\]+\\})?" $var] 
    310                 set padding 0 
    311         } 
    312  
    313         set loops 0 
    314         bMotion_putloglev 4 * "doing TIME processing" 
    315         while {[regexp "%TIME\{(\[a-zA-Z0-9 -\]+)\}" $line matches timeString]} { 
    316                 bMotion_putloglev 2 * "found timestring $timeString" 
    317                 set origtime $timeString 
    318                 regsub -nocase {^-([0-9]) minutes?$} $timeString "\\1 minutes ago" timeString 
    319                 set var [clock scan $timeString] 
    320                 set var [clock format $var -format "%I:%M %p"] 
    321                 bMotion_putloglev 2 * "using time $var" 
    322                 incr loops 
    323                 if {$loops > 10} { 
    324                         putlog "bMotion: ALERT! looping too much in %TIME code with %line" 
    325                         set line "/has a tremendous error while trying to do complex time mathematics :(" 
    326                 } 
    327                 set line [bMotionInsertString $line "%TIME\\{$origtime\\}" $var] 
    328         } 
    329  
    330246        bMotion_putloglev 4 * "doing misc interpolation processing for $line" 
    331247        set line [bMotionInsertString $line "%%" $nick] 
    332         set line [bMotionInsertString $line "%pronoun" [getPronoun]] 
    333         set line [bMotionInsertString $line "%himherself" [getPronoun]] 
    334         set line [bMotionInsertString $line "%me" $botnick] 
    335         set line [bMotionInsertString $line "%colen" [bMotionGetColenChars]] 
    336         set line [bMotionInsertString $line "%hishers" [getHisHers]] 
    337         set line [bMotionInsertString $line "%heshe" [getHeShe]] 
    338         set line [bMotionInsertString $line "%hisher" [getHisHer]] 
    339248        set line [bMotionInsertString $line "%2" $moreText] 
    340249        set line [bMotionInsertString $line "%percent" "%"] 
    341         set line [bMotionInsertString $line "%daytime" [bMotion_get_daytime]] 
    342  
    343250 
    344251        bMotion_putloglev 4 * "done misc" 
     
    387294proc bMotionInterpolation2 { line } { 
    388295        bMotion_putloglev 5 * "bMotionInterpolation2 ($line)" 
    389         #owners 
    390         set loops 0 
    391  
    392         while {[regexp -nocase "%OWNER\{(.*?)\}" $line matches BOOM]} { 
    393                 set BOOM [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\} $ \\\$ \" \\\" | \\\|} $BOOM] 
    394  
    395                 incr loops 
    396                 if {$loops > 10} { 
    397                         putlog "bMotion: ALERT! looping too much in %OWNER code with $line" 
    398                         set line "/has a tremendous error while trying to sort something out :(" 
    399                 } 
    400                 # set line [bMotionInsertString $line "%OWNER\{$BOOM\}" [bMotionMakePossessive $BOOM]] 
    401                 regsub -nocase "%OWNER\{$BOOM\}" $line [bMotionMakePossessive $BOOM] line 
    402                 regsub -all "\\\\" $line "" line 
    403         } 
    404  
    405         set loops 0 
    406         while {[regexp -nocase "%VERB\{(.*?)\}" $line matches BOOM]} { 
    407                 incr loops 
    408                 if {$loops > 10} { 
    409                         putlog "bMotion: ALERT! looping too much in %VERB code with $line" 
    410                         set line "/has a tremendous error while trying to sort something out :(" 
    411                 } 
    412                 # set line [bMotionInsertString $line "%VERB\{$BOOM\}" [bMotionMakeVerb $BOOM]] 
    413                 regsub -nocase "%VERB\{$BOOM\}" $line [bMotionMakeVerb $BOOM] line 
    414         } 
    415  
    416         set loops 0 
    417         while {[regexp -nocase "%PLURAL\{(.*?)\}" $line matches BOOM]} { 
    418                 incr loops 
    419                 if {$loops > 10} { 
    420                         putlog "bMotion: ALERT! looping too much in %PLURAL code with $line" 
    421                         set line "/has a tremendous error while trying to sort something out :(" 
    422                 } 
    423                 # set line [bMotionInsertString $line "%PLURAL\{$BOOM\}" [bMotionMakePlural $BOOM]] 
    424                 regsub -nocase "%PLURAL\{$BOOM\}" $line [bMotionMakePlural $BOOM] line 
    425         } 
    426  
    427         set loops 0 
    428         while {[regexp -nocase "%REPEAT\{(.+?)\}" $line matches BOOM]} { 
    429                 incr loops 
    430                 if {$loops > 10} { 
    431                         putlog "bMotion: ALERT! looping too much in %REPEAT code with $line" 
    432                         set line "/has a tremendous error while trying to sort something out :(" 
    433                 } 
    434                 set replacement [bMotionMakeRepeat $BOOM] 
    435                 regsub -nocase "%REPEAT\\{$BOOM\\}" $line $replacement line 
    436         } 
    437296 
    438297        return $line 
     
    446305        global mood botnick bMotionInfo bMotionCache bMotionOriginalInput 
    447306        global bMotion_output_delay 
    448  
    449         set line [bMotionInterpolation2 $line] 
    450307 
    451308        #TODO: Put %ruser and %rbot back in here 
     
    470327                } else { 
    471328                #non-random 
    472                 regexp {%BOT\[(@[^,]+,)?(.+)\]} $line matches condition cmd 
     329                        regexp {%BOT\[(@[^,]+,)?(.+)\]} $line matches condition cmd 
    473330                } 
    474331 
     
    514371                        } 
    515372                } 
    516         } 
    517  
    518         # Run the plugins :D 
    519  
    520         if {$noTypo == 0} { 
    521                 set plugins [bMotion_plugin_find_output $bMotionInfo(language) $channel] 
    522                 if {[llength $plugins] > 0} { 
    523                         foreach callback $plugins { 
    524                                 bMotion_putloglev 1 * "bMotion: output plugin: $callback..." 
    525                                 set result "" 
    526                                 catch { 
    527                                         set result [$callback $channel $line] 
    528                                 } err 
    529                                 bMotion_putloglev 3 * "bMotion: returned from output $callback ($result)" 
    530                                 if [regexp "1Š(.+)" $result matches line] { 
    531                                         break 
    532                                 } 
    533                                 if {$result == ""} { 
    534                                         return 0 
    535                                 } 
    536                                 set line $result 
    537                         } 
    538                 } 
    539         } 
    540  
    541         #make sure the line wasn't set to blank by a plugin (may be trying to block output) 
    542         if {($line == "") || [regexp "^ +$" $line]} { 
    543                 return 0 
    544373        } 
    545374 
  • trunk/modules/plugins.tcl

    r958 r961  
    258258# 
    259259# Load an output plugin 
    260 proc bMotion_plugin_add_output { id callback enabled language { priority 2 } } { 
     260proc bMotion_plugin_add_output { id callback enabled language { priority 11 } } { 
    261261        global bMotion_plugins_output plugins bMotion_testing bMotion_noplugins 
    262262 
     
    283283# Sorted by priority then name 
    284284# Includes plugins only enabled for the given channel 
    285 proc bMotion_plugin_find_output { lang { channel "" } } { 
     285proc bMotion_plugin_find_output { lang { channel "" } { min_priority 0} { max_priority 100 } } { 
    286286        global bMotion_plugins_output botnicks 
    287287        global bMotion_plugins_output_perchan 
     
    295295                set language [lindex $val $BMOTION_PLUGIN_OUTPUT_LANGUAGE] 
    296296                set priority [lindex $val $BMOTION_PLUGIN_OUTPUT_PRIORITY] 
    297                 if {[string match $lang $language] || ($language == "any")|| ($language == "all")} { 
    298                         if {$enabled == 1} { 
    299                                 lappend result [list $callback $priority] 
    300                         } else { 
    301                                 bMotion_putloglev 1 * "Searching $key for channel $channel" 
    302                                 if {$channel != ""} { 
    303                                         catch { 
    304                                                 set chanlist $bMotion_plugins_output_perchan($key) 
    305                                                 if {[lsearch $chanlist $channel] > -1} { 
    306                                                         lappend result [list $callback $priority] 
    307                                                         bMotion_putloglev d * "Plugin $key is enabled for $channel" 
     297                if {($priority >= $min_priority) && ($priority <= $max_priority)} { 
     298                        if {[string match $lang $language] || ($language == "any")|| ($language == "all")} { 
     299                                if {$enabled == 1} { 
     300                                        lappend result [list $callback $priority] 
     301                                } else { 
     302                                        bMotion_putloglev 1 * "Searching $key for channel $channel" 
     303                                        if {$channel != ""} { 
     304                                                catch { 
     305                                                        set chanlist $bMotion_plugins_output_perchan($key) 
     306                                                        if {[lsearch $chanlist $channel] > -1} { 
     307                                                                lappend result [list $callback $priority] 
     308                                                                bMotion_putloglev d * "Plugin $key is enabled for $channel" 
     309                                                        } 
    308310                                                } 
    309311                                        } 
  • trunk/modules/system.tcl

    r958 r961  
    239239                        if [bMotion_is_active_enough $channel $active_idle_sec] { 
    240240                        #channel is fairly busy 
    241                         if [bMotionSaySomethingRandom $channel 1] { 
    242                         lappend saidChannels "$channel/active" 
    243                         } else { 
    244                         lappend silentChannels $channel 
    245                         } 
     241                                if [bMotionSaySomethingRandom $channel 1] { 
     242                                        lappend saidChannels "$channel/active" 
     243                                } else { 
     244                                        lappend silentChannels $channel 
     245                                } 
    246246                        } else { 
    247247                        #use a more idle randomstuff 
    248                         if [bMotionSaySomethingRandom $channel 0] { 
    249                         lappend saidChannels $channel 
    250                         } else { 
    251                         lappend silentChannels $channel 
    252                         } 
     248                                if [bMotionSaySomethingRandom $channel 0] { 
     249                                        lappend saidChannels $channel 
     250                                } else { 
     251                                        lappend silentChannels $channel 
     252                                } 
    253253                        } 
    254254                } else { 
  • trunk/plugins/admin_plugin.tcl

    r958 r961  
    5454        if [regexp -nocase {disable ([^ ]+) (.+?)( .+)?} $arg matches t id channel] { 
    5555                if {$t == "output"} { 
    56                         bMotion_putadmin "Disabling output plugin $id..." 
    5756                        if {$channel != ""} { 
    5857                                set channel [string trim $channel] 
  • trunk/plugins/en/action_complex_failsafe.tcl