# -*- tcl -*-
# $Id: quota.tcl,v 1.2 2004/08/01 19:55:43 shrike Exp $

bind pub -|- [set cmdpre]quota quota

proc quota { nick uhost hand chan arg } {
    global sitename

    set url "http://netinfo.jyu.fi/resnet/resnet-netquota.cgi"
    set lynx "/usr/bin/lynx"
    
    set quotastr ""

    foreach line [split [exec $lynx "--dump" "-connect_timeout=5" "--width=100" "$url"] "\n"] {
	if {[string match "*You can transfer*" $line]} {
	    set quotastr [string replace $line 0 4]
	    break
	}
    }

    if {[string length $quotastr] != 0} {
	putquick "PRIVMSG $chan :-$sitename- \[QUOTA\] $quotastr"
    } else {
	putquick "PRIVMSG $chan :-$sitename- \[QUOTA\] Cannot get quota info"
    }
}

putlog "JYU Quota v1.0 by Shrike loaded"

### for debugging ###
#set cmdpre "h"
#set sitename "Hyperion"
#proc putquick { str } {
#    puts $str
#}
#quota "nick" "uhost" "hand" "\#chan" "arg"

