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.
Old posts that have not been replied to for several years.
a
acm
Post
by acm » Thu Dec 26, 2002 11:06 pm
I wrote a little !calc script:
Code: Select all
bind pub - !calc calc
proc calc { nick uhost hand chan arg } {
if {[llength $arg]==0} {
return 0
}
set result [expr $arg]
putserv "PRIVMSG $chan :$nick: $result"
}
It works exactly how I want it to,
except when there are problems with the arguments. Example:
!calc 4 / 0
This returns the following in botnet (and nothing to the channel):
Tcl error [calc]: divide by zero
I would like this to print out to the channel instead. Is it possible to do output redirection like this?
tainted
Master
Posts: 239 Joined: Sun May 12, 2002 8:00 pm
Location: chicago
Contact:
Post
by tainted » Thu Dec 26, 2002 11:59 pm
You should probably catch it, with something similiar to this (correct me if im wrong guys)
Code: Select all
if {[catch blah blah e]} {
putserv "etc etc"
return
}
<on to the existing code>
Make sure to use catch to execute the calc string, otherwise it wont do any good. You could also just check if the operation is "/" and then if the number is not zero, put I'll let you try out this way first.
a
acm
Post
by acm » Fri Dec 27, 2002 12:13 am
Thanks for the quick reply! 'catch' is exactly what I was looking for. Here is the final code for anyone interested:
Code: Select all
bind pub - !calc calc
proc calc { nick uhost hand chan arg } {
if {[llength $arg]==0} {
return 0
}
if { [catch { set result [expr $arg]} err] } {
putserv "PRIVMSG $chan :$nick: Error: $err"
} else {
putserv "PRIVMSG $chan :$nick: $result"
}
}
thanks again,
acm