Code: Select all
set default-purgeage 180
#purgebanlist ?-age days? ?&/#channel?
#Checks through the specified banlist and removes any and all older
#bans that have not been in use in the specified number of days.
#Returns: A list of ban-structures, format similar to "banlist".
proc purgebanlist args {
#Initialize local variables
if {[info exists ::default-purgeage]} {
set purgeage ${::default-purgeage}
}
set removed [list]
#Read and interpret parameters
#Only takes -age and optional channelname sofar... guess more might be added further on
for {set i 0} {$i < [llength $args]} {incr i} {
switch -glob -- [lindex $args $i] {
"-age" {
if {[string is integer [lindex $args [incr i]]]} {
set purgeage [lindex $args $i]
} {
error "Age is not an integer: [lindex $args $i]"
}
}
"#*" -
"&*" {
set channel [lindex $args $i]
if {![validchan $channel]} {
error "Invalid channel: $channel"
}
}
default {error "Unknown option: [lindex $args $i]"}
}
}
#Lets make sure we have a sane value to check age against
#If not, just error out since we really don't know how to fix
#it anyway
if {[info exists purgeage] && [string is integer $purgeage]} {
set threshold [expr [clock seconds] - $purgeage * 86400]
} {
error "No valid age-setting was found."
}
#Get the list of bans...
if {[info exists channel]} {
set bans [banlist $channel]
} {
set bans [banlist]
}
#...and start processing them. Save the removed bans for now.
foreach ban $bans {
if {[lindex $ban 3] < $threshold && [lindex $ban 4] < $threshold} {
if {[info exists channel]} {
killchanban $channel [lindex $ban 0]
} {
killban [lindex $ban 0]
}
lappend removed $ban
}
}
#Return the list of removed bans, so the scripter can present this
#in some fancy way with pretty colors *yuck*
return $removed
}
Code: Select all
bind dcc - purgebans dcc:purgebans
proc dcc:purgebans {hand idx text} {
foreach chan [channels] {
foreach ban [purgebanlist $chan] {
putidx $idx "Removed \"[lindex $ban 0]\" from $chan"
}
}
foreach ban [purgebanlist] {
putidx $idx "Removed \"[lindex $ban 0]\" from global banlist"
}
}
And I have the line set default-purgeage 35 set in the script. what will be the outcome?[05:55] <MyBot> [2331] *!*@192.168.1.1 (perm)
[05:55] <MyBot> Larry: Flooders
[05:55] <MyBot> Created 37 days ago, last used 2 days ago