bind pub - !suser-tux pub:susertux

proc pub:susertux {nick host handle chan arg} {

if {[llength $arg]==0} {
	putserv "PRIVMSG $channel :Syntax: !suser-tux <Suse_Version> (z.B. !suser-tux 9.1 zeigt die vorh. RPMs für Suse 9.1)"

	} else {

    set distri [lindex $arg 0]
    set tok [http::geturl http://ftp.gwdg.de/pub/linux/suse/apt/SuSE/$distri-i386/RPMS.suser-tux/]
    set data [http::data $tok]

    foreach {word word} [regexp -all -inline {"HREF=\"([^"]+)rpm\">"} $data] {
      lappend words $word
    }

    foreach line [wordwrap $words 400] {
    putserv "PRIVMSG $chan : RPMs von suser-tux für Suse $distri: $line"
    }
    }
    }
    
proc wordwrap {str {len 300} {splitChr { }}} {
   set out [set cur {}]; set i 0
   foreach word [split [set str][unset str] $splitChr] {
      if {[incr i [string len $word]]>$len} {
         lappend out [join $cur $splitChr]
         set cur [list $word]
         set i [string len $word]
      } {
         lappend cur $word
      }
      incr i
   }
   lappend out [join $cur $splitChr]
}