This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Errorhandling using the http package

Old posts that have not been replied to for several years.
Locked
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Errorhandling using the http package

Post by ProXy »

Hi there,

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"
M
MC_8
Voice
Posts: 36
Joined: Sat Apr 26, 2003 5:04 pm
Location: Dallas, Texas
Contact:

Post by MC_8 »

I see it handling errors within your code... what's the question again?
As far as catching TCL errors, use catch -> http://tcl.activestate.com/man/tcl8.3/TclCmd/catch.htm.
Carl M. Gregory - MC_8
http://mc.purehype.net/whois/
Locked