############################
### RandRead.tcl	 ###
### Version 1.0		 ###
### By Wcc		 ###
### wcc@techmonkeys.org  ###
### http://dawg.dynu.com ###
### EFnet #|DAWG|Tcl     ###
############################

############################################################################
### Copyright © 2000 - 2001 |DAWG| Scripting Group. All rights reserved. ###
############################################################################

##############################################################################
## This script sends a random line from a file to a channel every x seconds. #
##############################################################################

#############################################################
## Just load the script, set the variables, and rehash.    ##
#############################################################

##############################################
# Set the channels to send the line to here. #
##############################################

set randread_setting(chans) "#|DAWG|Net #|DAWG|Tcl"

##################################################
# Set the time in seconds between messages here. #
##################################################

set randread_setting(timer) "90"

#########################################################
# Set the file to read from here. This file must exist. #
# NOTE: Changing the contents of this file requires a   #
# rehash for the changes to take effect.		#
#########################################################

set randread_setting(file) "./scripts/test.txt"

####################
# Code begins here #
####################

if {![string match 1.6.* $version]} {
	putlog "\002RANDREAD:\002 \002CRITICAL ERROR\002 RandRead.tcl requires eggdrop 1.6.x to run."
	die "\002RANDREAD:\002 \002CRITICAL ERROR\002 RandRead.tcl requires eggdrop 1.6.x to run."
}
if {![string match *randread_timeread* [utimers]]} {
	utimer $randread_setting(timer) randread_timeread
}
proc randread_timeread {} {
	global randread_setting randread_line
	set item "[rand [array size randread_line]]"
	if {$item == 0} {
		set item 1
	}
	foreach c $randread_setting(chans) {
		putserv "PRIVMSG $c :$randread_line($item)"
	}
	if {![string match *randread_timeread* [utimers]]} {
		utimer $randread_setting(timer) randread_timeread
	}
}
proc randread_getdata {} {
	global randread_setting randread_line randread_lines
	set fd [open $randread_setting(file) r]
	set lines 0
	while {![eof $fd]} {
		gets $fd line
		incr lines
		set randread_line($lines) $line
	}
}
randread_getdata
putlog "\002RANDREAD:\002 RandRead.tcl Version 1.0 by Wcc is loaded."