egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Tomekk's badwords script
Goto page 1, 2  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
Torrevado
Op


Joined: 02 Aug 2006
Posts: 101

PostPosted: Sat Dec 20, 2008 2:26 pm    Post subject: Tomekk's badwords script Reply with quote

Hi, would be possible to add "X" warnings before kicking? and setting up how much time the bot will remember the offences? and ban time duration?

I know there are another scripts with that features, but I need this one Razz

Hey, Tommek, are you there? Cool

Code:
# 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"
Back to top
View user's profile Send private message
tomekk
Master


Joined: 28 Nov 2008
Posts: 255
Location: Oswiecim / Poland

PostPosted: Sat Dec 20, 2008 5:40 pm    Post subject: Reply with quote

new version:

Code:
# 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. You can define ban duration time etc. Script is very simple to use

# Author: tomekk
# e-mail:  tomekk/@/oswiecim/./eu/./org
# home page: http://tomekk.oswiecim.eu.org/
#
# Version 0.7
#
# 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]

# added: ban duration time, "offence" duration time (a time between one bad word and 2nd)
# 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 1

# wait 'waitb' times before ban
# if you want to ban user after one bad word, set 'waitb' to 0
set waitb 3

# 'waitb' info type
# 1 - kick after bad word and ban after 'waitb' times
# 2 - write message after bad word to the nick, 'nick: message' and ban after 'waitb' times
# 3 - do nothing, just ban after 'waitb' times
set waitb_type 3

# if u set 'waitb' type 2, then here is a option to set this message
set waitb_message "watch your language kid !"

# ban duration time (minutes)
# 0 - infinite
set ban_duration 0

# "offence" duration time, how long bot should remember last bad word time (minutes)
# 0 - infinite
set offence_duration 0

# kick message
set kmsg "bad word! - kick"

# ban message
set bmsg "banned!"

# base directory
set dirname "badwords.db"

# users directory
set usersdir "$dirname/lusers"

# banned hosts file
set banned_hosts "$dirname/bndhosts"

# dbase with bad words
set dbase "$dirname/words_bank.db"

