Changeset 1026


Ignore:
Timestamp:
08/29/09 04:42:03 (2 years ago)
Author:
james
Message:

Add diagnostic to parse all abstracts and report any broken ones

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/abstract.tcl

    r1022 r1026  
    621621} 
    622622 
     623# implementation-independent way to get all abstract names 
     624proc bMotion_abstract_get_names { } { 
     625        global bMotion_abstract_contents 
     626        return [array names bMotion_abstract_contents] 
     627} 
    623628 
    624629bind time - "* * * * *" bMotion_abstract_auto_gc 
  • trunk/modules/diagnostics.tcl

    r947 r1026  
    328328} 
    329329 
     330### bMotion_diagnostic_parsing 
     331# Try to build every abstract we can and make sure it parses ok 
     332# This is not run automatically! 
     333# This is run as an admin plugin, so it tries to output to the admin stuff 
     334proc bMotion_diagnostic_parsing { } { 
     335        bMotion_putadmin "Counting abstracts..." 
     336        set all_abstracts [bMotion_abstract_get_names] 
     337        set all_abstracts_size [llength $all_abstracts] 
     338        bMotion_putadmin "Found $all_abstracts_size abstracts" 
     339 
     340        set broken [list] 
     341        set errors 0 
     342        set count_abstract 0 
     343        set count_lines 0 
     344        set i 0 
     345 
     346        foreach abstract $all_abstracts { 
     347                incr i 
     348                if {[expr $i % 10] == 0} { 
     349                        bMotion_putadmin "Processing abstract $i: $abstract..." 
     350                } 
     351                set abstract_contents [bMotion_abstract_all $abstract] 
     352                bMotion_putloglev d * "Processing [llength $abstract_contents] items for abstract $abstract" 
     353                incr count_abstract 
     354                foreach content $abstract_contents { 
     355                        incr count_lines 
     356                        set line "" 
     357                        set fail "" 
     358                        catch { 
     359                                set line [bMotion_process_macros "" $content] 
     360                                set line [bMotionDoInterpolation $line "JamesOff" "moretext" "#diagnostics"] 
     361                                # bit of a hack! 
     362                                set line [bMotion_plugin_output_preprocess "#diagnostics" $line] 
     363                        }  
     364                        if {($line == "") || [regexp {%(?!(SETTING|ruser|r?bot|BOT|percent|channel))[^%2\| ]} $line matches moo]} { 
     365                                incr errors 
     366                                lappend broken "$abstract:$content\r\n  -> $line" 
     367                        } 
     368                } 
     369        } 
     370 
     371        bMotion_putadmin "Finished." 
     372        bMotion_putadmin "$errors errors found in $count_lines lines in $count_abstract abstracts." 
     373        foreach line $broken { 
     374                bMotion_putadmin $line 
     375        } 
     376} 
     377 
    330378### bMotion_diagnostic_auto <<<1 
    331379proc bMotion_diagnostic_auto { min hr a b c } { 
  • trunk/modules/output.tcl

    r1022 r1026  
    121121} 
    122122 
    123 # 
    124 # our magic output function 
    125 proc bMotionDoAction {channel nick text {moreText ""} {noTypo 0} {urgent 0} } { 
    126         bMotion_putloglev 5 * "bMotionDoAction($channel,$nick,$text,$moreText,$noTypo,$urgent)" 
    127         global bMotionInfo bMotionCache bMotionOriginalInput 
    128         global bMotion_output_delay bMotionSettings BMOTION_SLEEP 
    129  
    130         set bMotion_output_delay 0 
    131  
    132         #check our global toggle 
    133         global bMotionGlobal 
    134         if {$bMotionGlobal == 0} { 
    135                 return 0 
    136         } 
    137  
    138         set bMotionCache($channel,last) 1 
    139  
    140         # check if we're asleep 
    141         if {[bMotion_setting_get "asleep"] == $BMOTION_SLEEP(ASLEEP)} { 
    142                 return 0 
    143         } 
    144  
    145         if [regexp "^\[#!\].+" $channel] { 
    146                 set channel [string tolower $channel] 
    147                 if {![channel get $channel bmotion]} { 
    148                         bMotion_putloglev d * "bMotion: aborting bMotionDoAction ... $channel not allowed" 
    149                         return 0 
    150                 } 
    151         } 
    152  
    153         if {[bMotion_setting_get "silence"] == 1} {  
    154                 return 0  
    155         } 
    156         catch { 
    157                 if {$bMotionInfo(adminSilence,$channel) == 1} {  
    158                         return 0  
    159                 } 
    160         } 
    161  
    162         switch [rand 3] { 
    163                 0 { } 
    164                 1 { set nick [string tolower $nick] } 
    165                 2 { set nick "[string range $nick 0 0][string tolower [string range $nick 1 end]]" } 
    166         } 
    167  
    168         # Process macros 
     123proc bMotion_process_macros { channel text } { 
    169124 
    170125        set done 0 
     
    174129                set current_pos [string first "%" $text $current_pos] 
    175130                if {$current_pos == -1} { 
    176                         # no more matches 
     131                # no more matches 
    177132                        set done 1 
    178133                        continue 
     
    180135                bMotion_putloglev d * "macro: found a % at $current_pos" 
    181136                if {$current_pos < [string length $text]} { 
    182                         # this isn't a % at the end of the line 
     137                # this isn't a % at the end of the line 
    183138                        if {[string index $text [expr $current_pos + 1]] == "|"} { 
    184139                                set current_pos [expr $current_pos + 2] 
     
    192147                                set plugin [bMotion_plugin_find_output "en" "" 0 10 $macro] 
    193148                                if {[llength $plugin] == 1} { 
    194                                         # call plugin 
     149                                # call plugin 
    195150                                        bMotion_putloglev d * "macro: found matching plugin for macro [lindex $plugin 0]" 
    196151                                        set result "" 
     
    235190                incr current_pos 
    236191        } 
     192 
     193        return $text 
     194} 
     195 
     196# 
     197# our magic output function 
     198proc bMotionDoAction {channel nick text {moreText ""} {noTypo 0} {urgent 0} } { 
     199        bMotion_putloglev 5 * "bMotionDoAction($channel,$nick,$text,$moreText,$noTypo,$urgent)" 
     200        global bMotionInfo bMotionCache bMotionOriginalInput 
     201        global bMotion_output_delay bMotionSettings BMOTION_SLEEP 
     202 
     203        set bMotion_output_delay 0 
     204 
     205        #check our global toggle 
     206        global bMotionGlobal 
     207        if {$bMotionGlobal == 0} { 
     208                return 0 
     209        } 
     210 
     211        set bMotionCache($channel,last) 1 
     212 
     213        # check if we're asleep 
     214        if {[bMotion_setting_get "asleep"] == $BMOTION_SLEEP(ASLEEP)} { 
     215                return 0 
     216        } 
     217 
     218        if [regexp "^\[#!\].+" $channel] { 
     219                set channel [string tolower $channel] 
     220                if {![channel get $channel bmotion]} { 
     221                        bMotion_putloglev d * "bMotion: aborting bMotionDoAction ... $channel not allowed" 
     222                        return 0 
     223                } 
     224        } 
     225 
     226        if {[bMotion_setting_get "silence"] == 1} {  
     227                return 0  
     228        } 
     229        catch { 
     230                if {$bMotionInfo(adminSilence,$channel) == 1} {  
     231                        return 0  
     232                } 
     233        } 
     234 
     235        switch [rand 3] { 
     236                0 { } 
     237                1 { set nick [string tolower $nick] } 
     238                2 { set nick "[string range $nick 0 0][string tolower [string range $nick 1 end]]" } 
     239        } 
     240 
     241        # Process macros 
     242 
     243        set text [bMotion_process_macros $channel $text] 
    237244 
    238245        # Run the plugins :D 
     
    482489        } 
    483490 
    484         regsub -all "%%" $line "%percent" line 
     491        regsub -all "%" $line "%percent" line 
    485492 
    486493        return $line 
  • trunk/plugins/admin_abstract.tcl

    r862 r1026  
    7878                bMotion_abstract_flush 
    7979                bMotion_putadmin "Flushing all abstracts to disk..." 
     80                return 0 
     81        } 
     82 
     83        if [regexp -nocase "diagnose" $arg] { 
     84                bMotion_diagnostic_parsing 
    8085                return 0 
    8186        } 
     
    161166        bMotion_putadmin "  .bmotion abstract filter apply <abstract>" 
    162167        bMotion_putadmin "    For an abstract to be filtered now" 
     168        bMotion_putadmin "  .bmotion abstract diagnose" 
     169        bMotion_putadmin "    Test all abstracts for parsability and report any broken ones" 
    163170        return 0 
    164171} 
  • trunk/plugins/en/output_VAR.tcl

    r1022 r1026  
    118118 
    119119                # check if what we swapped in gave us a %noun 
    120                 if [string match "*%noun*" $line] { 
    121                         set line [bMotionInsertString $line "%noun" "%VAR{sillyThings}"] 
    122                 } 
     120                set line [string map { "%noun" "%VAR{sillyThings}" } $line] 
    123121        } 
    124122 
Note: See TracChangeset for help on using the changeset viewer.