#--------------------------------------------------------------------- # viso.tcl # Tcl script for IRC bot eggdrop # # Reads in a file, makes variable substitutions and writes to # another file. # To get the tcl started, make a template file named "template.html". # An example template is shown at the bottom of this tcl. # # v0: 05-Feb-2003 #--------------------------------------------------------------------- package require eggdrop 1.6.13 package require Tcl 8.0 #--------------------------------------------------------------------- # bindings #--------------------------------------------------------------------- bind time - * time:viso bind dcc - viso dcc:viso #--------------------------------------------------------------------- # for testing purposes #--------------------------------------------------------------------- proc dcc:viso { hand idx text } { proc:viso } #--------------------------------------------------------------------- # Every now and then make the substitutions #--------------------------------------------------------------------- proc time:viso { args } { # check every 7 minutes set secs [clock seconds] set mins [expr round($secs/60.0)] if {[expr $mins % 7] != 0 } { return 0 } proc:viso } #--------------------------------------------------------------------- # On input a file with $::variables, on output a file with the # variables substituted. #--------------------------------------------------------------------- proc proc:viso { } { # define infile and outfile set infile "template.html" set outfile "info.html" # check infile and outfile if { ![file exists $infile] } { putlog "VISO: Error. File \"$infile\" does not exist." return } if { ![file readable $infile] } { putlog "VISO: Error. File \"$infile\" is not readable." return } if { ![file exists $outfile] } { putlog "VISO: Warning. File \"$outfile\" does not exist." } if { ![file writable $outfile] } { putlog "VISO: Warning. File \"$outfile\" is not writeable." return } # make a backup # file copy -force $infile $infile.bk # open the file for reading set infileid [open $infile r] set outfileid [open $outfile w] # read the infile line by line # substitute variable names # write line to outfile while { [gets $infileid line] != -1 } { if { [catch { set line\ [subst -nobackslashes -nocommands $line] } error] != 0 } { putlog "VISO: Warning. Error in line \"$line\": $error." continue } puts $outfileid $line } close $infileid close $outfileid putlog "VISO: task completed." } putlog "Viso var-in-substitute-out version 0 loaded." #--------------------------------------------------------------------- # Sample of an infile. Save this sample starting at "# # # #Info on $::botnick # # #Info on $::botnick on $::network # #