This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

badwords by MadaliN exception individual words

Help for those learning Tcl or writing their own scripts.
Post Reply
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

badwords by MadaliN exception individual words

Post by juanamores »

Code: Select all

#### ++++ Author: MadaliN <madalinmen28@yahoo.com
### ++++ Script name: Badwords
## ++++ Version: 1.0 (2/9/2013)
#
# Commands
#      !badwords on/off
#      !badwords ban-reason REASON
#      !badwords ban-type 1/2/3/4 (!badwords ban-type 1)
#      !badwords add WORD/PHRASE
#      !badwords del WORD/PHRASE
#      !badwords list

setudef flag badwords

bind PUB n !badwords badwords:pub

bind PUBM - * badwords:pubm

proc mh {nuhost type} {

   set user [lindex [split $nuhost !] 0]
   set host [lindex [split $nuhost !] 1]

   switch $type {
      1 {return $nuhost}
      2 {return *!*@$host}
      3 {return *!*$user@$host}
      4 {return *!*$user@*}
   }
}


proc badwords:pubm {nick uhost hand chan arg} {
   global badwords tempbw

   if {[channel get $chan badwords]} {
      foreach b [array names badwords $chan,*] {
         if {[string match -nocase "*[lindex [split $b ,] 1]*" $arg] && ![matchattr $hand n] && ![isop $nick $chan]} {

            if {![info exists tempbw($chan,ban-type)]} { set tempbw($chan,ban-type) 2 }
            if {![info exists tempbw($chan,reason)]} { set tempbw($chan,reason) "Hit the door ya ;" }

            newchanban $chan [mh $nick!$uhost $tempbw($chan,ban-type)] $nick $tempbw($chan,reason) 0

            putserv "KICK $chan $nick :$tempbw($chan,reason)"
         }
      }
   }
}

proc badwords:pub {nick uhost hand chan arg} {
   global badwords tempbw

   set what [join [lrange [split $arg] 1 end]]

   switch -exact -- [lindex [split $arg] 0] {
      ban-type -
      -ban-type {
         if {[lindex [split $arg] 1] == ""} { putserv "PRIVMSG $chan :\002$nick\002 - You have to specify ban-type (1/2/3/4)"; return }
         if {![regexp {^(1|2|3|4)$} [lindex [split $arg] 1]]} { putserv "PRIVMSG $chan :\002$nick\002 valid types are 1/2/3 or 4 (!badwords ban-type 2)"; return }

         set tempbw($chan,ban-type) $what
         badwords:save

         putserv "PRIVMSG $chan :\002$nick\002 - 'ban-type' has been SET"
      }
      -r -
      -reason {
         if {[lindex [split $arg] 1] == ""} { putserv "PRIVMSG $chan :\002$nick\002 - You have to specify ban-reason"; return }

         set tempbw($chan,reason) $what
         badwords:save

         putserv "PRIVMSG $chan :\002$nick\002 - 'ban-reason' has been SET"
      }
      on -
      -on {
         channel set $chan +badwords

         putserv "PRIVMSG $chan :\002$nick\002 - Succesfully activated \00303badwords\003 script on this channel"
      }
      off -
      -off {
         channel set $chan -badwords

         putserv "PRIVMSG $chan :\002$nick\002 - Succesfully deactivated \00303badwords\003 script on this channel"
      }
      add -
      -add {
         if {[info exists badwords($chan,$what)]} {
            putserv "PRIVMSG $chan :\002$nick\002 - '\00312$what\003' already exists in the database."
            return
         } else {
            set badwords($chan,$what) "[unixtime]"
            badwords:save

            putserv "PRIVMSG $chan :\002$nick\002 - Succesfully added '\00312$what\003' into the database."
            return
         }
      }
      del -
      -del {
         if {![info exists badwords($chan,$what)]} {
            putserv "PRIVMSG $chan :\002$nick\002 - '\00312$what\003' was not found in the database."
            return
         } else {
            unset -nocomplain badwords($chan,$what)
            badwords:save

            putserv "PRIVMSG $chan :\002$nick\002 - Succesfully removed '\00312$what\003' from the database."
            return
         }
      }
      list -
      -list {
         set temp(list) ""
         foreach b [array names badwords $chan,*] { lappend temp(list) [lindex [split $b ,] 1] }

         if {$temp(list) == ""} { putserv "PRIVMSG $chan :\002$nick\002 - Badwords database for \00303$chan\003 is \002empty\002"; return }

         putserv "PRIVMSG $chan :\002$nick\002 - Badwords: [join $temp(list) ", "]"
      }
      reset -
      -reset {
         foreach b [array names badwords $chan,*] {
            unset -nocomplain badwords($chan,[lindex [split $b ,] 1])
         }

         badwords:save
         putserv "PRIVMSG $chan :\002$nick\002 - Succesfully RESET badwords"
      }
   }
}

proc badwords:save {} {
   global badwords tempbw

   set ofile [open badwords w]
   puts $ofile "array set badwords [list [array get badwords]]"
   puts $ofile "array set tempbw [list [array get tempbw]]"
   close $ofile
}

catch {source badwords}


putlog "++++ Succesfully loaded: \00312Badwords TCL Script"
I need certain words to be excepted by the code.
I have succeeded, but only partially.
Example:
Badwords == puta, sexo, porno, ....more words....
If someone writes the word "diputada", containing the pattern "puta", the bot penalizes.
Partial solution:
proc badwords:pubm {nick uhost hand chan arg} {
global badwords tempbw

if {[channel get $chan badwords]} {
foreach b [array names badwords $chan,*] {
if {[string match -nocase "*diputada*" $arg]} { continue }
if {[string match -nocase "*[lindex [split $b ,] 1]*" $arg] && ![matchattr $hand n] && ![isop $nick $chan]} {
........................................more stuff..................................
Why partial?
If someone writes the phrase "la mejor diputada del mundo"
Work perfect! The boT does not penalize the user for writing "diputada".

but.................

If someone writes the phrase "a la diputada le gusta el sexo duro"
The bot does not penalize the word "sexo".

Any solution for the exception of individual words in a sentence, without the bot ceasing to control all other words?
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks :)
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

I find this sort of thing to work on some similar scripts.

Replace

Code: Select all

[string match -nocase "*[lindex [split $b ,] 1]*" $arg]
with

Code: Select all

[string match -nocase "* [lindex [split $b ,] 1] *" " $arg "]
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

Work perfectly!
Thanks SpiKe^^
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks :)
Post Reply