Ignore:
Timestamp:
08/23/09 19:22:05 (3 years ago)
Author:
james
Message:

New output parser for core plugins - should fix problems with late replacements getting missed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/output.tcl

    r1017 r1019  
    124124# our magic output function 
    125125proc bMotionDoAction {channel nick text {moreText ""} {noTypo 0} {urgent 0} } { 
    126         bMotion_putloglev 5 * "bMotionDoAction($channel,$nick,$text,$moreText,$noTypo)" 
     126        bMotion_putloglev 5 * "bMotionDoAction($channel,$nick,$text,$moreText,$noTypo,$urgent)" 
    127127        global bMotionInfo bMotionCache bMotionOriginalInput 
    128128        global bMotion_output_delay bMotionSettings BMOTION_SLEEP 
    129129 
    130130        set bMotion_output_delay 0 
    131  
    132         set bMotionCache($channel,last) 1 
    133131 
    134132        #check our global toggle 
     
    137135                return 0 
    138136        } 
     137 
     138        set bMotionCache($channel,last) 1 
    139139 
    140140        # check if we're asleep 
     
    151151        } 
    152152 
    153         if {[bMotion_setting_get "silence"] == 1} { return 0 } 
     153        if {[bMotion_setting_get "silence"] == 1} {  
     154                return 0  
     155        } 
    154156        catch { 
    155                 if {$bMotionInfo(adminSilence,$channel) == 1} { return 0 } 
    156         } 
    157  
    158         # TODO: ugly, refactor? 
     157                if {$bMotionInfo(adminSilence,$channel) == 1} {  
     158                        return 0  
     159                } 
     160        } 
     161 
    159162        switch [rand 3] { 
    160163                0 { } 
     
    163166        } 
    164167 
     168        # Process macros 
     169 
     170        set done 0 
     171        set current_pos 0 
     172        while {$done == 0} { 
     173                bMotion_putloglev d * "macro: starting loop with $text and current pos=$current_pos" 
     174                set current_pos [string first "%" $text $current_pos] 
     175                if {$current_pos == -1} { 
     176                        # no more matches 
     177                        set done 1 
     178                        continue 
     179                }  
     180                bMotion_putloglev d * "macro: found a % at $current_pos" 
     181                if {$current_pos < [string length $text]} { 
     182                        # this isn't a % at the end of the line 
     183                        if {[string index $text [expr $current_pos + 1]] == "|"} { 
     184                                set current_pos [expr $current_pos + 2] 
     185                                continue 
     186                        } 
     187 
     188                        #find the element following this % 
     189                        set substring [string range $text $current_pos end] 
     190                        if [regexp -nocase {%([a-z]+)} $text matches macro] { 
     191                                bMotion_putloglev d * "macro: found macro $macro at $current_pos" 
     192                                set plugin [bMotion_plugin_find_output "en" "" 0 10 $macro] 
     193                                if {[llength $plugin] == 1} { 
     194                                        # call plugin 
     195                                        bMotion_putloglev d * "macro: found matching plugin for macro [lindex $plugin 0]" 
     196                                        set result "" 
     197                                        catch { 
     198                                                set result [[lindex $plugin 0] $channel $text] 
     199                                                if {$result == ""} { 
     200                                                        bMotion_putloglev d * "macro: [lindex $plugin 0] returned nothing, aborting output" 
     201                                                        return 0 
     202                                                } 
     203                                        } 
     204                                        if {$result == ""} { 
     205                                                continue 
     206                                        } 
     207 
     208                                        if {$text != $result} { 
     209                                                set text $result 
     210                                                # reset current pos 
     211                                                set current_pos 0 
     212                                                continue 
     213                                        } else { 
     214                                                bMotion_putloglev d * "macro: [lindex $plugin 0] did nothing at position $current_pos in output $text" 
     215                                        } 
     216                                } else { 
     217                                        bMotion_putloglev d * "macro: unexpectly got too many matching plugins back: $plugin" 
     218                                } 
     219 
     220                                incr current_pos 
     221                                continue 
     222                        } else { 
     223                                bMotion_putloglev d * "macro: couldn't find a macro in $substring" 
     224                                # skip it 
     225                                incr current_pos 
     226                                continue 
     227                        } 
     228                } 
     229 
     230                # hmm 
     231                bMotion_putloglev d * "macro: got to end of macro loop o_O" 
     232                incr current_pos 
     233        } 
    165234 
    166235        # Run the plugins :D 
    167236 
    168237        # 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         } 
     238        #set plugins [bMotion_plugin_find_output $bMotionInfo(language) $channel 0 10] 
     239        #if {[llength $plugins] > 0} { 
     240        #       foreach callback $plugins { 
     241        #               bMotion_putloglev 1 * "bMotion: output plugin: $callback..." 
     242        #               set result "" 
     243        #               catch { 
     244        #                       set result [$callback $channel $text] 
     245        #               } err 
     246        #               bMotion_putloglev 3 * "bMotion: returned from output $callback ($result)" 
     247        #               # TODO: Still used? 
     248        #               if {$result == ""} { 
     249        #                       return 0 
     250        #               } 
     251        #               set text $result 
     252        #       } 
     253        #} 
    185254 
    186255        set text [bMotionDoInterpolation $text $nick $moreText $channel] 
     
    248317        set line [bMotionInsertString $line "%2" $moreText] 
    249318        set line [bMotionInsertString $line "%percent" "%"] 
    250  
    251         bMotion_putloglev 4 * "done misc" 
    252  
    253         #ruser: 
    254         set loops 0 
    255         while {[regexp "%ruser(\{(\[^\}\]+)\})?" $line matches param condition]} { 
    256                 set ruser [bMotionGetRealName [bMotion_choose_random_user $channel 0 $condition] ""] 
    257                 if {$condition == ""} { 
    258                         set findString "%ruser" 
    259                 } else { 
    260                         set findString "%ruser$param" 
    261                 } 
    262                 regsub $findString $line $ruser line 
    263                 incr loops 
    264                 if {$loops > 10} { 
    265                         putlog "bMotion: ALERT! looping too much in %ruser code with $line" 
    266                         return "" 
    267                 } 
    268         } 
    269  
    270         #rbot: 
    271         set loops 0 
    272         while {[regexp "%rbot(\{(\[^\}\]+)\})?" $line matches param condition]} { 
    273                 set ruser [bMotionGetRealName [bMotion_choose_random_user $channel 1 $condition] ""] 
    274                 if {$condition == ""} { 
    275                         set findString "%rbot" 
    276                 } else { 
    277                         set findString "%rbot$param" 
    278                 } 
    279                 regsub $findString $line $ruser line 
    280                 incr loops 
    281                 if {$loops > 10} { 
    282                         putlog "bMotion: ALERT! looping too much in %rbot code with $line" 
    283                         return "" 
    284                 } 
    285         } 
    286319 
    287320        bMotion_putloglev 4 * "bMotionDoInterpolation returning: $line" 
Note: See TracChangeset for help on using the changeset viewer.