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.
Old posts that have not been replied to for several years.
Doos
Voice
Posts: 9 Joined: Thu Jul 07, 2005 11:31 am
Post
by Doos » Fri Jul 08, 2005 7:12 am
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
}
demond
Revered One
Posts: 3073 Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:
Post
by demond » Fri Jul 08, 2005 2:48 pm
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
}
Doos
Voice
Posts: 9 Joined: Thu Jul 07, 2005 11:31 am
Post
by Doos » Fri Jul 08, 2005 3:37 pm
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
Sir_Fz
Revered One
Posts: 3794 Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:
Post
by Sir_Fz » Fri Jul 08, 2005 8:11 pm
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.
demond
Revered One
Posts: 3073 Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:
Post
by demond » Fri Jul 08, 2005 9:05 pm
of course, you also need to bind to SIGN (that's quit) and KICK - two other events that take out nicks off the channel
Doos
Voice
Posts: 9 Joined: Thu Jul 07, 2005 11:31 am
Post
by Doos » Sun Jul 10, 2005 6:32 am
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
}
}
Doos
Voice
Posts: 9 Joined: Thu Jul 07, 2005 11:31 am
Post
by Doos » Sun Jul 10, 2005 6:50 am
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.
Sir_Fz
Revered One
Posts: 3794 Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:
Post
by Sir_Fz » Sun Jul 10, 2005 10:37 am
you should use ${kick-nick} instead of $nick.
PS: I suggest you change kick-nick to something else like kn or targ.
Doos
Voice
Posts: 9 Joined: Thu Jul 07, 2005 11:31 am
Post
by Doos » Sun Jul 10, 2005 11:19 am
Thanks, that did the trick.
Care to explain a bit what happened?
Sir_Fz
Revered One
Posts: 3794 Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:
Post
by Sir_Fz » Sun Jul 10, 2005 11:27 am
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.
Doos
Voice
Posts: 9 Joined: Thu Jul 07, 2005 11:31 am
Post
by Doos » Sun Jul 10, 2005 11:59 am
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?
Sir_Fz
Revered One
Posts: 3794 Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:
Post
by Sir_Fz » Sun Jul 10, 2005 8:03 pm
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.
Doos
Voice
Posts: 9 Joined: Thu Jul 07, 2005 11:31 am
Post
by Doos » Mon Jul 11, 2005 6:42 am
Ah now I see, it's a quotation without interpolation.