mIRC Homepage
Posted By: Garou find error please - 21/03/07 05:59 PM
Its not working all the time. Sometimes it does kick the bad word and other times it wont. Why I cant remove the 0 when I add a bad word? If i remove the 0 it turns off.

on *:start:{
if !$hget(BadWord) { .hmake BadWord 10 }
if $exists(BadWord.hsh) { .hload BadWord BadWord.hsh }
}
on *:exit:{
.hsave -o BadWord BadWord.hsh
}
on *:disconnect:{
.hsave -o BadWord BadWord.hsh
}

menu menubar {
-
Private Offensive Message
.Turn $iif($hget(BadWord,0),Off,On) : .hadd -m BadWord 0 $iif($hget(BadWord,0),$false,$true)
.-
.Add Offensive Word : .hadd -m BadWord $$?="Offensive word to be added" $true
.-
.View Offensive Word : .bad_words_list
.-
.Remove Offensive Word : .hdel BadWord $$?="Offensive word to be removed"
.-
}
alias -l bad_words_list {
var %a = 1, %b = $hget(BadWord,0).item
unset %BadWord
while %a <= %b {
set %BadWord $addtok(%BadWord,$hget(BadWord,%a).item,32)
if ($calc($numtok(%BadWord,32) + $len(%BadWord)) > 900) {
echo -a $replace(%BadWord,$chr(32),$+($chr(44),$chr(32)))
unset %BadWord
}
inc %a
}
if %BadWord {
echo -a $replace(%BadWord,$chr(32),$+($chr(44),$chr(32)))
unset %BadWord
}
}
on *:open:?:{
if ($ulevel != op) && ($hget(BadWord,0)) {
var %cnt = 1
while (%cnt <= $hget(BadWord,0).item) {
if ($hget(BadWord,%cnt).item isin $1-) {
close -m $nick
.timer. $+ $nick 2 1 spamdetect $nick
halt
}
inc %cnt
}
}
}

on ^*:notice:*:?: {
var %oknames = ChanServ NickServ MemoServ
if ($nick !isin %oknames) && ($hget(BadWord,0)) {
var %cnt = 1
while (%cnt <= $hget(BadWord,0).item) {
if ($hget(BadWord,%cnt).item isin $1-) {
.timer. $+ $nick 2 1 spamdetect $nick
halt
}
inc %cnt
}
}
}


alias spamdetect {
var %a = $comchan($1,0)
while (%a > 0) {
if ($me isop $comchan($1,%a)) && ($1 !isop $comchan($1,%a)) {
ban -ku600 $comchan($1,%a) $1 14Private Offensive Language
}
dec %a
}
}
Posted By: DJ_Sol Re: find error please - 21/03/07 09:10 PM
Well you didn't show an error message.

I found this.

$hget(BadWord,0)

Should be $hget(BadWord,0).item

Unless, of course, you have an entry named 0.
Posted By: RusselB Re: find error please - 21/03/07 10:45 PM
The code uses item 0 in the hash table to control whether the script is active or not.
Quote:
.Turn $iif($hget(BadWord,0),Off,On) : .hadd -m BadWord 0 $iif($hget(BadWord,0),$false,$true)


Garou:As to why it's not always kicking, I suspect that the bad word is coming in using text, rather than notice, at those times.
You don't have an ON TEXT event that corresponds with the ON NOTICE event. Another possibility is that the bad word is coming across as an action or is coloured, reversed, or underlined.

That script is similar to one that I've written many times before, with the exception of the fact that those options are missing.
I can add them for you, or you can script them yourself (I think you should be good enough to be able to do it yourself).
Posted By: Riamus2 Re: find error please - 21/03/07 10:53 PM
First, here's your code inside code tags so we can read it...

Code:
on *:start:{
  if !$hget(BadWord) { .hmake BadWord 10 }
  if $exists(BadWord.hsh) { .hload BadWord BadWord.hsh }
}
on *:exit:{
  .hsave -o BadWord BadWord.hsh
}
on *:disconnect:{
  .hsave -o BadWord BadWord.hsh
}

menu menubar {
  -
  Private Offensive Message                      
  .Turn $iif($hget(BadWord,0),Off,On) : .hadd -m BadWord 0 $iif($hget(BadWord,0),$false,$true)
  .-
  .Add Offensive Word : .hadd -m BadWord $$?="Offensive word to be added" $true
  .-
  .View Offensive Word : .bad_words_list
  .-
  .Remove Offensive Word : .hdel BadWord $$?="Offensive word to be removed"
  .-
}
alias -l bad_words_list {
  var %a = 1, %b = $hget(BadWord,0).item
  unset %BadWord
  while %a <= %b {
    set %BadWord $addtok(%BadWord,$hget(BadWord,%a).item,32)
    if ($calc($numtok(%BadWord,32) + $len(%BadWord)) > 900) {
      echo -a $replace(%BadWord,$chr(32),$+($chr(44),$chr(32)))
      unset %BadWord
    }
    inc %a
  }
  if %BadWord {
    echo -a $replace(%BadWord,$chr(32),$+($chr(44),$chr(32)))
    unset %BadWord
  }
}
on *:open:?:{
  if ($ulevel != op) && ($hget(BadWord,0)) {
    var %cnt = 1
    while (%cnt <= $hget(BadWord,0).item) {
      if ($hget(BadWord,%cnt).item isin $1-) {
        close -m $nick
        .timer. $+ $nick 2 1 spamdetect $nick
        halt
      }
      inc %cnt      
    }
  }
}

on ^*:notice:*:?: {
  var %oknames = ChanServ NickServ MemoServ
  if ($nick !isin %oknames) && ($hget(BadWord,0)) {
    var %cnt = 1
    while (%cnt <= $hget(BadWord,0).item) {
      if ($hget(BadWord,%cnt).item isin $1-) {
        .timer. $+ $nick 2 1 spamdetect $nick
        halt
      }
      inc %cnt 
    }
  }
}


alias spamdetect {
  var %a = $comchan($1,0)
  while (%a > 0) {
    if ($me isop $comchan($1,%a)) && ($1 !isop $comchan($1,%a))  {
      ban -ku600 $comchan($1,%a) $1 14Private Offensive Language 
    }
    dec %a
  } 
} 


Originally Posted By: Garou
Its not working all the time. Sometimes it does kick the bad word and other times it wont. Why I cant remove the 0 when I add a bad word? If i remove the 0 it turns off.


I don't have time to really go through it, but you're setting the item "0" as an on/off status. If you want an on/off status without having item "0" in your hash table, then you can just use a variable for that and that would probably be more appropriate. Also, because you have an item "0", then that will be considered a "bad word" and would trigger if someone just had a 0 in their text. You could avoid that by putting a check in or by using a variable for the on/off status.

Also, hash table commands (/hmake, /hload, etc) do not echo anything unless there is an error. As such, there isn't any real need to use a silencing . before those commands. Having it there just means that you'll never see an error message associated with those... and that's usually not a good thing.
© mIRC Discussion Forums