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 

help on reading and outputing multiple files

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Shimi
Voice


Joined: 04 Jan 2011
Posts: 1

PostPosted: Tue Jan 04, 2011 6:31 am    Post subject: help on reading and outputing multiple files Reply with quote

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:

# 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.
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 -> Scripting Help 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