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

  1. namespace eval ::herring {}
  2.  
  3. proc herring::wikisearch {what {max -1}} {
  4. set z {}
  5. set c 0
  6. set h [http::geturl http://wiki.tcl.tk/_search?S=$what]
  7. if {[http::status $h] eq {ok}} {
  8. foreach {. p n} [regexp -inline -all {<li>.*?\. \. \. <a href="/(.*?)">(.*?)</a>} [http::data $h]] {
  9. lappend z http://wiki.tcl.tk/$p\ \t$n
  10. if {$max == -1} { continue }
  11. if {[incr c] >= $max} { break }
  12. }
  13. }
  14. http::cleanup $h
  15. return $z
  16. }
  17.  
  18.  
  19. proc herring::wikiref {msg} {
  20. set srchres [wikisearch $msg 5]
  21. if {[llength $srchres] > 0} {
  22. ::tkjabber::msgSend "/nolog [join $srchres \n]" -attrs [list nolog 1]
  23. }
  24. }
  25.  
  26. ::tkchat::processAliasCommand {/alias wikiref proc ::herring::wikiref}