Changeset 1019


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

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

Location:
trunk
Files:
2 added
10 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" 
  • trunk/modules/plugins.tcl

    r1004 r1019  
    284284# Sorted by priority then name 
    285285# Includes plugins only enabled for the given channel 
    286 proc bMotion_plugin_find_output { lang { channel "" } { min_priority 0} { max_priority 100 } } { 
     286proc bMotion_plugin_find_output { lang { channel "" } { min_priority 0} { max_priority 100 } {name "" } } { 
    287287        global bMotion_plugins_output botnicks 
    288288        global bMotion_plugins_output_perchan 
     
    296296                set language [lindex $val $BMOTION_PLUGIN_OUTPUT_LANGUAGE] 
    297297                set priority [lindex $val $BMOTION_PLUGIN_OUTPUT_PRIORITY] 
    298                 if {($priority >= $min_priority) && ($priority <= $max_priority)} { 
    299                         if {[string match $lang $language] || ($language == "any")|| ($language == "all")} { 
    300                                 if {$enabled == 1} { 
    301                                         lappend result [list $callback $priority] 
    302                                 } else { 
    303                                         bMotion_putloglev 1 * "Searching $key for channel $channel" 
    304                                         if {$channel != ""} { 
    305                                                 catch { 
    306                                                         set chanlist $bMotion_plugins_output_perchan($key) 
    307                                                         if {[lsearch $chanlist $channel] > -1} { 
    308                                                                 lappend result [list $callback $priority] 
    309                                                                 bMotion_putloglev d * "Plugin $key is enabled for $channel" 
    310                                                         } 
    311                                                 } 
     298 
     299                if {($name != "") && ($name != $key)} { 
     300                        bMotion_putloglev 3 * "macro: ignoring $key on name" 
     301                        continue 
     302                } 
     303 
     304                if {!(($priority >= $min_priority) && ($priority <= $max_priority))} { 
     305                        bMotion_putloglev 3 * "macro: ignoring $key on priority" 
     306                        continue 
     307                } 
     308 
     309                if {!([string match $lang $language] && ($language != "any") && ($language != "all"))} { 
     310                        bMotion_putloglev 3 * "macro: ignoring $key on language" 
     311                        bMotion_putloglev 3 * "macro: plugin is $lang, want $language" 
     312                        continue 
     313                } 
     314 
     315                if {$enabled == 1} { 
     316                        lappend result [list $callback $priority] 
     317                } else { 
     318                        bMotion_putloglev 1 * "Searching $key for channel $channel" 
     319                        if {$channel != ""} { 
     320                                catch { 
     321                                        set chanlist $bMotion_plugins_output_perchan($key) 
     322                                        if {[lsearch $chanlist $channel] > -1} { 
     323                                                lappend result [list $callback $priority] 
     324                                                bMotion_putloglev d * "Plugin $key is enabled for $channel" 
    312325                                        } 
    313326                                } 
  • trunk/plugins/en/output_NUMBER.tcl

    r961 r1019  
    1 # 
    2 # 
    31# vim: fdm=indent fdn=1 
    42# 
     
    64############################################################################### 
    75# This is a bMotion plugin 
    8 # Copyright (C) James Michael Seward 2000-2008 
     6# Copyright (C) James Michael Seward 2000-2009 
    97# 
    108# This program is covered by the GPL, please refer the to LICENCE file in the 
     
    2119        bMotion_putloglev 4 * "bMotion_plugin_output_NUMBER $channel $line" 
    2220 
    23         set lastline "" 
    24  
    2521        set padding 0 
    26         while {[regexp "%NUMBER\{(\[0-9\]+)\}(\{(\[0-9\]+)\})?" $line matches numberString paddingOpt padding]} { 
     22        if {[regexp "%NUMBER\{(\[0-9\]+)\}(\{(\[0-9\]+)\})?" $line matches numberString paddingOpt padding]} { 
    2723                set var [bMotion_get_number [bMotion_rand_nonzero $numberString]] 
    2824                if {$padding > 0} { 
     
    3329                set line [bMotionInsertString $line "%NUMBER\\{$numberString\\}(\\{\[0-9\]+\\})?" $var] 
    3430                set padding 0 
    35  
    36                 if {$lastline == $line} { 
    37                         putlog "bMotion: ALERT! unable to process %NUMBER in $line (dropping output)" 
    38                         set line "" 
    39                         break 
    40                 } 
    41                 set lastline $line 
    4231        } 
    4332 
  • trunk/plugins/en/output_OWNER.tcl

    r961 r1019  
    1 # 
    2 # 
    31# vim: fdm=indent fdn=1 
    42# 
     
    64############################################################################### 
    75# This is a bMotion plugin 
    8 # Copyright (C) James Michael Seward 2000-2008 
     6# Copyright (C) James Michael Seward 2000-2009 
    97# 
    108# This program is covered by the GPL, please refer the to LICENCE file in the 
     
    1816proc bMotion_plugin_output_OWNER { channel line } { 
    1917 
    20         set previous_line "" 
    21  
    22         while {[regexp -nocase "%OWNER\{(.*?)\}" $line matches BOOM]} { 
     18        if {[regexp -nocase "%OWNER\{(.*?)\}" $line matches BOOM]} { 
    2319                set BOOM [string map {\\ \\\\ [ \\\[ ] \\\] \{ \\\{ \} \\\} $ \\\$ \" \\\" | \\\|} $BOOM] 
    2420 
     
    2622                regsub -nocase "%OWNER\{$BOOM\}" $line [bMotionMakePossessive $BOOM] line 
    2723                regsub -all "\\\\" $line "" line 
    28                 if {$line == $previous_line} { 
    29                         putlog "bMotion: ALERT! looping too much in %OWNER code with $line (no change since last parse)" 
    30                         set line "" 
    31                         break 
    32                 } 
    33                 set previous_line $line 
    3424        } 
    3525        return $line 
  • trunk/plugins/en/output_PLURAL.tcl

    r961 r1019  
    1 # 
    2 # 
    31# vim: fdm=indent fdn=1 
    42# 
     
    64############################################################################### 
    75# This is a bMotion plugin 
    8 # Copyright (C) James Michael Seward 2000-2008 
     6# Copyright (C) James Michael Seward 2000-2009 
    97# 
    108# This program is covered by the GPL, please refer the to LICENCE file in the 
     
    1816proc bMotion_plugin_output_PLURAL { channel line } { 
    1917 
    20         set previous_line "" 
    21         while {[regexp -nocase "%PLURAL\{(.*?)\}" $line matches BOOM]} { 
     18        if {[regexp -nocase "%PLURAL\{(.*?)\}" $line matches BOOM]} { 
    2219                # set line [bMotionInsertString $line "%PLURAL\{$BOOM\}" [bMotionMakePlural $BOOM]] 
    2320                regsub -nocase "%PLURAL\{$BOOM\}" $line [bMotionMakePlural $BOOM] line 
    24                 if {$line == $previous_line} { 
    25                         putlog "bMotion: ALERT! looping too much in %PLURAL code with $line (no change since last parse)" 
    26                         set line "" 
    27                         break 
    28                 } 
    29                 set previous_line $line 
    3021        } 
    3122        return $line 
  • trunk/plugins/en/output_REPEAT.tcl

    r961 r1019  
    1 # 
    2 # 
    31# vim: fdm=indent fdn=1 
    42# 
     
    64############################################################################### 
    75# This is a bMotion plugin 
    8 # Copyright (C) James Michael Seward 2000-2008 
     6# Copyright (C) James Michael Seward 2000-2009 
    97# 
    108# This program is covered by the GPL, please refer the to LICENCE file in the 
     
    1715 
    1816proc bMotion_plugin_output_REPEAT { channel line } { 
    19         set previous_line "" 
    20         while {[regexp -nocase "%REPEAT\{(.+?)\}" $line matches BOOM]} { 
     17        if {[regexp -nocase "%REPEAT\{(.+?)\}" $line matches BOOM]} { 
    2118                set replacement [bMotionMakeRepeat $BOOM] 
    2219                regsub -nocase "%REPEAT\\{$BOOM\\}" $line $replacement line 
    23                 if {$previous_line == $line} { 
    24                         putlog "bMotion: ALERT! looping too much in %REPEAT code with $line (no change since last parse)" 
    25                         set line "" 
    26                         break 
    27                 } 
    28                 set previous_line $line 
    2920        } 
    3021        return $line 
  • trunk/plugins/en/output_SETTING.tcl

    r961 r1019  
    1 # 
    2 # 
    31# vim: fdm=indent fdn=1 
    42# 
     
    64############################################################################### 
    75# This is a bMotion plugin 
    8 # Copyright (C) James Michael Seward 2000-2008 
     6# Copyright (C) James Michael Seward 2000-2009 
    97# 
    108# This program is covered by the GPL, please refer the to LICENCE file in the 
     
    1917        bMotion_putloglev 4 * "bMotion_plugin_output_SETTING $channel $line" 
    2018 
    21         set lastline "" 
    22  
    23         while {[regexp "%SETTING\{(.+?)\}" $line matches settingString]} { 
     19        if {[regexp "%SETTING\{(.+?)\}" $line matches settingString]} { 
    2420                set var "" 
    2521                if [regexp {([^:]+:[^:]+):([^:]+):([^:]+):([^:]+)} $settingString matches plugin setting ch ni] { 
     
    3127                } 
    3228                set line [bMotionInsertString $line "%SETTING{$settingString}" $var] 
    33  
    34                 if {$lastline == $line} { 
    35                         putlog "bMotion: ALERT: couldn't parse $line for %SETTING (dropping output)"     
    36                         set line "" 
    37                         break 
    38                 } 
    3929        } 
    4030 
  • trunk/plugins/en/output_TIME.tcl

    r961 r1019  
    1 # 
    2 # 
    31# vim: fdm=indent fdn=1 
    42# 
     
    64############################################################################### 
    75# This is a bMotion plugin 
    8 # Copyright (C) James Michael Seward 2000-2008 
     6# Copyright (C) James Michael Seward 2000-2009 
    97# 
    108# This program is covered by the GPL, please refer the to LICENCE file in the 
     
    1917        bMotion_putloglev 4 * "bMotion_plugin_output_TIME $channel $line" 
    2018 
    21         set lastline "" 
    22  
    23         while {[regexp "%TIME\{(\[a-zA-Z0-9 -\]+)\}" $line matches timeString]} { 
     19        if {[regexp "%TIME\{(\[a-zA-Z0-9 -\]+)\}" $line matches timeString]} { 
    2420                bMotion_putloglev 2 * "found timestring $timeString" 
    2521                set origtime $timeString 
     
    2925                bMotion_putloglev 2 * "using time $var" 
    3026                set line [bMotionInsertString $line "%TIME\\{$origtime\\}" $var] 
    31  
    32                 if {$lastline == $line} { 
    33                         # nothing changed 
    34                         set line "" 
    35                         break 
    36                 } 
    37                 set lastline $line 
    3827        } 
    3928 
  • trunk/plugins/en/output_VAR.tcl

    r1016 r1019  
    1 # 
    2 # 
    31# vim: fdm=indent fdn=1 
    42# 
     
    64############################################################################### 
    75# This is a bMotion plugin 
    8 # Copyright (C) James Michael Seward 2000-2008 
     6# Copyright (C) James Michael Seward 2000-2009 
    97# 
    108# This program is covered by the GPL, please refer the to LICENCE file in the 
     
    3230        regsub {%VAR\{([^\}]+)\}\{strip\}} $line "%VAR{\\1:strip}" line 
    3331 
    34         set lastloop "" 
    35  
    36         while {[regexp -nocase {(%VAR\{([^\}:]+)(:[^\}]+)?\}(\{strip\})?)} $line matches whole_thing abstract options clean]} { 
     32        if {[regexp -nocase {(%VAR\{([^\}:]+)(:[^\}]+)?\}(\{strip\})?)} $line matches whole_thing abstract options clean]} { 
    3733                global $abstract 
    3834                #see if we have a new-style abstract available 
     
    126122                        set line [bMotionInsertString $line "%noun" "%VAR{sillyThings}"] 
    127123                } 
    128  
    129                 if {$lastloop == $line} { 
    130                         putlog "bMotion: ALERT! looping too much in %VAR code with $line (no change since last parse)" 
    131                         set line "/has a tremendous error while trying to sort something out :(" 
    132                         break 
    133                 } 
    134                 set lastloop $line 
    135124        } 
    136125 
  • trunk/plugins/en/output_VERB.tcl

    r961 r1019  
    1 # 
    2 # 
    31# vim: fdm=indent fdn=1 
    42# 
     
    1816proc bMotion_plugin_output_VERB { channel line } { 
    1917 
    20         set previous_line "" 
    21  
    22         while {[regexp -nocase "%VERB\{(.*?)\}" $line matches BOOM]} { 
     18        if {[regexp -nocase "%VERB\{(.*?)\}" $line matches BOOM]} { 
    2319                regsub -nocase "%VERB\{$BOOM\}" $line [bMotionMakeVerb $BOOM] line 
    24                 if {$line == $previous_line} { 
    25                         putlog "bMotion: ALERT! looping too much in %VERB code with $line (no change since last parse)" 
    26                         set line "" 
    27                         break 
    28                 } 
    29                 set previous_line $line 
    3020        } 
    3121 
Note: See TracChangeset for help on using the changeset viewer.