egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Check letters

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
McMilan
Voice


Joined: 13 Mar 2009
Posts: 24

PostPosted: Sun Aug 16, 2009 5:36 am    Post subject: Check letters Reply with quote

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
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Sun Aug 16, 2009 6:22 am    Post subject: Reply with quote

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
View user's profile Send private message
McMilan
Voice


Joined: 13 Mar 2009
Posts: 24

PostPosted: Sun Aug 16, 2009 8:42 am    Post subject: Reply with quote

Thanks Very Happy

And, how to check if ! and @ are in a word? This is to check if is a invalid hostname or no.
Back to top
View user's profile Send private message
TCL_no_TK
Owner


Joined: 25 Aug 2006
Posts: 509
Location: England, Yorkshire

PostPosted: Sun Aug 16, 2009 9:35 am    Post subject: Reply with quote

Can use
Code:
 if {![string match "*!*@*.*" $uhost]} {
 #not a valid hostmask
}
Very Happy
_________________
TCL the misunderstood
Back to top
View user's profile Send private message Send e-mail
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Sun Aug 16, 2009 9:44 am    Post subject: Reply with quote

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
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Sun Aug 16, 2009 10:15 am    Post subject: Reply with quote

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
View user's profile Send private message
McMilan
Voice


Joined: 13 Mar 2009
Posts: 24

PostPosted: Sun Aug 16, 2009 10:31 am    Post subject: Reply with quote

And how to check if there is no ! and @? because it is for a nickname/hostname ban script.
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Sun Aug 16, 2009 10:40 am    Post subject: Reply with quote

From the information given so far, its time to try yourself
_________________
I must have had nothing to do
Back to top
View user's profile Send private message
McMilan
Voice


Joined: 13 Mar 2009
Posts: 24

PostPosted: Sun Aug 16, 2009 10:50 am    Post subject: Reply with quote

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
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sun Aug 16, 2009 11:28 am    Post subject: Reply with quote

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
View user's profile Send private message
McMilan
Voice


Joined: 13 Mar 2009
Posts: 24

PostPosted: Sun Aug 16, 2009 11:36 am    Post subject: Reply with quote

It works like arfer's script. Embarassed
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sun Aug 16, 2009 11:41 am    Post subject: Reply with quote

McMilan wrote:
It works like arfer's script. Embarassed

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.. Smile
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
McMilan
Voice


Joined: 13 Mar 2009
Posts: 24

PostPosted: Sun Aug 16, 2009 11:45 am    Post subject: Reply with quote

Shocked

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
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sun Aug 16, 2009 11:46 am    Post subject: Reply with quote

McMilan wrote:
Shocked

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
View user's profile Send private message
McMilan
Voice


Joined: 13 Mar 2009
Posts: 24

PostPosted: Sun Aug 16, 2009 11:54 am    Post subject: Reply with quote

Oops... Sorry. Embarassed Embarassed Embarassed

Thanks hehehe
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber