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.
Help for those learning Tcl or writing their own scripts.
tessa1
Halfop
Posts: 49 Joined: Mon Apr 18, 2005 12:51 pm
Location: Germany
Post
by tessa1 » Sun Sep 22, 2013 12:18 am
Hi
I want to write the stats data of all 6 servers into a file.
e.g:
server1.irc.net:1268
server2.irc.net:724
server3.irc.net:954
...
But my script writes only the last server number six into the file. What can I do?
Here is my script:
Code: Select all
bind pub - !uptime stats:cmd:uptime
proc stats:cmd:uptime {nick uhost handle channel text} {
global server_stats
putserv "STATS u server1.irc.net"
putserv "STATS u server2.irc.net"
putserv "STATS u server3.irc.net"
putserv "STATS u server4.irc.net"
putserv "STATS u server5.irc.net"
putserv "STATS u server6.irc.net"
}
bind raw - 242 stats:raw:242
proc stats:raw:242 {from keyword text} {
global server_stats
set server_stats(text) "$from:[lindex [split [lrange $text 3 end] " "] 0]"
set fd [open "uptimefile" w+]
puts $fd $server_stats(text)
close $fd
}
unset -nocomplain server_stats(text)
Thank you for help
Last edited by
tessa1 on Sun Sep 22, 2013 2:12 pm, edited 1 time in total.
SpiKe^^
Owner
Posts: 831 Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:
Post
by SpiKe^^ » Sun Sep 22, 2013 9:58 am
tessa1
Halfop
Posts: 49 Joined: Mon Apr 18, 2005 12:51 pm
Location: Germany
Post
by tessa1 » Sun Sep 22, 2013 11:52 am
Spike, yes! I know that. But "a" doesn't overwrite the file like "w"
It adds a new line to this file. I need this file to read it out with php and publish it on our homepage.
willyw
Revered One
Posts: 1203 Joined: Thu Jan 15, 2009 12:55 am
Post
by willyw » Sun Sep 22, 2013 12:13 pm
We know what happens if you use +w. You get only the last one saved to the file. That's because +w is re-writing the file.
Spike's solution does cure that. However it creates a never ending file.
With your latest clarification, it sounds like you want both - a new file every time, that contains all six lines.
Would the solution be:
Do what Spike said, AND add a new line to your script.... one that deletes the old file, first?
Reference:
http://www.tcl.tk/man/tcl8.5/TclCmd/file.htm#M12
Code: Select all
proc stats:raw:242 {from keyword text} {
global server_stats
file delete uptimefile
.... rest of your script text here .....
Something like that, anyway...
I hope this helps.
tessa1
Halfop
Posts: 49 Joined: Mon Apr 18, 2005 12:51 pm
Location: Germany
Post
by tessa1 » Sun Sep 22, 2013 12:36 pm
Ok, this is my script now.
There are no errors in the partyline.
But the script writes only the last server.
I rehashed an restarted the Bot.
Without deleting the file, the script writes all lines.
Code: Select all
bind pub - !uptime stats:cmd:uptime
proc stats:cmd:uptime {nick uhost handle channel text} {
global server_stats
putserv "STATS u server1.irc.net"
putserv "STATS u server2.irc.net"
putserv "STATS u server3.irc.net"
putserv "STATS u server4.irc.net"
putserv "STATS u server5.irc.net"
putserv "STATS u server6.irc.net"
}
bind raw - 242 stats:raw:242
proc stats:raw:242 {from keyword text} {
global server_stats
file delete uptimefile
set server_stats(text) "$from:[lindex [split [lrange $text 3 end] " "] 0]"
set fd [open "uptimefile" a]
puts $fd $server_stats(text)
close $fd
}
unset -nocomplain server_stats(text)
willyw
Revered One
Posts: 1203 Joined: Thu Jan 15, 2009 12:55 am
Post
by willyw » Sun Sep 22, 2013 12:56 pm
Every time proc stats:raw:242 is triggered by the raw bind, the file is being deleted.
Thus, only the last one is being saved.
See what I mean?
My mistake. Sorry.
Try moving this line:
file delete uptimefile
from where it is currently, to before the first putserv line in
proc stats:cmd:uptime
That way, the file will only be deleted once - when you issue the
!uptime
command. Let's hope this solves it.
tessa1
Halfop
Posts: 49 Joined: Mon Apr 18, 2005 12:51 pm
Location: Germany
Post
by tessa1 » Sun Sep 22, 2013 1:13 pm
Yes! Thats it!
Many thanks