Posted to tcl by Stu at Fri May 09 03:22:43 GMT 2008view pretty

namespace eval ::herring {}

proc herring::wikisearch {what {max -1}} {
        set z {}
        set c 0
        set h [http::geturl http://wiki.tcl.tk/_search?S=$what]
        if {[http::status $h] eq {ok}} {
                foreach {. p n} [regexp -inline -all {<li>.*?\. \. \. <a href="/(.*?)">(.*?)</a>} [http::data $h]] {
                        lappend z http://wiki.tcl.tk/$p\ \t$n
                        if {$max == -1} { continue }
                        if {[incr c] >= $max} { break }
                }
        }
        http::cleanup $h
        return $z
}


proc herring::wikiref {msg} {
        set srchres [wikisearch $msg 5]
        if {[llength $srchres] > 0} {
                ::tkjabber::msgSend "/nolog [join $srchres \n]" -attrs [list nolog 1]
        }
}

::tkchat::processAliasCommand {/alias wikiref proc ::herring::wikiref}