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 on reading and outputing multiple files

Help for those learning Tcl or writing their own scripts.
Post Reply
S
Shimi
Voice
Posts: 1
Joined: Tue Jan 04, 2011 5:29 am

help on reading and outputing multiple files

Post by Shimi »

Hello,

My friends and I are running an internet radio station and I drew the straw for running our IRC eggdrop bot, so now I am learning how to script in TCL.

We have severl affiliate channels that have requested a script for runnging ads on their channles as well as on our radio channel.

I curently have a script I am working on and belive I have a start but would like some assistance if anyone can help me out.

Since it will be working in multiple channles I curently have it writing indivule files to save the ads for each indivule channle it will display in.

Here is what i got going so far reading one file. How do I get it to read multiple files and list all the contents of the files to the main room (advert(channel1)).

Code: Select all

# file to store adverts in ?
set advert(file1) "room1.advert"
set advert(file2) "room2.advert"
set advert(file3) "room3.advert"
set advert(file4) "room4.advert"

# list of channels to announce adverts in
set advert(channel1) ""
set advert(channel2) ""
set advert(channel3) ""
set advert(channel4) ""

# set number of adverts to show when triggered by timer
set advert(showtimer) 15

# what delay between the adverts in minutes, 0 disables timed announce
set advert(timer1) 0
set advert(timer2) 0
set advert(timer3) 0
set advert(timer4) 0

# what delay in minutes from loading this script till it prints the adverts first time, 0 disables timed announce
set advert(firstrun) 10

# headerstyle
set advert(header) "\0034\002NEWS:\002"

# dateformat (default is: 06 Nov 03:20) http://www.tcl.tk/man/tcl8.4/TclCmd/clock.htm#M6 for help
set advert(dateformat) "%d %b %H:%M"

# linestyle, %time %user and %advert are valid cookies
set advert(line) "\[%time\] %user - %advert"



proc timer:advert { arg } {
        global advert

        set fp [open $advert(file) r]
        set data [split [read $fp] "\n"]
        close $fp

        foreach chan [split $advert(channels)] {
                putserv "PRIVMSG $chan :$advert(header)"
        }

        for { set i [expr [llength $data] - 2] } { $i >= [expr [llength $data] - $arg - 1] } { incr i -1 } {
                if { [lindex $data $i] != "" } {
                        set line [lindex $data $i]
                        set output [string map [list "%time" [clock format [lindex $line 0] -format $advert(dateformat)] "%user" [lindex $line 1] "%advert" [lrange $line 2 end]] $advert(line)]
                        foreach chan [split $advert(channels)] {
                                 putserv "PRIVMSG $chan :$output"
                        }
                }
        }

        timer $advert(timer) { timer:advert $advert(showtimer) }
}

if { ![string match *timer:advert* [utimers]] && ![string match *timer:advert* [timers]] && $advert(firstrun) > 0 && $advert(timer) > 0 } {
        timer $advert(firstrun) { timer:advert $advert(showtimer) }
}

if { ![file isfile $advert(file)] } {
        set fp [open $advert(file) w]
        close $fp
}

also I was wondering if once it reads from the multiple files if there was some way to flood protect it by making it display 3 lines of info then wait 3 minets and display the next 3 lines, ect till all files info has been displayed.

I really need some help on this one and it will be a great learning experance for me.

Thank you very much for any assistance.
Post Reply