##################################################################
if {[file exists $dirname] == 0} {
   file mkdir $dirname
   set crtdb [open $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 } {
   set fs_open [open $rdb r]
   gets $fs_open dbout
   close $fs_open

   return $dbout
}

proc get_all_bwords { } {
   global dbase

   set bf [open $dbase r]
   set allwords [read $bf]
   close $bf

   set bw_split [split $allwords "\n"]
        return $bw_split
}

proc add_new_bword { bword } {
   global dbase

   set bfile_handle [open $dbase a]
   puts $bfile_handle "$bword"
   close $bfile_handle
}

proc add_new_bnd_host { new_host  } {
   global banned_hosts

   set bnd_hosts [open $banned_hosts a]
   puts $bnd_hosts $new_host
   close $bnd_hosts
}

proc delete_bword { dbword {dlall 0}} {
   global dbase

   set old_bwdb [get_all_bwords]
   
   set file_tow [open $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
}

proc ban_checker_timer { } {
   ban_checker

   if {[string match *ban_checker_timer* [utimers]] != 1} {
      utimer 20 ban_checker_timer
   }
}

bind pubm - * word_fct
bind msgm - "*" bpmsg_fct

proc word_fct { nick uhost hand chan arg } {
     global botnick protectops usersdir waitb waitb_type waitb_message want_ban kmsg bmsg offence_duration ban_duration

   set nasty_words [get_all_bwords]

   set kill 0

   set ban_status 0

   set msg $kmsg

   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} {
            set time_in_seconds [clock seconds]
            set user_ban_mask [banmask $uhost $nick]

            if {$waitb == 0} {
               putquick "MODE $chan +b $user_ban_mask"

               if {$ban_duration > 0}  {
                  add_new_bnd_host "$chan&$user_ban_mask&$time_in_seconds"
               }

               set msg $bmsg

               putkick $chan $nick $msg

               set ban_status 1
            } {
               if {[file exists $usersdir/$nick] == 0} {
                  create_db "$usersdir/$nick" "$uhost&1&$time_in_seconds"
               } {
                  set each_user_data [split [readdb "$usersdir/$nick"] "&"]
                  set ident [lindex $each_user_data 0]
                  set times [lindex $each_user_data 1]
                  set first_time [lindex $each_user_data 2]

                  if {([expr $time_in_seconds - $first_time] >= [expr $offence_duration * 60]) && ($offence_duration > 0)} {
                     file delete $usersdir/$nick
                     create_db "$usersdir/$nick" "$uhost&1&$time_in_seconds"
                  } {
                     file delete $usersdir/$nick

                     set overall [expr $times + 1]

                     create_db "$usersdir/$nick" "$ident&$overall&$first_time"
                     set ident [lindex [split [readdb "$usersdir/$nick"] "&"] 0]

                     if {$uhost == $ident} {            
                        if {$overall >= $waitb} {
                           putquick "MODE $chan +b $user_ban_mask"

                           if {$ban_duration > 0} {
                              add_new_bnd_host "$chan&$user_ban_mask&$time_in_seconds"
                           }

                           file delete $usersdir/$nick
                           set msg $bmsg

                           putkick $chan $nick $msg

                           set ban_status 1
                        }
                     } {
                        file delete $usersdir/$nick
                        create_db "$usersdir/$nick" "$uhost&1"
                     }
                  }   
               }
            }
         }

         if {($ban_status == 0) && ($waitb_type < 3)} {
            if {$waitb_type == 1} {
               putkick $chan $nick $msg
            } {
               putquick "PRIVMSG $chan :$nick: $waitb_message"
            }
         }
      }
   }
}

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 exists"
                  } {
                     add_new_bword $nbword
                     putquick "PRIVMSG $nick :word $nbword has been 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 have been deleted"
               } {
                  foreach dbword $bargs_opt_newords {
                     if {[check_bw_exist $dbword]} {
                        delete_bword $dbword
                        putquick "PRIVMSG $nick :word $dbword have been 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
       }
}

proc ban_checker { } {
   global banned_hosts ban_duration

   if {([file exists $banned_hosts]) && ($ban_duration > 0)} {
      set hosts_hand [open $banned_hosts r]
      set give_me_hosts [read $hosts_hand]
      close $hosts_hand

      set time_in_seconds [clock seconds]

      set rewrite_hosts_hand [open $banned_hosts w]
      foreach banned_h [split $give_me_hosts "\n"] {
         if {$banned_h != ""} {
            set split_banned_h [split $banned_h "&"]
            set host_ban_chan [lindex $split_banned_h 0]
            set host_ban_mask [lindex $split_banned_h 1]
            set need_ban_time [lindex $split_banned_h 2]
   
            if {[expr $time_in_seconds - $need_ban_time] >= [expr $ban_duration * 60]} {
               putquick "MODE $host_ban_chan -b $host_ban_mask"
            } {
               puts $rewrite_hosts_hand "$host_ban_chan&$host_ban_mask&$need_ban_time"
            }
         }
      }
      close $rewrite_hosts_hand
   }
}

if {[string match *ban_checker_timer* [utimers]] != 1} {
           utimer 20 ban_checker_timer
}

putlog "tkbadword.tcl ver 0.7 by tomekk loaded"



added:
- ban duration (script checks every 20 sec file with banned hosts and their chans)
- "offence" duration
- now, you can choose an action for "bad word" , kick, message or nothing

I think message after X kicks is kinda weird,
for example: 3 messages and 1 kick, 3 kick and ban = 3 * 3 = 9 before bot will ban Smile

You can type just message and after X messages will be ban Smile

try this ver :>


Last edited by tomekk on Fri Jan 02, 2009 5:35 am; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
Torrevado
Op


Joined: 02 Aug 2006
Posts: 101

PostPosted: Sat Dec 20, 2008 7:53 pm    Post subject: Reply with quote

It's perfect, thank you very much Tomekk Smile
Back to top
View user's profile Send private message
Torrevado
Op


Joined: 02 Aug 2006
Posts: 101

PostPosted: Tue Dec 23, 2008 8:30 am    Post subject: Reply with quote

Tommek, I have a problem.
When I set ban type 2, the script removes perfectly the ban in file with banned hosts, but not in chans...
It seems to work fine with the other 3 ban types.
Back to top
View user's profile Send private message
tomekk
Master


Joined: 28 Nov 2008
Posts: 255
Location: Oswiecim / Poland

PostPosted: Tue Dec 23, 2008 8:51 am    Post subject: Reply with quote

Torrevado wrote:
Tommek, I have a problem.
When I set ban type 2, the script removes perfectly the ban in file with banned hosts, but not in chans...
It seems to work fine with the other 3 ban types.


ban type 2, 1 minute:
Quote:
13:45:51 < rambo> bad
13:45:51 < rambo> bad
13:45:53 < rambo> bad
13:45:54 -!- mode/#chan [+b *!*@bux184.internetdsl.tpnet.pl] by botty
13:45:54 -!- rambo was kicked from #chan by botty [banned!]
13:46:58 -!- mode/#chan [-b *!*@bux184.internetdsl.tpnet.pl] by botty


hmm, any special chars in chann name or smth, or some wierd host?
Back to top
View user's profile Send private message Visit poster's website
Torrevado
Op


Joined: 02 Aug 2006
Posts: 101

PostPosted: Tue Dec 23, 2008 3:57 pm    Post subject: Reply with quote

I think it could be a shell's problem (they're upgrading freeBSD) or maybe the script is chocking with another one...
Sometimes it works (for me) but sometimes it doesn't...

