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.

memory issue

Old posts that have not been replied to for several years.
Locked
D
Doos
Voice
Posts: 9
Joined: Thu Jul 07, 2005 11:31 am

memory issue

Post by Doos »

Hi all,

I'm trying to write a small script that reads the nicks in the channel to file.
Which then later will be used on a webpage.

My problem is that when someone does a /part, his/her nick stays in the list. I'm probably missing the obvious in my test script, but could someone give me some pointers.

Thanks.

Code: Select all

bind join - * log_join
bind part - * log_part

proc log_join {nick uhost handle chan} {
  set fd [open "/home/me/whoisonline.txt" w]
  set nicks [chanlist $chan]
  puts $fd [join $nicks]
  close $fd
  return 0
}
proc log_part {nick uhost handle chan msg} {
  set fd [open "/home/me/whoisonline.txt" w]
  set nicks [chanlist $chan]
  puts $fd [join $nicks]
  close $fd
  return 0
}
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

you are missing the fact that PART bind triggers before eggdrop removing nick from [chanlist]

here's how this should be done:

Code: Select all

bind join - * log_join
bind part - * log_part
bind time - ?0* log_save ;# save chanlist every 10 minutes

if {[botonchan #chan]} {set nicks [chanlist #chan]} {set nicks {}}

proc log_join {nick uhost handle chan} {
  if {[lsearch -exact $::nicks $nick] == -1} {
    lappend ::nicks $nick
  }
}
proc log_part {nick uhost handle chan msg} {
  if {[set idx [lsearch -exact $::nicks $nick]] != -1} {
    set ::nicks [lreplace $::nicks $idx $idx]
  }
}
proc log_save {min hour day mon year} {
  set fd [open /home/me/whoisonline.txt w]
  puts $fd [join $::nicks]
  close $fd  
}
D
Doos
Voice
Posts: 9
Joined: Thu Jul 07, 2005 11:31 am

Post by Doos »

Interesting demond,

I'm going to study that.
Just a short question before I dive into Tcl, if I replace ?0* with 01**** .. would that update every minute?

Oh nevermind, I should just get of my lazy ass and read the fabulous manual.

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

Post by Sir_Fz »

01**** (which is the same as 01* btw) will trigger every hour at 01 minutes. If you want to save the list every minute then * should do it.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

of course, you also need to bind to SIGN (that's quit) and KICK - two other events that take out nicks off the channel
D
Doos
Voice
Posts: 9
Joined: Thu Jul 07, 2005 11:31 am

Post by Doos »

Thanks all for the help.
Most of it works now (except the bind kick).

I added a nickchange detector which actually seems to work, don't ask me how.

When the following kick proc gets executed, it deletes the first entry in the list (or the one who does the kick). Anyone has a suggestion?

Code: Select all

bind kick - * log_kick
proc log_kick {nick uhost handle chan kick-nick msg} {
  if {[set idx [lsearch -exact $::nicks $nick]] != -1} {
    set ::nicks [lreplace $::nicks $idx $idx]
  set fd [open /home/me/whoisonline.txt w]
  puts $fd [join $::nicks]
  close $fd
  }
}
D
Doos
Voice
Posts: 9
Joined: Thu Jul 07, 2005 11:31 am

Post by Doos »

Maybe I should explain how I think when I see that code (I'm new to Tcl).

if {[set idx [lsearch -exact $::nicks $nick]] != -1} { ##here you test if the nick is in the $::nick list (an array I presume) and set the result (the nick) in $idx

set ::nicks [lreplace $::nicks $idx $idx] ##here you replace the $idx'ed entry in the array to the same nick in $idx (here is where I get totally lost)

Then write it to file.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

you should use ${kick-nick} instead of $nick.

PS: I suggest you change kick-nick to something else like kn or targ.
D
Doos
Voice
Posts: 9
Joined: Thu Jul 07, 2005 11:31 am

Post by Doos »

Thanks, that did the trick.

Care to explain a bit what happened?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

It's pretty simple if you think about it, $nick is the one who kicked ${kick-nick}, thus $nick is till in the channel while ${kick-nick} is out and should be removed from the list.
D
Doos
Voice
Posts: 9
Joined: Thu Jul 07, 2005 11:31 am

Post by Doos »

Yes that part I understand (I experimented with $kick-nick) , I was actually thinking of what ${kick-nick} does .. is that some sort of reference?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

It's not advisable to use '-' in a variable name, if you used $kick-nick instead of ${kick-nick} then it would've told you "tcl error no such variable kick" (i.e. it's the same as putting $kick). I remember reading about this 2 years ago, maybe it's in the forum I'm not sure.
D
Doos
Voice
Posts: 9
Joined: Thu Jul 07, 2005 11:31 am

Post by Doos »

Ah now I see, it's a quotation without interpolation.
Locked