I wrote a little script that reads the info about a stream from a website. It works fine, but I would like to add some errorhandling. Maybe the Site is down, my eggdrop only writes some error messages to the partyline. Maybe anyone could help me to do this?
Here`s the source so far:
Code: Select all
############ Configuration #############
set streamurl "http://rootbash.com:25000"
########################################
bind pub *|* "!listeners" pub:listeners
package require http
proc pub:listeners {nick host handle channel arg} {
global streamurl
set streamsource [http::geturl $streamurl]
upvar #0 $streamsource streaminfo
if {[lindex $streaminfo(http) 2] != "OK"} {
putserv "PRIVMSG $channel :Sorry, an error occured!"
} else {
set streamdata [http::data $streamsource]
set streamkbps "0"
regexp {^.*Stream Status: </font></td><td><font class=default><b>Stream is up at (.*) kbps with <B>(.*) of (.*) listeners \((.*) unique\).*} $streamdata streamdata streamkbps streamlisteners streammaxlisteners streamuniquelisteners
if {$streamkbps == "0"} {
putserv "PRIVMSG $channel :Sorry, the stream is currently offline!"
} else {
putserv "PRIVMSG $channel :The stream is online at $streamkbps kbps with $streamlisteners/$streammaxlisteners listeners. ($streamuniquelisteners unique)"
}
}
}
putlog "LOADED: Stream v0.1"