# Begin - Utility, Anti Idle. (utl_antiidle.tcl)
#	Designed & Written by slennox <slennox@egghelp.org>, © March 1999
#	Modified and re-coded by Ninja_baby (Jaysee@Jaysee.Tv), © January 2001

# This TCL was modified from simple Anti-Idle script by Slennox (aidle.tcl v1.1 - www.ozemail.com.au/~slenny/eggdrop/).
# I add new features and re-code this script in purpose to have better performance and flexibility. Developing stuffs ;)

# This TCL will prevent your bot from idling, I made two types of anti-idle here, 1) Self-PING. 2) Self-Talk.
# You can either choose one of those types, or use both.

# NOTE: absolutely DON'T use both utl_antiidle.tcl and aidle.tcl (or aidle netbots component), coz' both script use the same procs
# and the messages will be on top one another.


# Set this to "1" if you like your bot to PING itself every X minutes. Set to "0" if you don't want the bot to PING itself.
set ai_ping 0

# This is a frequent time. Set this in minute(s). Your bot will PING itself or TALK every X minute, according-
# how many minutes you set in this variable. Careful on setting this, I suggest you set this above "5".
# That's to prevent your bot from lagging coz too much talking or too much PING. ;)
set ai_time 15

# Set this to "1" if you like your bot to talk or msg some channel/itself every X minutes. Leave it to "0"-
# if you don't want your bot to talk.
set ai_pub 1

# Set this as your bot random message. If you set your bot to TALK, you need to set its messages too.
# Set this as many as you wish. ;) Remember that the bot will do random message.
set ai_msgs {
  "Trust Computer System Jl. Muararajeun Baru no. 2 Bdg phone/fax 022-7103422. Sales, Hardware, Software, Maintenance, Web Design & IT Consultant. Gimana ya nasibnya? :("
  "djempol.net Jl. Jatiraya c-15 Banyumanik Semarang, akses cepat & operatornya funky, :P. Tapi masih buka ga ya???"
  "type !start to start the scramble game, or type !gamehelp for help concerning the game."
  "warnet Squid Jl. Suci no. ?? Bandung depan Bank Mandiri, akses cepat & tempat nyaman, tapi dah lama ga buka :("
  "Kornet WebStation Jl. Buah Batu no. 56 Bandung w-net lesehan dengan akses wavelan, siang/malam Rp.3500 :) Tapi dah lama tutup, :P"
}

# Set this as your bot anti-idle target (to whom the bot will talk).
# if it's a channel set to "#channelname". and set to "bot" if you like the bot to msg itself ;)
set ai_targ {
  "#HaLL"
}

# Set this to "1" if you like this script to be automatically loaded when you do .rehash or start the bot.
# Leave it to "0" if you don't like this script to be loaded. Don't worry, this script will automatically shutdown-
# ALL anti-idle timers that currently running. ;)
set ailoaded 1

# This is for your benefit hehe ;), you can either set your own LOGO here, your logo will appear-
# when the bot notice you, or when it makes msgs/notices/kicks or scripts loading. So keep smiling-
# and set this variable as you wish ;), you can either set this to "" to leave it blank.
set utlailg "\[4x]:"

######### Please do not edit anything below unless you know what you are doing ;) #########

proc ai_start {} {
	global ai_time botnick
	foreach aisendtimer [timers] {if {[string match "ai_sendmsg" [lindex $aisendtimer 1]]} {killtimer [lindex $aisendtimer 2]}}
	timer [expr [rand $ai_time] + 1] "ai_sendmsg"
}

proc ai_sendmsg {} {
	global ai_ping ai_pub ai_time ai_msgs ai_targ botnick
	timer [expr [rand $ai_time] + 1] "ai_sendmsg"
	if {$ai_ping} {putquick "PRIVMSG $botnick :\001PING [unixtime]\001"}
	if {$ai_pub} {
		if {$ai_msgs == "" || $ai_targ == ""} {set ai_pub 0 ; return 0}
		set ai_sendto [lindex $ai_targ [rand [llength $ai_targ]]]
		if {[string match "#*" $ai_sendto]} {if {![validchan $ai_sendto]} {return 0}} else {if {[string toupper $ai_sendto] == "BOT"} {set ai_sendto $botnick}}
		putquick "PRIVMSG $ai_sendto :\[4x-advert]: [lindex $ai_msgs [rand [llength $ai_msgs]]]"
	} ; return 0
}

if {[info exist ailoaded]} {
	if {${ailoaded}} {
		ai_start
	} else {
		foreach aisendtimer [timers] {if {[string match "ai_sendmsg" [lindex $aisendtimer 1]]} {killtimer [lindex $aisendtimer 2]}}
	}
	putlog "${utlailg} Utility, Advertisement. Loaded."
}

# End of - Utility, Advertisement & Anti Idle.
