mIRC Home    About    Download    Register    News    Help

Print Thread
#155851 09/08/06 11:42 PM
Joined: Feb 2005
Posts: 344
B
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Feb 2005
Posts: 344
Looking for something that takes out the bad words from a line.
Instead of the badword it wil say <cencored>.
found some things but the remove the whole line instead of only the word.

#155852 09/08/06 11:47 PM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
If the network you're on is using Unreal, and you have access to change channel modes, set channel mode +G

This may work with other IRCd's as well, but definetely works with Unreal. The +G mode makes the channel G rated, so the network looks after the "bad words".

#155853 10/08/06 12:34 AM
Joined: Feb 2005
Posts: 342
R
Fjord artisan
Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
Simple example:

Code:
alias cursefilter { return $regsubex($1-,/(badword1|badword2|badword3|badword4)/g,&lt;censored&gt;)  }


You will want to replace the "badword1" with a bad word, and same for badword2 and badword3. To add more badwords to that list, you can simply add a | after the word, but before the )/g
So in other words:
(badword1|badword2)
(badword1|badword2|badword3)
(badword1|badword2|badword3|badword4)

Those three lines just shows the transition from having two bad words, to four bad words.

You'll be able to use:
//echo -ag $cursefilter(Something something your-bad-word something something)

#155854 10/08/06 12:38 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Please note that Rand's suggestion, and any other code that someone might write for you, will only be effective for your display. If you want to filter it out from everyone, then you'll need to use something like my suggestion so that the filtering takes place at the server level.

#155855 10/08/06 08:19 AM
Joined: Feb 2005
Posts: 344
B
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Feb 2005
Posts: 344
I only want it to have effect on my display.
In the alias can i make a variable for badword ?
Something like:
Code:
  var %badword = $readini(badword.ini,badwords,$$1)

and alias would look like this:
Code:
 alias cursefilter { return $regsubex($1-,/(%badword)/g,&lt;censored&gt;)  }

Then i can make a command that uses /writeini to add more badwords when i bump into one.

#155856 10/08/06 09:20 AM
Joined: Feb 2005
Posts: 342
R
Fjord artisan
Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
I don't really suggest using an ini file for badwords.

You can of course, use a global variable instead. For example:

Code:
alias addbadword { set %badword $addtok(%badword,$1,124) | viewbadword }
alias delbadword { set %badword $remtok(%badword,$1,124) | viewbadword }
alias viewbadword { tokenize 124 %badword | echo -ag Your badwords are: $1- }
alias cursefilter { return $regsubex($1-,/( $+ %badword $+ )/g,&lt;censored&gt;)  }


/addbadword somewordhere; -- This adds "somewordhere" to your list.
/delbadword otherwordhere; -- This deletes the word "otherwordhere" from your list.
/viewbadword; -- This shows you your badword list.

#155857 10/08/06 09:54 AM
Joined: Feb 2005
Posts: 344
B
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Feb 2005
Posts: 344
thank you

#155858 10/08/06 06:08 PM
Joined: Jan 2003
Posts: 1,063
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2003
Posts: 1,063
problem there would be that vars can't hold that many characters. using a hash table would be preferable


If it ain't broken, don't fix it!
#155859 10/08/06 06:38 PM
Joined: Feb 2005
Posts: 344
B
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Feb 2005
Posts: 344
one thing .....
on testing it show that if the badword is a part of another word that isn't a badword it also is filtered.
example:
badword = pussy

word spoken = pussycat

outcome then is <censored>cat

Is there a way around this ?

#155860 10/08/06 09:05 PM
Joined: Mar 2003
Posts: 612
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Mar 2003
Posts: 612
put a $chr(32) into the match string. $+(pussy,$chr(32),$chr(42)) perhaps

Last edited by billythekid; 10/08/06 09:06 PM.

billythekid
#155861 10/08/06 10:30 PM
Joined: Feb 2005
Posts: 344
B
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Feb 2005
Posts: 344
A good friend came up with this:

Code:
 ;$1- is de tekst die gecensureerd moet worden
alias censuur {
  var %text = $1-
  var %i = $hget(censuur,0).data
  while ( %i ) {
    var %word = $hget(censuur,%i).data
    var %text = $iif($regsub($strip(%text),/\b $+ %word $+ \b/ig,$str(*,$len(%word)),%new),%new,%text)
    dec %i
  }
  return %text
}

;voegt een woord toe aan censuur
alias addcensuur {
  hadd -m censuur $1 $1
  savecensuur
}

;verwijdert een woord uit de censuur lijst 
;(gebruik een * voor meerdere soortgelijke woorden te verwijderen)
alias delcensuur {
  .hdel -w $1
  savecensuur
}

;bewaard de censuurlijst
alias savecensuur { .hsave censuur censuur.txt }

;censuurlijst inladen
alias loadcensuur { 
  .hmake censuur 100 
  if ( $exists(censuur.txt) ) { .hload censuur censuur.txt }
}