There are no special chars in channel name or host Smile
Back to top
View user's profile Send private message
tomekk
Master


Joined: 28 Nov 2008
Posts: 255
Location: Oswiecim / Poland

PostPosted: Sun Dec 28, 2008 8:48 am    Post subject: Reply with quote

hmm, maybe its to fast, try to change:
Code:
putquick "MODE $host_ban_chan -b $host_ban_mask"


to:
Code:
putserv "MODE $host_ban_chan -b $host_ban_mask"
Back to top
View user's profile Send private message Visit poster's website
Torrevado
Op


Joined: 02 Aug 2006
Posts: 101

PostPosted: Tue Dec 30, 2008 12:43 pm    Post subject: Reply with quote

Both putquick and putserv works in the same way.
I noticed the script works better in short bans (1-2 mins) but (in my case) it doesn't work with, for example, a 5 minutes ban.

Thanks anyway, tomekk
Back to top
View user's profile Send private message
tomekk
Master


Joined: 28 Nov 2008
Posts: 255
Location: Oswiecim / Poland

PostPosted: Tue Dec 30, 2008 3:02 pm    Post subject: Reply with quote

Torrevado wrote:
Both putquick and putserv works in the same way.
I noticed the script works better in short bans (1-2 mins) but (in my case) it doesn't work with, for example, a 5 minutes ban.

Thanks anyway, tomekk


hmm, hard to say
I just tested it with 7-10 minutes, with diffrent ban masks, with many hosts and all is working good

Try to add before "putquick "MODE $host_ban_chan -b $host_ban_mask"" in ban_checker proc:
Code:
putquick "PRIVMSG #chan :test"


Replace #chan with your chan name, then run script with ban (5 and more minutes), add some ban and wait.

We will see if bot will print "test" or no.

Are you using this script on one channel or multiple chans?
Back to top
View user's profile Send private message Visit poster's website
Torrevado
Op


Joined: 02 Aug 2006
Posts: 101

PostPosted: Tue Dec 30, 2008 4:41 pm    Post subject: Reply with quote

First of all, thanks for your patience, tomekk Smile

