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.

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

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
c
coke
Voice
Posts: 7
Joined: Sat Oct 09, 2010 1:10 pm

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

Post by coke »

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
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

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

Post by willyw »

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: Select all

# 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.
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.
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. :)
c
coke
Voice
Posts: 7
Joined: Sat Oct 09, 2010 1:10 pm

Post by coke »

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

Code: Select all

<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?
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

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

Code: Select all

<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.
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. :)
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? :)


You have this, I believe:

Code: Select all

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: Select all


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?
:)


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.
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

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

Code: Select all

set fp [open $fname "a"] 
to

Code: Select all

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". :) "w" will also create the file if it does not exist.

http://www.astro.princeton.edu/~rhl/Tcl ... pen.n.html
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

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

Code: Select all

set fp [open $fname "a"] 
to

Code: Select all

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". :) "w" will also create the file if it does not exist.

http://www.astro.princeton.edu/~rhl/Tcl ... pen.n.html
Right.
That's why I said:
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.
c
coke
Voice
Posts: 7
Joined: Sat Oct 09, 2010 1:10 pm

Post by coke »

willyw wrote:

Code: Select all


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.
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

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. :)
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.
Post Reply