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.

need help creating an autovoice

Old posts that have not been replied to for several years.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

user wrote:
Sir_Fz wrote:so how should it be ? $flnick == [lsearch $firstletter] ?
If we're to believe the manual, the syntax is as follows: lsearch ?options? list pattern ...and the index of the first element matching is returned or -1 if it was not found..so something like this should do the trick:

Code: Select all

if {[lsearch -exact $firstletter $flnick]>-1} {found} {not}
didn't get the "{found} {not}" part.

also in your final post:
if {[botisop $chan] && [string match \[a-z\]* $nick]} {
doesn't this mean if one of the cases is available the bot does the voicing.

shouldn't it be if {[botisop $chan] || [string match \[a-z\]* $nick]} {
so the bot only voices when both cases are available ?
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Sir_Fz wrote:didn't get the "{found} {not}" part.

the {found} is where you put the code you want to handle the case where a match is found, the {not} is where you put the code you want to handle the case where a match is NOT found.
Sir_Fz wrote: also in your final post:
if {[botisop $chan] && [string match \[a-z\]* $nick]} {
doesn't this mean if one of the cases is available the bot does the voicing.
shouldn't it be if {[botisop $chan] || [string match \[a-z\]* $nick]} {
so the bot only voices when both cases are available ?

Um, "||" is the logical OR , and "&&" is the logical "AND".. So "&&" is infact what he wanted.

I highly suggest you go through the suninet eggdrop tcl tutorial.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

BlackRaven wrote:some of the other nicks I want it to voice begin with different brackets...
Your creation of the variable and comparison would work, but you have an extra { in there screwing things up.

I'd just include the braces in the character range passed to 'string match' in the existing code like this:
\[a-z\{\}\]*
Then it would match anything starting with a lowercase letter OR a brace...just add the chars you want between the brackets ([]) and escape the ones that needs it. (check the manual if in doubt)
B
BlackRaven

Post by BlackRaven »

Thanks for all the great advice user, I appreciate it tremendously

BR
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

strikelight wrote:[snip]
the {found} is where you put the code you want to handle the case where a match is found, the {not} is where you put the code you want to handle the case where a match is NOT found.

Um, "||" is the logical OR , and "&&" is the logical "AND".. So "&&" is infact what he wanted.

I highly suggest you go through the suninet eggdrop tcl tutorial.
well I didn't get much of the found not... would you please give me an example, because if commands usualy are if {bla} {do} so how come you're telling me if {command} {found} {not} ... it confuses me.
can you please give an example ?

also some example about the "|| or" and the "&& and" , using them in lots of cases but not figuring out how they function.

thank you :)
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Sir_Fz wrote:
strikelight wrote:[snip]
the {found} is where you put the code you want to handle the case where a match is found, the {not} is where you put the code you want to handle the case where a match is NOT found.

Um, "||" is the logical OR , and "&&" is the logical "AND".. So "&&" is infact what he wanted.

I highly suggest you go through the suninet eggdrop tcl tutorial.
well I didn't get much of the found not... would you please give me an example, because if commands usualy are if {bla} {do} so how come you're telling me if {command} {found} {not} ... it confuses me.
can you please give an example ?

also some example about the "|| or" and the "&& and" , using them in lots of cases but not figuring out how they function.

thank you :)
The forum is polluted with examples, as is the suninet site that was posted in my last reply in this thread...

However.. Staying with the example from this thread:

Code: Select all

if {[botisop $chan] && [string match \[a-z\]* $nick]} { 
  # Here is what is meant by "found"....
  putlog "The bot is opped in $chan -AND- The first letter of the nick "$nick" is a lowercase letter"
} {
  # Here is what is meant by "not found"
  putlog "Either the bot is not opped in $chan -OR- The first letter of the nick "$nick" is NOT a lowercase letter"
}
Now, many times you'll see an 'else' in the middle of that code between the } and the { , which is perfectly acceptable, but unnecessary.

For more examples, again, I emplore you to read through various threads on this forum, and also visit various tcl tutorial sites, such as the mentioned suninet.nl site.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

ok, that's what confused me. I always use the "else" between the two } {.

I'll be reading the manuals :)

thank you
User avatar
Dedan
Master
Posts: 260
Joined: Wed Jul 09, 2003 10:50 pm
Location: Memphis

Post by Dedan »

ok,
lets say you want to return the first 3 letters of a word.
what is the simplest way to do that?

Code: Select all

set word "eggdrop"

proc get:first:3letters { stuff } {
  global word
  set first3letters [ ?? [split $word] ??]
}

I once was an intelligent young man, now i am old and i can not remember who i was.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

User avatar
Dedan
Master
Posts: 260
Joined: Wed Jul 09, 2003 10:50 pm
Location: Memphis

Post by Dedan »

cool,
thanks user
I once was an intelligent young man, now i am old and i can not remember who i was.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

if it's a string then do as user sugested, but when is a list use lrange.
Once the game is over, the king and the pawn go back in the same box.
User avatar
Dedan
Master
Posts: 260
Joined: Wed Jul 09, 2003 10:50 pm
Location: Memphis

Post by Dedan »

Code: Select all

set word "eggdrop" 

proc get:first:3letters { stuff } { 
  global word 
  set first3letters [string trimright $word 2]
  # returns egg
  set firstletter [string trimright $word 0]
  # returns e

  also, how can i check to see if $firstletter is a number?
  is there a command, or do you "have" to use regexp
} 

I once was an intelligent young man, now i am old and i can not remember who i was.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

'string trim' doesn't do what you said in your comments. I recommend reading the entire 'string' manual page :)

Check out: string is, string index, string range, string match
Last edited by user on Wed Sep 03, 2003 5:07 pm, edited 2 times in total.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

most networks do not allow the first letter to be a number.

if on yours' its allowed then regexp would be the best solution.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

regexp SUCKS :P (so slow compared to most string commands that perform such tasks...it's only needed for really complex patterns that would require lots of other commands)

Here's an example (matching a number as the first char in a string):
% set a 0abcdefghijklmnopqrstuvwxyz
0abcdefghijklmnopqrstuvwxyz
% time [list regexp {[0-9]+.*} $a] 100000
10 microseconds per iteration
% time [list string match {[0-9]*} $a] 100000
2 microseconds per iteration
Last edited by user on Wed Sep 03, 2003 5:13 pm, edited 1 time in total.
Locked