Sir_Fz wrote:how to catch the channel add ?
Code: Select all
if {[catch {channel add invalidName} var]} {
# an error occured, $var is the error message
} else {
# everything went fine...var contains the value returned by the command
}
Sir_Fz wrote:how to catch the channel add ?
Code: Select all
if {[catch {channel add invalidName} var]} {
# an error occured, $var is the error message
} else {
# everything went fine...var contains the value returned by the command
}
Code: Select all
bind msg m .join pub_join
proc pub_join {nick uhost hand arg} {
set chan [lindex [split $arg] 0]
if {[catch {channel add $chan} var]} {
puthelp "PRIVMSG $nick :$var - use prefix: \002#\002"
} else {
channel add $chan
puthelp "PRIVMSG $nick :Succesfully join $chan"
}
Code: Select all
bind msg m .join pub_join
proc pub_join {nick uhost hand arg} {
set chan [lindex [split $arg] 0]
if {[catch {channel add $chan} "*Invalid channel*"]} {
puthelp "PRIVMSG $nick :Invalid Channel - use prefix: \002#\002"
} else {
channel add $chan
puthelp "PRIVMSG $nick :Succesfully join $chan"
}
The first one was closer, however on successful completion of the 'channel add' command from within the catch claus, you do not want to execute 'channel add' again.. Remove it from the 'else' branch, and it will be fine.Sir_Fz wrote:so this code is correct?orCode: Select all
bind msg m .join pub_join proc pub_join {nick uhost hand arg} { set chan [lindex [split $arg] 0] if {[catch {channel add $chan} var]} { puthelp "PRIVMSG $nick :$var - use prefix: \002#\002" } else { channel add $chan puthelp "PRIVMSG $nick :Succesfully join $chan" }
?Code: Select all
bind msg m .join pub_join proc pub_join {nick uhost hand arg} { set chan [lindex [split $arg] 0] if {[catch {channel add $chan} "*Invalid channel*"]} { puthelp "PRIVMSG $nick :Invalid Channel - use prefix: \002#\002" } else { channel add $chan puthelp "PRIVMSG $nick :Succesfully join $chan" }
Code: Select all
bind msg m .join pub_join
proc pub_join {nick uhost hand arg} {
set chan [lindex [split $arg] 0]
if {[catch {channel add $chan} var]} {
puthelp "PRIVMSG $nick :$var - use prefix: \002#\002"
} else {
puthelp "PRIVMSG $nick :Succesfully joined $chan"
}
Properly indenting the code would probably make you add another "}" without even thinking about itSir_Fz wrote:Code: Select all
proc pub_join {nick uhost hand arg} { set chan [lindex [split $arg] 0] if {[catch {channel add $chan} var]} { puthelp "PRIVMSG $nick :$var - use prefix: \002#\002" } else { puthelp "PRIVMSG $nick :Succesfully joined $chan" }