Code: Select all
### GLOBALS ###
set exclude(op) 1
set exclude(halfop) 1
set exclude(voice) 1
set ban(type) 3
set ban(time) 10
set ban(reason) "Ban temporaneo di %BAN minuti"
set notice(msg) "Vietato sostare su %CHAN per più di %IDLE minuti"
### END GLOBALS ###
### FLAGS ###
setudef int max_idle
### END FLAGS###
### BINDS ###
bind time - "* * * * *" idle:check
### END BINDS ###
### PROCS ###
proc idle:check { hour min day month year } {
foreach chan [ channels ] {
idle:scan ${chan}
}
}
proc idle:scan { chan } {
set max [ channel get ${chan} max_idle ]
if { ${max} > 0 } {
foreach nick [ chanlist ${chan} ] {
if { [ isop ${nick} ${chan} ] && $::exclude(op) != 0 } {
continue
}
if { [ ishalfop ${nick} ${chan} ] && $::exclude(halfop) != 0 } {
continue
}
if { [ isvoice ${nick} ${chan} ] && $::exclude(voice) != 0 } {
continue
}
if { [ getchanidle ${nick} ${chan} ] >= ${max} } {
set kickmsg [ var:replace $::ban(reason) "%BAN" "$::ban(time)" ]
set noticemsg [ var:replace [ var:replace $::notice(msg) "%CHAN" "${chan}" ] "%IDLE" "${max}" ]
set mask [ address "${nick}![ getchanhost ${nick} ${chan} ]" $::ban(type) ]
if { [ isop ${nick} ${chan} ] } {
putquick "MODE ${chan} -o+b ${nick} ${mask}"
} elseif { [ ishalfop ${nick} ${chan} ] } {
putquick "MODE ${chan} -h+b ${nick} ${mask}"
} else {
putquick "MODE ${chan} +b ${mask}"
}
if { ${kickmsg} != "" } {
putquick "KICK ${chan} ${nick} :${kickmsg}"
} else {
putquick "KICK ${chan} ${nick} :Ban temporaneo di ${max} minuti"
}
if { ${noticemsg} != "" } {
putquick "NOTICE ${nick} :${noticemsg}"
}
timer $::ban(time) "ban:remove ${chan} ${mask}"
}
}
}
}
proc ban:remove { chan mask } {
putquick "MODE ${chan} -b ${mask}"
}
proc var:replace { line var value } {
regsub -- "$var" $line "$value" line
return $line
}
proc address { mask type } {
set nick [ lindex [ split ${mask} "!" ] 0 ]
set ident [ lindex [ split [ lindex [ split ${mask} "!" ] 1 ] "@" ] 0 ]
set host [ lindex [ split ${mask} "@" ] 1 ]
set domain [ lindex [ split [ maskhost ${mask} ] "@" ] 1 ]
switch -- ${type} {
0 { return "*!${ident}@${host}" }
1 { return "*!*${ident}@${host}" }
2 { return "*!*@${host}" }
3 { return "*!*${ident}@${domain}" }
4 { return "*!*@${domain}" }
5 { return "${nick}!${ident}@${host}" }
6 { return "${nick}!*${ident}@${host}" }
7 { return "${nick}!*@${host}" }
8 { return "${nick}!*${ident}@${domain}" }
9 { return "${nick}!*@${domain}" }
}
}
### END PROCS ###
### INITIAL ###
if { $ban(time) < 1} {
set ban(time) 10
}
if { $ban(type) < 0 || $ban(type) > 9 } {
set ban(type) 2
}