# badnick.tcl, by peldaddy, extended by dre^ # We load bad nicks from a file when the bot starts up. # Also, there are now rudimentary facilities for adding new bad # nicks (bnadd). Using bnadd automatically saves the nick list # to disk. # Run .bnhelp in dcc or telnet console for a full command list #kickmessage set kickMsg "spam sucks" # bind the proc on join catch { unbind join - * BadNick } bind join - * BadNick # bind procs for saving and loading unbind dcc - bnload *dcc:bnload bind dcc - bnload *dcc:bnload unbind dcc - bnsave *dcc:bnsave bind dcc - bnsave *dcc:bnsave # procs for adding and removing nicks unbind dcc - bnadd *dcc:bnadd bind dcc - bnadd *dcc:bnadd unbind dcc - bndel *dcc:bndel bind dcc - bndel *dcc:bndel # procs for debugging and help unbind dcc - bnisbad *dcc:bnisbad bind dcc - bnisbad *dcc:bnisbad unbind dcc - bnhelp *dcc:bnhelp bind dcc - bnhelp *dcc:bnhelp proc *dcc:bnload {handle idx arg} { putlog "badnick: Attempting to load bad nicks from disk..." global BadNicks catch { unset BadNicks } set nickfile [open "scripts/badnicks.txt" r] set count 0 while { [gets $nickfile nick] >= 0 } { incr count set BadNicks($nick) 1 } close $nickfile putlog "badnick: Loaded $count bad nicks from disk!" } proc *dcc:bnsave {handle idx arg} { putidx $idx "Attempting to save bad nicks..." global BadNicks set nickfile [open "scripts/badnicks.txt" w] set count 0 foreach name [array names BadNicks] { # putlog "$name" incr count puts $nickfile "$name" } close $nickfile putidx $idx "Saved $count bad nicks to disk!" } proc *dcc:bndel {handle idx arg} { # putlog "bndel" global BadNicks if { ![catch {unset BadNicks($arg)}] } { putidx $idx "$arg removed" } else { putidx $idx "$arg is not a bad nick" } *dcc:bnsave $handle $idx 1 } proc *dcc:bnadd {handle idx arg} { # putlog "bnadd" global BadNicks set tmpnick [string tolower $arg] if { ![catch {set temper $BadNicks($tempnick)}] } { putidx $idx "$tmpnick was already in the bad nicks list" } else { set BadNicks($tmpnick) 1 putidx $idx "$tmpnick has been added to the bad nick list." } *dcc:bnsave $handle $idx 1 } proc *dcc:bnisbad {handle idx arg} { # putlog "bnisbad" global BadNicks set tmpnick [string tolower $arg] if { ![catch {set foo $BadNicks($tmpnick)}] } { putidx $idx "$tmpnick is bad" } else { putidx $idx "$tmpnick is not bad" } } proc *dcc:bnhelp {handle idx arg} { # putlog "bnhelp" putidx $idx "Command Description Usage" putidx $idx "----------------------------------------------------------------" putidx $idx "bnisbad test a nick for badness bnisbad dre^" putidx $idx "bnadd add new bad nick bnadd spamhead" putidx $idx "bndel remove a bad nick bndel niceman" putidx $idx "bnsave save bad nick file to disk bnsave" putidx $idx "bnload load bad nick file from disk bnload" putidx $idx "bnhelp show command list bnhelp" } proc BadNick {nick uhost hand chan} { global BadNicks global kickMsg catch { unset shortNick } set lowerNick [string tolower $nick] # Derive root nickname from the current nickname (strip digits) # between 3 and 8 lowercase letters followed by two digits # The string of letters is assigned to shortNick regexp {^([a-z]{3,8})[[:digit:]]{2}$} $lowerNick wholeNick shortNick if {[info exists shortNick]} { putlog "badnick: derived $shortNick from $nick" set tempNick $shortNick } else { putlog "badnick: OK => $nick!$uhost" return } #Check for nick match. We now kick based solely on nick. #The catch prevents an error if the value is not in the hash if { ![catch {set temper $BadNicks($tempNick)}] } { putkick $chan $nick $kickMsg putlog "badnick: Kicking => $nick!$uhost (ident ignored)" return } else { putlog "badnick: OK => $nick!$uhost" } } putlog "badnick.tcl loaded, execute .bnhelp for command list" # Load the list of bad nicks from disk *dcc:bnload 1 1 1 # putlog [info tcl]