I tried that test message and the problem was still there (some times it worked and sometimes it didn't). So, I re-compiled my egg several times, but nothing to do. I decided to delete all my bot folders and start a new eggdrop install. Now it works like a charm, always, for all type of bans and for any ban time selected (even +5 minutes) Smile

Anyway, I changed every "putquick" in the script for "putserv" to let my egg have a restful life (he's getting old Razz ).

I use your script only for one chan, but my bot is opped on more channels, so I added the line "if {[lsearch {#mychannelname} $chan] == -1} return" to proc word_fct.
Code:
proc word_fct { nick uhost hand chan arg } {
if {[lsearch {#mychannelname} $chan] == -1} return
     global botnick protectops usersdir waitb waitb_type waitb_message want_ban kmsg bmsg offence_duration ban_duration


Thanks for all, if I had any problem, I'll disturb you again Laughing
Back to top
View user's profile Send private message
tomekk
Master


Joined: 28 Nov 2008
Posts: 255
Location: Oswiecim / Poland

PostPosted: Tue Dec 30, 2008 7:04 pm    Post subject: Reply with quote

yeap no problem, anyway thanks for beta tests Smile

Hpy Nw Yr
regards
Back to top
View user's profile Send private message Visit poster's website
demonoid
Voice


Joined: 19 Jan 2009
Posts: 2

PostPosted: Mon Jan 19, 2009 12:32 pm    Post subject: Reply with quote

Hi tomekk, I would know if all users on channel can add/delete the bwords with command /msg bot bword add/del word. If yes it's possible change this command (change "bword" with a myrandom code), for prevently abusing? Thanks you.
Back to top
View user's profile Send private message
tomekk
Master


Joined: 28 Nov 2008
Posts: 255
Location: Oswiecim / Poland

PostPosted: Tue Jan 20, 2009 7:31 am    Post subject: Reply with quote

sure, go on Smile
Back to top
View user's profile Send private message Visit poster's website
pen
Voice


Joined: 23 Apr 2009
Posts: 4

PostPosted: Thu Apr 23, 2009 2:09 pm    Post subject: Reply with quote

I'd like to use this script to just kick and not ban, but I'm not sure what to change to do that. I've tried setting "set want_ban 0" and that doesn't do it, and neither does commenting out that line. Help would be much appreciated Smile
Back to top
View user's profile Send private message
tomekk
Master


Joined: 28 Nov 2008
Posts: 255
Location: Oswiecim / Poland

PostPosted: Thu Apr 23, 2009 3:29 pm    Post subject: Reply with quote

Code:
# 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. You can define ban duration time etc. Script is very simple to use.

# Author: tomekk
# e-mail:  tomekk/@/oswiecim/./eu/./org
# home page: http://tomekk.oswiecim.eu.org/
#
# Version 0.8
#
# 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]

# added: you can now choose badwords script channels
# fixed: want_ban

# USE '/msg <botnick> bword' for more information

# check for 'badwords' on channels:
set bdw_channels {#channel #channel2}

# 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 - don't
# 1 means that user with +o can use 'badwords'
set protectops 0

# 1 - enable ban, 0 - disable ban (just kick after bad word)
set want_ban 1

# wait 'waitb' times before ban, works only when want_ban is set to 1
# if you want to ban user after one bad word, set 'waitb' to 0
set waitb 3

# 'waitb' info type, works only when want_ban is set to 1
# 1 - kick after bad word and ban after 'waitb' times
# 2 - write message after bad word to the nick, 'nick: message' and ban after 'waitb' times
# 3 - do nothing, just ban after 'waitb' times
set waitb_type 2

# if you set 'waitb' to 2, then here is a option to set this message
set waitb_message "watch your language kid !"

# ban duration time (minutes)
# 0 - infinite
set ban_duration 0

# "offence" duration time, how long bot should remember last bad word time (minutes)
# 0 - infinite
set offence_duration 0

# kick message
set kmsg "bad word! - kick"

# ban message
set bmsg "banned!"

# dirs and files, better leave it ;)
# base directory
set dirname "badwords.db"

# users directory
set usersdir "$dirname/lusers"

# banned hosts file
set banned_hosts "$dirname/bndhosts"

# dbase with bad words
set bw_dbase "$dirname/words_bank.db"

##################################################################
if {[file exists $dirname] == 0} {
   file mkdir $dirname
   set crtdb [open $bw_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 } {
   set fs_open [open $rdb r]
   gets $fs_open dbout
   close $fs_open

   return $dbout
}

proc get_all_bwords { } {
   global bw_dbase

   set bf [open $bw_dbase r]
   set allwords [read $bf]
   close $bf

   set bw_split [split $allwords "\n"]
        return $bw_split
}

proc add_new_bword { bword } {
   global bw_dbase

   set bfile_handle [open $bw_dbase a]
   puts $bfile_handle "$bword"
   close $bfile_handle
}

proc add_new_bnd_host { new_host  } {
   global banned_hosts

   set bnd_hosts [open $banned_hosts a]
   puts $bnd_hosts $new_host
   close $bnd_hosts
}

proc delete_bword { dbword {dlall 0}} {
   global bw_dbase

   set old_bwdb [get_all_bwords]
   
   set file_tow [open $bw_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
}

proc ban_checker_timer { } {
   ban_checker

   if {[string match *ban_checker_timer* [utimers]] != 1} {
      utimer 20 ban_checker_timer
   }
}

bind pubm - * word_fct
bind msgm - "*" bpmsg_fct

proc word_fct { nick uhost hand chan arg } {
     global botnick protectops usersdir waitb waitb_type waitb_message want_ban kmsg bmsg offence_duration ban_duration bdw_channels

   if {[lsearch $bdw_channels $chan] == -1} {
      return                               
   } 

   set nasty_words [get_all_bwords]

   set kill 0

   set ban_status 0

   set bb_msg $kmsg

   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} {
            set time_in_seconds [clock seconds]
            set user_ban_mask [banmask $uhost $nick]

            if {$waitb == 0} {
               putquick "MODE $chan +b $user_ban_mask"

               if {$ban_duration > 0}  {
                  add_new_bnd_host "$chan&$user_ban_mask&$time_in_seconds"
               }

               set bb_msg $bmsg

               putkick $chan $nick $bb_msg

               set ban_status 1
            } {
               if {[file exists $usersdir/$nick] == 0} {
                  create_db "$usersdir/$nick" "$uhost&1&$time_in_seconds"
               } {
                  set each_user_data [split [readdb "$usersdir/$nick"] "&"]
                  set ident [lindex $each_user_data 0]
                  set times [lindex $each_user_data 1]
                  set first_time [lindex $each_user_data 2]

                  if {([expr $time_in_seconds - $first_time] >= [expr $offence_duration * 60]) && ($offence_duration > 0)} {
                     file delete $usersdir/$nick
                     create_db "$usersdir/$nick" "$uhost&1&$time_in_seconds"
                  } {
                     file delete $usersdir/$nick

                     set overall [expr $times + 1]

                     create_db "$usersdir/$nick" "$ident&$overall&$first_time"
                     set ident [lindex [split [readdb "$usersdir/$nick"] "&"] 0]

                     if {$uhost == $ident} {            
                        if {$overall >= $waitb} {
                           putquick "MODE $chan +b $user_ban_mask"

                           if {$ban_duration > 0} {
                              add_new_bnd_host "$chan&$user_ban_mask&$time_in_seconds"
                           }

                           file delete $usersdir/$nick
                           set bb_msg $bmsg

                           putkick $chan $nick $bb_msg

                           set ban_status 1
                        }
                     } {
                        file delete $usersdir/$nick
                        create_db "$usersdir/$nick" "$uhost&1"
                     }
                  }   
               }
            }
         }

         if {$want_ban == 1} {
            if {($ban_status == 0) && ($waitb_type < 3)} {
               if {$waitb_type == 1} {
                  putkick $chan $nick $bb_msg
               } {
                  putquick "PRIVMSG $chan :$nick: $waitb_message"
               }
            }
         } {
            putkick $chan $nick $bb_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 exists"
                  } {
                     add_new_bword $nbword
                     putquick "PRIVMSG $nick :word $nbword has been 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 have been deleted"
               } {
                  foreach dbword $bargs_opt_newords {
                     if {[check_bw_exist $dbword]} {
                        delete_bword $dbword
                        putquick "PRIVMSG $nick :word $dbword have been 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
       }
}

proc ban_checker { } {
   global banned_hosts ban_duration

   if {([file exists $banned_hosts]) && ($ban_duration > 0)} {
      set hosts_hand [open $banned_hosts r]
      set give_me_hosts [read $hosts_hand]
      close $hosts_hand

      set time_in_seconds [clock seconds]

      set rewrite_hosts_hand [open $banned_hosts w]
      foreach banned_h [split $give_me_hosts "\n"] {
         if {$banned_h != ""} {
            set split_banned_h [split $banned_h "&"]
            set host_ban_chan [lindex $split_banned_h 0]
            set host_ban_mask [lindex $split_banned_h 1]
            set need_ban_time [lindex $split_banned_h 2]
   
            if {[expr $time_in_seconds - $need_ban_time] >= [expr $ban_duration * 60]} {
               putquick "MODE $host_ban_chan -b $host_ban_mask"
            } {
               puts $rewrite_hosts_hand "$host_ban_chan&$host_ban_mask&$need_ban_time"
            }
         }
      }
      close $rewrite_hosts_hand
   }
}

if {[string match *ban_checker_timer* [utimers]] != 1} {
           utimer 20 ban_checker_timer
}

putlog "tkbadword.tcl ver 0.8 by tomekk loaded"


ver 0.8

this ver. should work better and now you have to define on which channels script should check for bad words,
i added this because some ppl were asking me about this option, have fun

Code:
# check for 'badwords' on channels:
set bdw_channels {#channel #channel2}


cheers

P.S
thanks
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber