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.

Logging number of users to file

Help for those learning Tcl or writing their own scripts.
Post Reply
D
Doos
Voice
Posts: 9
Joined: Thu Jul 07, 2005 11:31 am

Logging number of users to file

Post by Doos »

Hi all,

I created the following file (with some stolen code). The purpose is to count the number of users in a channel and write that to a file.
It does update the number of people in chat when they join nicely, but not when someone leaves the channel. Could someone comment on it as I'm very poor at TCL.

Code: Select all

set cc_outptpath "/home/doos/"
set cc_outptfile "whoisonline.txt"

# $cc_chanlist
# List of channels to monitor (ommit #)
set cc_chanlist {go}

bind join - * cc_join
bind part - * cc_part
bind sign - * cc_sign
bind kick - * cc_kick
bind splt - * cc_split

proc cc_countusers {chan} {
  global cc_outptfile cc_outptpath

set totalusers [llength [chanlist #go]]

  set c [catch {set fd [open "$cc_outptpath$chan.$cc_outptfile" w]} reason]

puts $fd $totalusers

  catch {close $fd}
  return 0
}

proc cc_join {nick uhost handle chan} {
  regsub -all "\#" $chan "" chan
  global cc_chanlist
  if {[lsearch $cc_chanlist $chan] != -1} {cc_countusers $chan}

#puthelp "PRIVMSG #go :Doos is an idiot."

  return 0
}
proc cc_part {nick uhost handle chan msg} {
  regsub -all "\#" $chan "" chan
  global cc_chanlist
  if {[lsearch $cc_chanlist $chan] != -1} {cc_countusers $chan}


  return 0
}

proc cc_sign {nick uhost handle chan msg} {
  regsub -all "\#" $chan "" chan

  global cc_chanlist
  if {[lsearch $cc_chanlist $chan] != -1} {cc_countusers $chan}

  return 0
}

proc cc_kick {nick uhost handle chan msg} {
  regsub -all "\#" $chan "" chan

  global cc_chanlist
  if {[lsearch $cc_chanlist $chan] != -1} {cc_countusers $chan}


  return 0
}

proc cc_split {nick uhost handle chan msg} {
  regsub -all "\#" $chan "" chan

  global cc_chanlist
  if {[lsearch $cc_chanlist $chan] != -1} {cc_countusers $chan}

  return 0
}

# Check for a QUIT
proc hung_up {nick uhost handle chan msg} {
  regsub -all "\#" $chan "" chan

  global cc_chanlist
  if {[lsearch $cc_chanlist $chan] != -1} {cc_countusers $chan}

  return 0
}

putlog "\002WHOSONLINE:\002 countlist.tcl Version1 is loaded."
Thanks in advance.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

This is because when part is triggered, the user is still on the channel. just give your proc a hint if it was a part and then expr -1 the totalusers.
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...
Post Reply