I know there are another scripts with that features, but I need this one
Hey, Tommek, are you there?
Code: Select all
# description: Kicks/Bans people who say bad words. Words are stored in a file. Op protect is allowed. You can add/del/list words via priv msg. You don't need to rehash/restart your bot.
# Author: Tomekk
# e-mail: tomekk/@/oswiecim/./eu/./org
# home page: http://tomekk.oswiecim.eu.org/
#
# Version 0.6
#
# This file is Copyrighted under the GNU Public License.
# http://www.gnu.org/copyleft/gpl.html
# default ban type is: *!*ident*@some.domain.com [4]
# fixed: some code fixes
# USE '/msg <botnick> bword' for more information
# sets ban type
# 1) *!*@*.domain.com
# 2) *!*@some.domain.com
# 3) *nick*!*@some.domain.com
# 4) *!*ident*@some.domain.com
set btype 4
# 1 - protect ops, 0 - dont
set protectops "0"
# 1 - enable ban, 0 - disable ban
set want_ban "0"
# wait 'waitb' times before ban
# if you want to ban user after one bad word, set 'waitb' to 0
set waitb "3"
# base directory
set dirname "badwords.db"
# kick message
set msg "bad word!"
# users directory
set usersdir "$dirname/lusers"
# dbase with bad words
set dbase "words_bank.db"
if {[file exists $dirname] == 0} {
file mkdir $dirname
set crtdb [open $dirname/$dbase a+]
puts $crtdb "[censored]\nshit"
close $crtdb
}
if {[file exists $usersdir] == 0} {
file mkdir $usersdir
}
proc create_db { dbname definfo } {
if {[file exists $dbname] == 0} {
set crtdb [open $dbname a+]
puts $crtdb "$definfo"
close $crtdb
}
}
proc readdb { rdb } {
global ident times
set fs_open [open $rdb r]
gets $fs_open dbout
close $fs_open
set separate [split $dbout "&"]
set ident [lindex $separate 0]
set times [lindex $separate 1]
}
proc get_all_bwords { } {
global dirname dbase
set bf [open $dirname/$dbase]
set allwords [read $bf]
close $bf
set bw_split [split $allwords "\n"]
return $bw_split
}
proc add_new_bword { bword } {
global dirname dbase
set bfile_handle [open $dirname/$dbase a]
puts $bfile_handle "$bword"
close $bfile_handle
}
proc delete_bword { dbword {dlall 0}} {
global dirname dbase
set old_bwdb [get_all_bwords]
set file_tow [open $dirname/$dbase w]
if {$dlall == 0} {
foreach chk_bw $old_bwdb {
if {$chk_bw != $dbword} {
if {$chk_bw != ""} {
puts $file_tow $chk_bw
}
}
}
}
close $file_tow
}
proc check_bw_exist { chword } {
set old_chbwdb [get_all_bwords]
set bw_exist 0
foreach check_bword $old_chbwdb {
if {$check_bword == $chword} {
set bw_exist 1
}
}
return $bw_exist
}
bind pubm - * word_fct
bind msgm - "*" bpmsg_fct
proc word_fct { nick uhost hand chan arg } {
global botnick dbase dirname protectops usersdir times ident waitb want_ban msg
set nasty_words [get_all_bwords]
set kill 0
if {[isop $botnick $chan]} {
foreach i [string tolower $nasty_words] {
if {$i != ""} {
if {[string match *$i* [string tolower $arg]]} {
if {$protectops == "0"} {
set kill "1"
} {
if {[isop $nick $chan] == "1"} {
continue
} {
set kill "1"
}
}
}
}
}
if {$kill == "1"} {
if {$want_ban == "1"} {
if {$waitb == 0} {
putquick "MODE $chan +b [banmask $uhost $nick]"
append msg " - banned"
} {
if {[file exists $usersdir/$nick] == 0} {
create_db "$usersdir/$nick" "$uhost&1"
} {
readdb "$usersdir/$nick"
file delete $usersdir/$nick
set overall [expr $times + 1]
create_db "$usersdir/$nick" "$ident&$overall"
readdb "$usersdir/$nick"
if {"$uhost" == "$ident"} {
if {$times >= $waitb} {
putquick "MODE $chan +b [banmask $uhost $nick]"
file delete $usersdir/$nick
append msg " - banned"
}
} {
file delete $usersdir/$nick
create_db "$usersdir/$nick" "$uhost&1"
}
}
}
}
putkick $chan $nick $msg
}
}
}
proc bpmsg_fct { nick uhost hand arg } {
set all_bargs [split $arg]
set bargs_opt1 [lindex $all_bargs 0]
set bargs_opt2 [lindex $all_bargs 1]
set bargs_opt_newords [string tolower [lrange $all_bargs 2 end]]
set bw_list [list]
if {$bargs_opt1 == "bword"} {
if {$bargs_opt2 != ""} {
if {$bargs_opt2 == "add"} {
if {$bargs_opt_newords != ""} {
foreach nbword $bargs_opt_newords {
if {[check_bw_exist $nbword]} {
putquick "PRIVMSG $nick :word $nbword allready exist"
} {
add_new_bword $nbword
putquick "PRIVMSG $nick :word $nbword added"
}
}
} {
putquick "PRIVMSG $nick :use: /msg <botnick> bword add <new_word> ... <new_word>"
}
} elseif {$bargs_opt2 == "list"} {
set list_bwords [get_all_bwords]
if {$list_bwords != ""} {
foreach bw_word $list_bwords {
lappend bw_list "$bw_word"
}
putquick "PRIVMSG $nick :[join $bw_list ", "]"
} else {
putquick "PRIVMSG $nick :db is empty"
}
} elseif {$bargs_opt2 == "del"} {
if {$bargs_opt_newords != ""} {
if {$bargs_opt_newords == "delall"} {
delete_bword 0 1
putquick "PRIVMSG $nick :all words deleted"
} {
foreach dbword $bargs_opt_newords {
if {[check_bw_exist $dbword]} {
delete_bword $dbword
putquick "PRIVMSG $nick :word $dbword deleted"
} {
putquick "PRIVMSG $nick :word $dbword not found"
}
}
}
} {
putquick "PRIVMSG $nick :use: /msg <botnick> bword del <word> ... <word>"
putquick "PRIVMSG $nick :if you want to delete all words use: /msg <botnick> del delall"
}
}
} {
putquick "PRIVMSG $nick :use: /msg <botnick> bword <add|del|list>"
}
}
}
proc banmask {host nick} {
global btype
switch -- $btype {
1 {
set mask "*!*@[lindex [split [maskhost $host] "@"] 1]"
}
2 {
set mask "*!*@[lindex [split $host @] 1]"
}
3 {
set mask "*$nick*!*@[lindex [split $host "@"] 1]"
}
4 {
set mask "*!*[lindex [split $host "@"] 0]*@[lindex [split $host "@"] 1]"
}
return $mask
}
}
putlog "tkbadword.tcl ver 0.6 by Tomekk loaded"