;laat alle woorden zien
alias showcensuur {
  if ( $window(@censuur) ) { window -c @censuur }
  window -s @censuur
  var %i = $hget(censuur,0).data
  while ( %i ) {
    aline @censuur $hget(censuur,%i).data
    dec %i
  }
}
on *:start: { loadcensuur }
on ^*:text:*:*: { echo -t $target &lt; $+ $iif($target ischan,$nick($chan,$nick).pnick,$nick) $+ &gt; $censuur($1-) | haltdef }
on ^*:action:*:*: { echo -t $target &lt; $+ $iif($target ischan,$nick($chan,$nick).pnick,$nick) $+ &gt; $censuur($1-) | haltdef } 


And this works perfectly.
Thanks snabbi

#155862 11/08/06 12:26 AM
Joined: Feb 2005
Posts: 342
R
Fjord artisan
Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
Your friends code has issues.

Code:
 ;$1- is de tekst die gecensureerd moet worden
alias censuur {
  var %text = $1-
  var %i = $hget(censuur,0).data
  while ( %i ) {
    var %word = $hget(censuur,%i).data
    var %text = $iif($regsub($strip(%text),/\b $+ %word $+ \b/ig,$str(*,$len(%word)),%new),%new,%text)
    dec %i
  }
  return %text
}


Obviously, it's a while loop. What's wrong with while loops? Well, using $regsubex to begin with was so you didn't have to use a while loop.

That alias isn't very optimal, you generally want to AVOID doing loops where possible, and btw, all you had to do was change:
Code:
Original:
alias cursefilter { return $regsubex($1-,/( $+ %badword $+ )/gi,&lt;censored&gt;)  }

To:
alias cursefilter { return $regsubex($1-,/\b( $+ %badword $+ )\b/gi,$str(*,$len(\t))) }


So if you had "pussy" in your badword filter, then "pussycat" would not match it. But if it was "pussy" in the text it'd show up as *****.

I really wouldn't suggest using a while loop. You'll get lagged up if a few bots decide to start flooding you. (Because that loop is going to trigger, regardless if a curse word is in the text or not. NOT good.)

#155863 11/08/06 03:35 AM
Joined: Feb 2005
Posts: 344
B
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Feb 2005
Posts: 344
didn't your thing end with storing 256 charaters rand ?
That would not be enough to store all badwords.

#155864 11/08/06 03:52 AM
Joined: Feb 2005
Posts: 342
R
Fjord artisan
Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
Hash tables are indeed preferable for most things. But in this case, if you're wanting to replace the actual word, it requires a loop somewhere in the process.

If you really MUST use a hash table for something like this, you want to keep loops to a minimum. Such as this:

Code:
; Add a bad word, /abword word; (just one word)
alias abword { 
  if ($0 == 1) { hadd -m bword $1 /\b( $+ $1  $+ )\b/gi | vbword | sbword }
  else { echo -agc info *** Error: Invalid parameters. Must be one word only. }
}
; Delete a bad word, /dbword word;
alias dbword {
  if ($0 == 1) { hdel bword $1 | vbword | sbword }
  else { echo -agc info *** Error: Invalid parameters. Must be one word only. }
}
; View bad words, /vbword;
alias vbword { 
  var %i = 1
  while ($hget(bword,%i).item) {
    var %bwords = %bwords $v1
    if ($len(%bwords) &gt; 200) { echo -ag Bwords: %bwords | var %bwords }
    inc %i 
  }
  if (%bwords) { echo -ag Bwords: %bwords }
}
; $curse($1-); Censors text based upon "bword" hash table.
alias cursef {
  var %i = 1 , %text = $1-
  while ($hfind(bword,$1-,%i,R).data) {
    var %text = $regsubex(%text,$hget(bword,$v1),$str(*,$len(\t)))
    inc %i
  }
  return %text
}
; Save the hash table, /sbword
alias sbword { if ($hget(bword)) { hsave -i bword bword.ini bword } }
; Load the hash table, /lbword
alias lbword { 
  if ($hget(bword)) { hfree bword }
  hmake bword 100
  if ($isfile(bword.ini)) { hload -i bword bword.ini bword }
}
on *:start:{ lbword }


The way I made this though, was mainly meant to be quick. So it doesn't support "multi-word swear words." I could change that of course, but then it'd require you to use a -different- way to delete the words (example: you'd probably need a dialog).

The commands would be:

/abword; -- Adds a word.
/dbword; -- Deletes a word.
/vbword; -- Shows badword list.
/sbword; -- Save the badword list. (This is triggered automatically after adding a word or deleting a word with the /abword and /dbword aliases.)
/lbword; -- This loads the badword.ini list into the bword hash table.
$cursef($1-); -- This returns the "censored" text.


I still suggest just using a variable to hold the vars, rather than using a hash table. Much cleaner.

#155865 11/08/06 03:54 AM
Joined: Feb 2005
Posts: 342
R
Fjord artisan
Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
Quote:
didn't your thing end with storing 256 charaters rand ?
That would not be enough to store all badwords.


Uh, no. It can hold over 900 characters. But you'd only want around 800 in there to be on the safe side.

Edit:

In case you're wondering how my hash table script differs from your friends, my script only looks at the relevent bad words found in the line.

Meaning if you had a list of 200 bad words, and the line of text only contained 2 of those bad words, your friends code would loop through all 200 of them. Where as my code would loop through just two, to replace your bad words.

Last edited by Rand; 11/08/06 03:59 AM.

Link Copied to Clipboard