Or, if the intended channel is supposed to be one of the bot's channels, an eggdrop tcl command will check if this is true. Generally, all channel names begin with a hash so without the hash it could not be a valid bot channel.
It would be easy enough to check if ! and @ were present in a string AND in the correct order using regexp or string match commands but my choice would be to generally use a scan command. This is because it can simultaneously seperate out the nick, user and host components for use later in the code. A regexp command could do the same but I prefer scan.
if {[scan $hostname {%[^!]!%[^@]@%s} nick user host] == 3} {
# $hostname is in the format nick!user@host
# additionally $nick, $user and $host can be used here in any further code
} else {
# $hostname is not in the format nick!user@host
}
Example :-
<arfer> % return [scan "arfer!peter@i.play.for.england.com" {%[^!]!%[^@]@%s} nick user host]
<Baal> 3
<arfer> % return $nick
<Baal> arfer
<arfer> % return $user
<Baal> peter
<arfer> % return $host
<Baal> i.play.for.england.com
Be very careful with our use of variable names. That applies to both my code and that of TCL_no_TK.
TCL_no_TK code is exactly correct except that $uhost is frequently used in eggdrop scripts to represent user@host and not nick!user@host in which case it would never pass the string match test.
In my code I use the variable name nick in the scan command. This variable name is widely used in scripts, say for example passed to a proc by a PUB bind. You would therefore have to choose an alternative name if my code was used inside such a proc.
if (! !isin $1 && @ !isin $1) {
msg # It will be used as nickname
}
elseif (! isin $1 && @ isin $1) {
msg # It will be used as hostname
}
else {
msg # Wrong format
}
bind pub - !something something
proc something {nick uhost hand chan text} {
set firstword [lindex [split $text] 0]
if {![string match "*!*@*" $firstword]} {
if {[string match "*!*" $firstword] || [string match "*@*" $firstword]} {
putserv "privmsg $chan :Wrong format" ; return
}
putserv "privmsg $chan :It will be used as nickname"
} else {
putserv "privmsg $chan :It will be used as hostname"
}
}
Are you high? Perhaps not high enough? It's the same as your crap mIRC code...
Without knowing what-the-F you mean it's clear the blushing your doing indicates to me that any further help you will receive will fall on deaf ears. Good day sir..
Look, my mirc scripting code had a if, a elseif and a else. And your tcl script had just a if and a else.
Check again charlie, all 3 of your conditions are there. And the style of code one uses to attain the same results can be dramatic. You've used horrible style, the tcl script doesn't....
#create the bind for event handling
bind pub - !something something
# create the bound procedure and header
proc something {nick uhost hand chan text} {
# grab the first word, in mirc this is $1
set firstword [lindex [split $text] 0]
# is *!*@* not found in the word?
if {![string match "*!*@*" $firstword]} {
# if there is no *!*@* in the word
# now we need to check them seperately
# *!* and *@*. if found, reply wrong format
if {[string match "*!*" $firstword] || [string match "*@*" $firstword]} {
putserv "privmsg $chan :Wrong format" ; return
}
# there is no *!*@*, no *!*, no *@*
putserv "privmsg $chan :It will be used as nickname"
} else {
# there is *!*@*
putserv "privmsg $chan :It will be used as hostname"
}
}
Commented it so you can see how this works.
Last edited by speechles on Sun Aug 16, 2009 11:55 am, edited 1 time in total.