| View previous topic :: View next topic |
| Author |
Message |
McMilan Voice
Joined: 13 Mar 2009 Posts: 24
|
Posted: Sun Aug 16, 2009 5:36 am Post subject: Check letters |
|
|
Hi.
How can i check what is the first letter of a word?
What i mean is how to check if a word is a channel. Checking if its first letter is a #
Thanks. |
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Sun Aug 16, 2009 6:22 am Post subject: |
|
|
You could use a string command
| Code: |
if {[string index $chan 0] == "#"} {
# code here
}
|
Or possibly two string commands
| Code: |
if {[string equal [string index $chan 0] "#"]} {
# code here
}
|
Or a regexp
| Code: |
if {[regexp -- {^#} $chan]} {
# code here
}
|
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.
| Code: |
if {[validchan $chan]} {
# code here
}
|
All the above assume the value of the variable chan (referenced by $chan) is the channel name to be checked _________________ I must have had nothing to do |
|
| Back to top |
|
 |
McMilan Voice
Joined: 13 Mar 2009 Posts: 24
|
Posted: Sun Aug 16, 2009 8:42 am Post subject: |
|
|
Thanks
And, how to check if ! and @ are in a word? This is to check if is a invalid hostname or no. |
|
| Back to top |
|
 |
TCL_no_TK Owner

Joined: 25 Aug 2006 Posts: 509 Location: England, Yorkshire
|
Posted: Sun Aug 16, 2009 9:35 am Post subject: |
|
|
Can use | Code: | if {![string match "*!*@*.*" $uhost]} {
#not a valid hostmask
} |  _________________ TCL the misunderstood |
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Sun Aug 16, 2009 9:44 am Post subject: |
|
|
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.
| Code: |
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 _________________ I must have had nothing to do |
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Sun Aug 16, 2009 10:15 am Post subject: |
|
|
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. _________________ I must have had nothing to do |
|
| Back to top |
|
 |
McMilan Voice
Joined: 13 Mar 2009 Posts: 24
|
Posted: Sun Aug 16, 2009 10:31 am Post subject: |
|
|
| And how to check if there is no ! and @? because it is for a nickname/hostname ban script. |
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Sun Aug 16, 2009 10:40 am Post subject: |
|
|
From the information given so far, its time to try yourself _________________ I must have had nothing to do |
|
| Back to top |
|
 |
McMilan Voice
Joined: 13 Mar 2009 Posts: 24
|
Posted: Sun Aug 16, 2009 10:50 am Post subject: |
|
|
lol
But how can i check if ! and @ there is no?
I dont know if you know mirc scripting, but i wanted something like:
| Code: |
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
}
|
i am new in tcl. |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Aug 16, 2009 11:28 am Post subject: |
|
|
| Code: | 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"
}
} |
_________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
McMilan Voice
Joined: 13 Mar 2009 Posts: 24
|
Posted: Sun Aug 16, 2009 11:36 am Post subject: |
|
|
It works like arfer's script.  |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Aug 16, 2009 11:41 am Post subject: |
|
|
| McMilan wrote: | It works like arfer's script.  |
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..  _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
McMilan Voice
Joined: 13 Mar 2009 Posts: 24
|
Posted: Sun Aug 16, 2009 11:45 am Post subject: |
|
|
Look, my mirc scripting code had a if, a elseif and a else. And your tcl script had just a if and a else. |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Aug 16, 2009 11:46 am Post subject: |
|
|
| McMilan wrote: |
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....
| Code: | #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. _________________ speechles' eggdrop tcl archive
Last edited by speechles on Sun Aug 16, 2009 11:55 am; edited 1 time in total |
|
| Back to top |
|
 |
McMilan Voice
Joined: 13 Mar 2009 Posts: 24
|
Posted: Sun Aug 16, 2009 11:54 am Post subject: |
|
|
Oops... Sorry.
Thanks hehehe |
|
| Back to top |
|
 |
|