egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

A script monitoring irc network status (/map > .txt)

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
coke
Voice


Joined: 09 Oct 2010
Posts: 7

PostPosted: Sat Oct 09, 2010 1:24 pm    Post subject: A script monitoring irc network status (/map > .txt) Reply with quote

Hey,

I need a script that would make the bot send /map command to the ircd (unreal) and then save ircd's replay to a txt file, say every 15 minutes. Nothing else.

If you have any better idea how to monitor network status, don't hesitate to let me know.

Would anybody be kind enough to help me out?
Thanks in advance!

coke
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Mon Oct 11, 2010 12:31 am    Post subject: Re: A script monitoring irc network status (/map > .txt) Reply with quote

coke wrote:


I need a script that would make the bot send /map command to the ircd (unreal) and then save ircd's replay to a txt file, say every 15 minutes.


Code:

# tested on a version 1.6.19 Windrop test bot.   I haven't upgraded any bots to .20 yet.
# Version .20 may have better capability to handle the 15 minute requirement
# I believe this method used below still works on ver .20 though

bind time - "00 * * * *" do:map
bind time - "15 * * * *" do:map
bind time - "30 * * * *" do:map
bind time - "45 * * * *" do:map


#you need to set this -  path and filename
set mapfile "scripts/path/to/your/map_output.txt"



proc do:map {min hour day month year} {

     bind raw -|- 006 mapstuff006
     bind raw -|- 007 mapstuff007

     putserv "map"

     utimer 10 [list unbind raw "-|-" 006 mapstuff006]
     utimer 10 [list unbind raw "-|-" 007 mapstuff007]

     # reference: http://forum.egghelp.org/viewtopic.php?t=6885
     set fname $mapfile
     set fp [open $fname "a"]
     puts $fp [strftime %c]
     close $fp
}



proc mapstuff006 {from key text} {
        set line_to_add "[string trimleft [lrange $text 1 end] :]"
        set fname $mapfile
        set fp [open $fname "a"]
   
        puts $fp $line_to_add
        close $fp
}


proc mapstuff007 {from key text} {
        set line_to_add "[string trimleft [lrange $text 1 end] :]"
        set fname $mapfile
        set fp [open $fname "a"]
        puts $fp $line_to_add
        puts $fp "-----------------"
        close $fp
}



Tested the above, on version Unreal3.2.8.1, and it worked, creating a file containing the results of the /map command.

Quote:

Nothing else.


This is basic, no frills.
Especially note: It runs four times per hour, appending to a text file. That text file will just get bigger, and bigger, and bigger. As it is, it is up to you to go find it occasionally, and delete it.
After observing for a while, if this script does what you want, perhaps we can build in something to help manage that.

Quote:

If you have any better idea how to monitor network status, don't hesitate to let me know.


Since I can't answer this part, I too would be interested to know. Smile
Back to top
View user's profile Send private message
coke
Voice


Joined: 09 Oct 2010
Posts: 7

PostPosted: Mon Oct 11, 2010 6:16 pm    Post subject: Reply with quote

Thank you very much for helping me. I edited set mapfile "map.txt" and I run the script. There were errors:

Code:

<bot> [23:45] Tcl error [do:map]: can't read "mapfile": no such variable
<bot> [23:45] Tcl error [mapstuff006]: can't read "mapfile": no such variable
<bot> [23:45] Tcl error [mapstuff006]: can't read "mapfile": no such variable
<bot> [23:45] Tcl error [mapstuff006]: can't read "mapfile": no such variable
<bot> [23:45] Tcl error [mapstuff007]: can't read "mapfile": no such variable


I compared the script with some other script and added global mapfile to every proc. It seemed to fix it - eggdrop 1.6.19

The script works fine. /map is being saved to a file. That's exactly what i wanted. One more thing. Could the script overwrite mapfile instead of appending to it?
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Mon Oct 11, 2010 7:25 pm    Post subject: Reply with quote

coke wrote:
Thank you very much for helping me. I edited set mapfile "map.txt" and I run the script. There were errors:

Code:

<bot> [23:45] Tcl error [do:map]: can't read "mapfile": no such variable
<bot> [23:45] Tcl error [mapstuff006]: can't read "mapfile": no such variable
<bot> [23:45] Tcl error [mapstuff006]: can't read "mapfile": no such variable
<bot> [23:45] Tcl error [mapstuff006]: can't read "mapfile": no such variable
<bot> [23:45] Tcl error [mapstuff007]: can't read "mapfile": no such variable


