home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HaCKeRz KrOnIcKLeZ 3
/
HaCKeRz_KrOnIcKLeZ.iso
/
scriptz
/
ads.tcl
< prev
next >
Wrap
Text File
|
1996-04-23
|
3KB
|
89 lines
# ads - tcl script for periodically displaying annoying little messages
#
# by Christian Williams (xian@youth.org)
# set ads(freq) to the number of minutes between ads (0 to disable)
# set ads(file) to the name of the file to use to save ads
# ("ads" is default")
proc ad_rehash {} { global ads
if ![info exists ads(file)] { set ads(file) "ads" }
if ![info exists ads(freq)] { set ads(freq) 0 }
if ![info exists ads(num)] { set ads(num) 0 }
if ![file exists $ads(file)] { close [open $ads(file) w] }
set ads(list) "" ; set theAdFile [open $ads(file) r]
while {![eof $theAdFile]} {
set theAd [gets $theAdFile]
if {[string length $theAd] > 0} {
lappend ads(list) $theAd }
} ; close $theAdFile
}
proc ad_write {} { global ads
set theAdFile [open $ads(file) w]
foreach theAd $ads(list) { puts $theAdFile $theAd }
close $theAdFile
}
proc ad_sched { {name1 ""} {name2 ""} {op ""} } { global ads
if {($ads(freq) == 0) || [info exists ads(started)]} { return 0 }
set ads(started) 1
timer $ads(freq) ad_vertise
}
trace variable ads(freq) w ad_sched
proc ad_vertise {} { global ads channel
if {$ads(freq) == 0} { return 0 }
set theAd [lindex $ads(list) $ads(num)]
if {[string length [string trim $theAd]] > 0} {
putchan $theAd }
incr ads(num) 1 ; if {$ads(num) >= [llength $ads(list)]} { set ads(num) 0 }
unset ads(started) ; ad_sched
}
ad_rehash
ad_sched
proc dcc_ads {hand dcc rest} { global ads botnick
set ad_cmd [string tolower [lindex $rest 0]]
set ad_arg [lrange $rest 1 end]
# if the command is something other than "list" and the user isn't a master,
# display the help.
if {![string match $ad_cmd list] && ![matchattr $hand m]} { set ad_cmd help }
switch $ad_cmd {
list { set adnum 1 ; putdcc $dcc "Ads on $botnick: (* = next up)"
foreach theAd $ads(list) {
if {[expr $ads(num)+1] == $adnum} {set pad "*"} {set pad " "}
putdcc $dcc "$pad$adnum: $theAd" ; incr adnum 1 }
if {$adnum == 1} { putdcc $dcc " None." } ; return 0 }
add { if {[string length $ad_arg]==0} { set showhelp 1 } else {
lappend ads(list) $ad_arg ; ad_write
putdcc $dcc "Added." ; return 1 } }
del { if {[string length $ad_arg]==0 || [catch {incr ad_arg -1}]} {
set showhelp 1 } else {
if {($ad_arg < 0) || ($ad_arg >= [llength $ads(list)])} {
putdcc $dcc "Item is out of range" ; return 0 }
set ads(list) [lreplace $ads(list) $ad_arg $ad_arg] ; ad_write
putdcc $dcc "Deleted." ; return 1 } }
period { set retval 0 ; if {[string length $ad_arg]!=0} {
if [catch {incr ad_arg 0}] { set showhelp 1 } else {
set retval 1 ; set ads(freq) $ad_arg } }
if ![info exists showhelp] {
if {$ads(freq) == 0} {
putdcc $dcc "Advertising turned off. (Period=0)"
} else {
putdcc $dcc "Ads every $ads(freq) minutes." }
return $retval } }
rehash { ad_rehash ; return 1 }
default { set showhelp 1 }
} ; if [info exists showhelp] { dccSimul $dcc "help ads" }
return 0
}
bind dcc - ads dcc_ads
putlog "Advertising stuff loaded."