#Dekadent Counter v1.0 by CoolMaster for eggdrop
#
######## INFO(it's important to read this and configuration) ########
#This Dekadent TCL Script is a simple join/kick counter for eggdrop channels.
#You can enable or disable some options, can reset stats and... take a look at configuration section
#Don't forget you need to have +rw permissions on files.
#I test this script in eggdrop 1.6.3 (yes i know i need to upgrade it:P)
#
#One more script to improve/learn my TCL for eggdrop abilities. I did not test this script a lot so
#if you find any bug please report it to me.
#
#Send your comments/flamez/sugestions to coolmaster@GameOver.co.pt or in Dcounter WebSite <http://coolmaster.cjb.net>
#You can visit me on irc.PTlink.net then #PST (http://scripters.ptlink.net)
#
#This Script is distributed under the TERMS of GNU General Public Licence(GPL) if you don't have
#the terms of GPL please go to http://www.bubix.net/~coolmaster/GPL.txt
#
#I'm not inspired today to tell you some history, so if you want to know what "d" means download the Dxtra TCL.
#First TCL Script of this year.
#
#ChangeLog
# *Version 1.0 - 02/01/2002*
# FIRST PUBLIC RELEASE
#
################### CONFIGURATION (recommend to read all) #########################
#[0/1] set this to 1 if you want to send an advertise notice(saying the number) when nick joins channel.
set dcounter(njoin) 1
#[0/1] set this to 1 if you want to send an advertise notice(saying the number) when nick gets kicked from channel.
set dcounter(nkick) 1
#[0/1] set this to 1 if you want to send a notice to channel operators(onotice) warning the number of kicks when
#someone gets kicked from channel.
set dcounter(nonotice) 0
#set here the file to stores/saves number of joins
set dcounter(joinfile) "dcjoin.dat"
#set here the file to stores/saves number of kicks
set dcounter(kickfile) "dckick.dat"
#set here the tmp file
set dcounter(tmpfile) "dcounter.tmp"
#set here the trigger(to dcc chat) to reset the counter to one channel to 0(for +m).--> trigger <#channel|all>
set dcounter(reset) "dcreset"
#set the trigger(to channel msgs) to see the statics of a channel --> trigger
set dcounter(see) "!dstats"
#set here the channels that you don't want to save information, separated by commands(,)
set dcounter(non-channels) "#Bots,#Lamer"
############# Don't change nothing below if you don't know what you are doing ###############
## BINDS ##
bind join - * dcounter_join
bind kick - * dcounter_kick
bind pub - $dcounter(see) dcounter_see
bind dcc m $dcounter(reset) dcounter_reset
## Misc ##
if {$dcounter(non-channels) != ""} {set dcounter(non-channels) "[string tolower $dcounter(non-channels)]"}
if {[string compare $dcounter(joinfile) $dcounter(kickfile)] == 0} {die "Dekadent Counter, you probably have the same name to other types of file, please edit your Dekadent Counter"}
if {[string compare $dcounter(joinfile) $dcounter(tmpfile)] == 0} {die "Dekadent Counter, you probably have the same name to other types of file, please edit your Dekadent Counter"}
if {[string compare $dcounter(tmpfile) $dcounter(kickfile)] == 0} {die "Dekadent Counter, you probably have the same name to other types of file, please edit your Dekadent Counter"}
if {![file exists $dcounter(joinfile)]} {set fxtmp [open $dcounter(joinfile) w] ; close $fxtmp}
if {![file exists $dcounter(kickfile)]} {set fxtmp [open $dcounter(kickfile) w] ; close $fxtmp}
putlog "Dekadent Counter v1.0 by CoolMaster <coolmaster@GameOver.co.pt> loaded"
## Procs ##
# Verify if channel is not on exempt list, if is return 1 else return 2 (proc from Dekadent learn by me)
proc isvalidchan {chan} {
global dcounter
set chans [string tolower [split "$dcounter(non-channels)" ","]]
set i 0
while {1} {
set chan_c [lindex $chans $i]
if {$chan_c == ""} {return 2} elseif {$chan_c == "$chan"} {return 1}
incr i 1
}
}
proc dcounter_join {nick host hand chan} {
global dcounter
set chan [string tolower $chan] ; set counter 0
if {[isvalidchan $chan] == 1} {return 0}
set fx [open $dcounter(joinfile) r] ; set fx2 [open $dcounter(tmpfile) w]
while {![eof $fx]} {
set tmp [gets $fx]
if {$tmp != ""} {
if {[lindex $tmp 0] == "$chan"} {set counter [expr [lindex $tmp 1] +1] ; puts $fx2 "$chan $counter"} else {puts $fx2 $tmp}
}
}
if {$counter == 0} {set counter 1 ; puts $fx2 "$chan $counter"}
close $fx ; close $fx2
exec rm -f $dcounter(joinfile) ; exec mv $dcounter(tmpfile) $dcounter(joinfile)
if {$dcounter(njoin) == 1} {puthelp "NOTICE $nick :You're the $counter person to join $chan"}
return 0
}
proc dcounter_kick {nick host hand chan target reason} {
global dcounter
set chan [string tolower $chan] ; set counter 0
if {[isvalidchan $chan] == 1} {return 0}
set fx [open $dcounter(kickfile) r] ; set fx2 [open $dcounter(tmpfile) w]
while {![eof $fx]} {
set tmp [gets $fx]
if {$tmp != ""} {
if {[lindex $tmp 0] == "$chan"} {set counter [expr [lindex $tmp 1] +1] ; puts $fx2 "$chan $counter"} else {puts $fx2 $tmp}
}
}
if {$counter == 0} {set counter 1 ; puts $fx2 "$chan $counter"}
close $fx ; close $fx2
exec rm -f $dcounter(kickfile) ; exec mv $dcounter(tmpfile) $dcounter(kickfile)
if {$dcounter(nkick) == 1} {puthelp "NOTICE $target :You're the $counter person kicked from $chan"}
if {$dcounter(nonotice) == 1} {puthelp "NOTICE @$chan :$target was the $counter person kicked from $chan"}
return 0
}
proc dcounter_see {nick host hand chan text} {
global dcounter
set chan [string tolower $chan] ; set joins 0 ; set kicks 0
if {[isvalidchan $chan] == 1} {puthelp "NOTICE $nick :I don't save join/kick stats for this channel" ; return 0}
set fx1 [open $dcounter(joinfile) r] ; set fx2 [open $dcounter(kickfile) r]
while {![eof $fx1]} {
set tmp [gets $fx1]
if {$chan == "[lindex $tmp 0]"} {set joins [lindex $tmp 1] ; break}
}
while {![eof $fx2]} {
set tmp [gets $fx2]
if {$chan == "[lindex $tmp 0]"} {set kicks [lindex $tmp 1] ; break}
}
puthelp "NOTICE $nick :$chan have $joins joins and $kicks kicks"
return 0
}
proc dcounter_reset {hand idx arg} {
global dcounter
set arg [string tolower [lindex $arg 0]]
if {$arg == ""} {putidx $idx "Invalid syntax, $dcounter(reset) <#channel|all>" ; return 0}
if {[isvalidchan $arg] == 1 && $arg != "all"} {putidx $idx "I don't save join/kick stats for that channel" ; return 0}
if {$arg == "all"} {putidx $idx "Reseting all data from all counter stats" ; putlog "#$hand# reset all counter stats" ; set fxtmp [open $dcounter(joinfile) w] ; close $fxtmp ; set fxtmp [open $dcounter(kickfile) w] ; close $fxtmp ; return 0}
set fx1 [open $dcounter(joinfile) r] ; set fx2 [open $dcounter(kickfile) r] ; set fx3 [open $dcounter(tmpfile) w]
while {![eof $fx1]} {
set tmp [gets $fx1]
if {$arg == "[lindex $tmp 0]"} {continue}
puts $fx3 $tmp
}
close $fx3
exec rm -f $dcounter(joinfile) ; exec mv $dcounter(tmpfile) $dcounter(joinfile)
set fx3 [open $dcounter(tmpfile) w]
while {![eof $fx2]} {
set tmp [gets $fx2]
if {$arg == "[lindex $tmp 0]"} {continue}
puts $fx3 $tmp
}
close $fx1 ; close $fx2 ; close $fx3
exec rm -f $dcounter(kickfile) ; exec mv $dcounter(tmpfile) $dcounter(kickfile)
putidx $idx "Reseting all data from $arg counter stats" ; putlog "#$hand# reset $arg counter stats"
}