I compared the script with some other script and added global mapfile to every proc. It seemed to fix it - eggdrop 1.6.19



da**it !!
as soon as I started to read this, I knew what it was.
You are exactly correct.
(the script originally had the path/filename 'hardcoded', and I remembered to change that, half-way into posting my reply here.
sigh... apparently, I flubbed it, and forgot to edit in the fix.
I apologize.

Quote:

The script works fine. /map is being saved to a file. That's exactly what i wanted.


And I'm very glad that you realized the problem, and got it fixed and working for you. Smile

Quote:

One more thing. Could the script overwrite mapfile instead of appending to it?


As long as you are sure - Yes.
All you'd see, whenever you viewed the file, was the text that is less than 15 minutes old.

Here's the thing:
It's not going to work, with a true "overwrite", when opening the file.
But, we can get the same result, by simply deleting the file, each time before we start to write new info in it, right? Smile


You have this, I believe:
Code:

proc do:map {min hour day month year} {
global mapfile

     bind raw -|- 006 mapstuff006
     bind raw -|- 007 mapstuff007

....


Add to it. Insert some commands, so it looks like this:
Code:


proc do:map {min hour day month year} {
global mapfile

if {[file exists $mapfile]} {
   file delete $mapfile
 }

     bind raw -|- 006 mapstuff006
     bind raw -|- 007 mapstuff007

....


Basically, check to see if the file exists, and if it does, then delete it.

Since this happens before anything that would append to it, each time there is nothing to append to, ... the file is created new.
Does this sound like what you'd like it to do?
Smile


p.s. Above changes are untested. Let us know if it does not perform properly, and if somebody else here doesn't beat me to it, I'll test it and fix it.
Back to top
View user's profile Send private message
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Tue Oct 12, 2010 12:50 am    Post subject: Reply with quote

Just wanted to say that I am pretty sure you can accomplish the same thing by simply changing this:

Code:
set fp [open $fname "a"]

to
Code:
set fp [open $fname "w]"


This basically accomplishes an "overwrite" of the file. In tcl, when you open a file with write permissions, it clears any existing content first. This is why there is "a" for "append" and "w" for "write". Smile "w" will also create the file if it does not exist.

http://www.astro.princeton.edu/~rhl/Tcl-Tk_docs/tcl/open.n.html
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Tue Oct 12, 2010 10:25 am    Post subject: Reply with quote

Luminous wrote:
Just wanted to say that I am pretty sure you can accomplish the same thing by simply changing this:

Code:
set fp [open $fname "a"]

to
Code:
set fp [open $fname "w]"


This basically accomplishes an "overwrite" of the file. In tcl, when you open a file with write permissions, it clears any existing content first. This is why there is "a" for "append" and "w" for "write". Smile "w" will also create the file if it does not exist.

http://www.astro.princeton.edu/~rhl/Tcl-Tk_docs/tcl/open.n.html


Right.
That's why I said:
Quote:

It's not going to work, with a true "overwrite", when opening the file.


Perhaps you missed that.

When I was building it, and first tested it,
bind raw -|- 006 mapstuff006
caused two returns from the server. Thus, the accompanying proc ran twice... and the second time through, it overwrote the results from the first time.
Not good.

It might be easier to see, if you consider that
bind raw -|- 007 mapstuff007
would come along after
bind raw -|- 006 mapstuff006
and its accompanying proc would overwrite everything that came before.
( I didn't get to actually test this far, as I changed it to append before I had it watch for 007)

While 006 is not listed here, 007 is:
http://www.mirc.net/raws/
and 007 looks to be one that would produce a result every time.

I hope this explains it.
Back to top
View user's profile Send private message
coke
Voice


Joined: 09 Oct 2010
Posts: 7

PostPosted: Tue Oct 12, 2010 7:28 pm    Post subject: Reply with quote

willyw wrote:
Code:


if {[file exists $mapfile]} {
   file delete $mapfile
 }




Excellent, now mapfile is being overwritten as requested! Thanks for the update, willyw! It is a fine script.
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Tue Oct 12, 2010 8:08 pm    Post subject: Reply with quote

coke wrote:

...
Excellent, now mapfile is being overwritten as requested! Thanks for the update, willyw! It is a fine script.


Great! and you are welcome. Smile
I'm glad you like it, and that it does what you wanted.

Thanks for taking time to post back. It is good to know.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber