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.
B
BlackRaven

need help creating an autovoice

Post by BlackRaven »

I have a bit of basic programming, but not sure what identifiers I can use in TCL..

I'm trying to set up a script which autovoices nicks that begin with lowercase letters. If anyone can help Me figure out how to have it check them on joining, I'd greatly appreciate it.

thanks,

BR
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: need help creating an autovoice

Post by user »

'bind join' (check doc/tcl-commands.doc) to trigger a procedure on join, then check the nick with 'string match' or 'regexp' and 'pushmode' to voice (tcl-commands.doc) if you're satisfied with the nick.

Take a look in this Tcl-FAQ thread for some pointers to tutorials and other useful pages.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

I'm just curious; would this work? :

Code: Select all

set firstletter "a b c d e f g h i j k l m n o p q r s t u v w x y z"

bind join - * lcase:voice

proc lcase:voice {nick uhost hand chan} {
set flnick [lindex [split $nick [lindex $nick 1]] 0]
 if {![botisop $chan]} {return 0}
  if {$flnick == [split $a]} {
   pushmode $chan +v $nick
 }
}
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Sir_Fz wrote:I'm just curious; would this work?
no, but I admire your bold attempt :)

Let's examine your code...

Code: Select all

set flnick [lindex [split $nick [lindex $nick 1]] 0]
nick contains a string when this line is executed. First you treat it as a list trying to access the second element from it. Then you split it by the empty element just retrieved from that 'list' (if you're lucky and the nick doesn't contain a {)
This line should be

Code: Select all

set flnick [lindex [split $nick ""] 0]
if you insist on converting it to a list. ('string index' would save you the trouble)

Code: Select all

  if {$flnick == [split $a]} { 
   pushmode $chan +v $nick 
 }
This just doesn't make sense. I take it you renamed some variables before posting the code and forgot 'a'. You also forgot to import the list of chars. As this variable already contains a valid list, there's no need to split it, and using == to find the char just doesn't work. Use 'lsearch' to search lists :)

Tip1: running the code will usually help you determine if it works or not.
Tip2: 'string index' provides an easy way of accessing single chars from a string, but why go through all this trouble when a simple 'string match \[a-z\]* $nick' would give you the answer? :)
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

user wrote:Tip1: running the code will usually help you determine if it works or not.
Tip2: 'string index' provides an easy way of accessing single chars from a string, but why go through all this trouble when a simple 'string match \[a-z\]* $nick' would give you the answer? :)
Or to maintain compatibility with lower tcl versions,
modify Tip2 to be: 'regexp {^[a-z]} $nick'
B
BlackRaven

Post by BlackRaven »

ok so the

string match \[a-z\]* $nick

will return a positive if only the first letter of the nick is lowercase?? or is it checking all of the nick to match?
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Only if the first char is lowercase...the rest is matched by the * and can be anything.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

ok thanx :)
but just for info:

Code: Select all

set firstletter "a b c d e f g h i j k l m n o p q r s t u v w x y z" 

bind join - * lcase:voice 

proc lcase:voice {nick uhost hand chan} { 
global firstletter
set flnick [lindex [split $nick ""] 0] 
 if {![botisop $chan]} {return 0} 
  if {$flnick == [split $firstletter]} { 
   pushmode $chan +v $nick 
 } 
}
I don't know from where I got the $a variable :P but anyway would this code work ?
also what does [split $nick ""] exactly do ?

and can you please explain to me how to use 'string index' ?

thank you :)
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

[split $nick ""] turns the nick into a list of singe characters, so when using 'lindex' on it you can fetch a single char. [string index $nick <number>] will give you a single char without needing to split the string first.

That last 'if' of yours makes just as little sense now as it did the last time. (Read what I said in my previous post for a solution).
The == operator is used to compare values and will never return true unless the values on each side of it are equal. The SINGLE CHAR fetched from the nick will NEVER be equal to that LIST OF CHARS unless you feed your interpreter some strong acid :P

Speaking of acid...how did you come up with this code? ;P
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

well I read the previous post, couldn't figure out the solution.

so how should it be ? $flnick == [lsearch $firstletter] ?

and I can't see what acid's got to do with the code :P lol
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

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}
B
BlackRaven

Post by BlackRaven »

Ok...just checking here...

I installed the script and it appears to be doing fine...but I want to add a few more features to it.

I just want to check the syntax with those of you who are more familiar with tcl than Myself as this is My first tcl script from scratch

this is the body of the script

Code: Select all

bind join - * lcase:voice

proc lcase:voice {nick uhost hand chan } {
      if {[!botisop $chan]} {return 0}
	    if { stringmatch /[a-z/]* $nick } {
		 pushmode $chan +v $nick
		 }
		 }
is there anything I need to put after that before adding another proc?

and btw...thanks for all the help, without it I'd have been lost

BR
B
BlackRaven

Post by BlackRaven »

ok, it's obvious the script DOES have a syntax error....

HELP!
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

BlackRaven wrote:ok, it's obvious the script DOES have a syntax error....

HELP!
You've got all the right commands in the right order, but the syntax is a bit off :P

Brackets ("[" and "]") are used to perform something called "command substitution", which means everything between the brackets is sort of treated like a separate line and executed with the first word being the command, and any following words become arguments to that command. The result is then passed back and will replace the entire bracket thing.

Eg: set a [blah blah]
First the line is read by the interpreter and the brackets are found, so command substitution is done; a command named "blah" is executed with the string "blah" as an argument and what ever was returned as a result from this command is inserted at the point where the brackets were, so the line becomes 'set a "what ever the command returned"' then 'set' is executed with those arguments. Get the idea?

Then there's that "if" command...to find out everything that is possible inside a if statement, check the manual page for "expr".

The first line in your proc tries to execute a command called "!botisop" (which I doubt exists in your interpreter) I guess you mean if {![botisop $chan]}. botisop returns 1 or 0 (true/false in a if) depending on wether the bot is oped in a channel or not...this integer is then passed to "if" which will execute its body(s) based on the value. (anything > 0 is considered "true", btw)

Your second "if" will fail because of several things...first there's no brackets to ensure command substitution, so the command name and arguments are passed as a single argument to "if" which has a hard time understanding what you mean :P

Then there's your "escaping" of those brackets used in the mask passed to "string match". Slash (/) is not the same as backslash (\), and will not have the desired effect. (...which is avoiding command substitution. - To have the bracket characters passed along to "string match")

Except from these minor glitches your code looks fine :)

Code: Select all

proc lcase:voice {nick uhost hand chan} {
	if {[botisop $chan] && [string match \[a-z\]* $nick]} {
		pushmode $chan +v $nick
	}
}
B
BlackRaven

Post by BlackRaven »

thanks greatly...your advice helped and it works now...

Now one more quick question

actually two

some of the other nicks I want it to voice begin with different brackets...
so I was wondering first...by assigning a variable for the brackets...is the syntax correct for this?

Code: Select all

set collar1 "{"
secondly...when trying to compare it, this is the line I wrote

Code: Select all

proc lcase:voice {nick uhost hand chan} { 
   if {[botisop $chan] &&{ [string index $nick 0] == $collar1 } { 
      pushmode $chan +v $nick 
   } 
}
is this correct?

thanks
BR
Locked