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.

usercount op/voice-count script.

Old posts that have not been replied to for several years.
Locked
e
exz

usercount op/voice-count script.

Post by exz »

hi there.

I am trying to do a script that uses MySQL to insert the values of users/ops/voices/normal from a certain channel. Now i know absolutley nothing about TCL-scripting so i checked out a few scripts that used MySQL and got the MySQL part up and working. I asked in #egghelp @ EFNet for help with the usercount part. Someone gave me this:

Code: Select all

set total [llength [chanlist #adaieski]]
set op [llength [chanlist #adaieski o]]
set voice [llength [chanlist #adaieski v]]
set normal [expr $total - $voice - $op]
In the channel at the time there was 6 users, all opped. But the script returned a bit strange values:

total: 6 (that's right)
op: 1 (um, no, we were 6)
voice: 4 (ehh, no, no voices)
normal: 1 (yeah right)

now there can't be anything wrong with the MySQL code because I do a putcmdlog every time it updates and those values are the same as in the DB..

as i said, i don't know anything about TCL-scripting so if you know the answere please try to explain as much as possible.

and also, sorry about my bad english, I'm from sweden. :)

EDIT:

now the script updated the database again, now i got a little better results (using the same code):

total: 7
ops: 0
voice: 0
normal: 7

now there were 6 ops and 1 normal, still no voices.
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Post by egghead »

docs/tcl-commands.doc wrote: chanlist <channel> [flags[&chanflags]]
Description: flags are any global flags; the '&' denotes to look for channel specific flags. Examples:
n (Global Owner)
&n (Channel Owner)
o&m (Global Op, Channel Master)
[snip]
If you want to count ops and voiced users you can iterate over the list and perform [isop] and [isvoice] checks.
e
exz

Post by exz »

yes, I understand that. but since i don't know TCL-scripting I need someone to do it for me, so this is more like a script request then a question. don't know your policy about that in here though..

you are welcome to suggest any script that is already using this code, if you know any.
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Post by egghead »

Code: Select all

# number of users, operators and voices

set chanusers [chanlist $channel]
set countusers [llength $chanusers]
set operators 0
set voices 0

foreach user $chanusers {
   if { [isop $user $channel] } { incr operators }
   if { [isvoice $user $channel] } { incr voices }
}
Note that users can have @ *and* +v, so simply subtracting the number of @'s and +v's from the total number of users will not work.
e
exz

Post by exz »

yes, I know. I figured out a bit of the code myself. This is how I did it:

Code: Select all

  foreach user [chanlist $chan] {
    if {[isop $user $chan]} { incr op }
    elseif {[isvoice $user $chan]} { incr voice }
    else { incr normal }
  }
However this gives me this error:
[22:57:00] :adaieski: [22:57] Tcl error in script for 'timer36':
[22:57:00] :adaieski: [22:57] invalid command name "elseif"

I have seen elseif been used in several other tcl-scripts and i don't understand why this wouldn't work. :/
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Post by egghead »

exz wrote:[snip]
I have seen elseif been used in several other tcl-scripts and i don't understand why this wouldn't work. :/
The location of the braces with respect to the elseif matters. Try following the example of the other tcl-scripts you have seen.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

Code: Select all

  foreach user [chanlist $chan] {
    if {[isop $user $chan]} {
      incr op
    } elseif {[isvoice $user $chan]} {
      incr voice
    } else { incr normal }
  }
so it should work ^^
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Have you ever read "The Manual"?
e
exz

Post by exz »

Thanks a lot, now it works just fine. :)
Locked