Author Topic: Badword Filter  (Read 4050 times)

0 Members and 1 Guest are viewing this topic.

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Badword Filter
« on: July 24, 2008, 09:38:33 am »
Script Name: Badword Filter
Script Description: Whenever a player says a badword (one of the ones listed in BadWordsList.txt) they are optionally kicked, and their number of used warnings is increased. Once they use up all of their warnings, they are either kicked or banned.
Original Author(s):Me, jrgp. I did use a function by DorkeyDear
Core Version: 2.2
Code: (Just some snippets, not the whole script)
Code: [Select]
//config
const
  NumWarnings = 3; //number of times a player can curse before getting kicked or banned
  FileName = 'BadWordsList.txt'; //file which holds the badwords, each seperated with a space
  Ban = false; //When a player reaches the curse limit, ban the player? (true or false)
  KillOnOffense = true; //With each offense, kill the player? (true or false)
  TextColor = $ffff00001; //color of messages told to player
  BanLength = 15; //minutes a player will be banned for, if the Ban = true;

//......

//whenever someone says something, check it.
procedure OnPlayerSpeak(PlayerID: Byte; Text: string);
var i: integer;
var Bad: boolean;
begin
//do we any badwords to check?
if not HaveBadWords then
exit;
//for now, make it false
Bad := false;
//check it!
for i := 0 to GetArrayLength(BadWords) - 1 do
begin
//if it is a bad word, make it known that we cursed
if ContainsString(UpperCase(Text), BadWords[i]) then //we're making what they said upercase so the badwords are case insensitive
Bad := true;
end;
//saying something naughty?
if Bad then
begin
//increase number of warnings used
inc(Warnings[PlayerID], 1);
//reached limit
if Warnings[PlayerID] = NumWarnings then
begin
//reset limit for this id
Warnings[PlayerID] := 0;
//Ban or kick?
if Ban then
begin
BanPlayer(PlayerID, 15);
exit;
end;
KickPlayer(PlayerID);
exit;
end;
//under limit..
if Warnings[PlayerID] < NumWarnings then
begin
//should we kill him / her?
if KillOnOffense then
DoDamage(PlayerID, 4000);
//notify player of this
WriteConsole(PlayerID, 'You have been warned for offensive language.', TextColor);
WriteConsole(PlayerID, 'If you curse '+inttostr(NumWarnings - Warnings[PlayerID])+' more time(s), you will be '+iif(Ban,'banned','kicked')+'.', TextColor);
end;
end;
end;
« Last Edit: July 24, 2008, 09:48:37 am by jrgp »
There are other worlds than these

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
Re: Badword Filter
« Reply #1 on: July 24, 2008, 12:57:06 pm »
I suggest using RegExpMatch to filter bad words, but your previous approach is not bad. The way of doing it with RegExpMatch allows you to filter a big amount of possible word combinations by having a certain amount of basic words. Take a look at JFK's NoobLottery, it's a quite good example how to use RegExpMatch  ;)


Markus
Soldat Global Account System: #soldat.sgas @ quakenet

Offline As de Espada

  • Soldat Beta Team
  • Veteran
  • ******
  • Posts: 1493
  • Mapper
    • My maps
Re: Badword Filter
« Reply #2 on: July 24, 2008, 01:48:21 pm »
they'll always find a way to offend themselfs
All my maps | my latest map: SoldatX Racing Mappack
me making a map on youtube: ctf_FastMade

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
Re: Badword Filter
« Reply #3 on: July 24, 2008, 02:50:54 pm »
Yea sure, but using RegExpMatch will offer you more possibilities to catch such words, therefore it's more capable.
Soldat Global Account System: #soldat.sgas @ quakenet

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Badword Filter
« Reply #4 on: July 24, 2008, 03:23:22 pm »
An example to use it w/ RegExpMatch...

".*[fF]+[ _\.,]*([uUvV]|\\/)+[ _\.,]*[cC\(\{\[kK\<]+[ _\.,]*[cC\(\{\[kK\<]+.*" (for feck with a u) (untested, thrown together)

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Re: Badword Filter
« Reply #5 on: July 24, 2008, 03:26:51 pm »
All of that is required for just one word? I think using arrays and ContainsString is much more efficient, since more words can easily be added to the text file, instead of having to be added through that cryptic regex.
There are other worlds than these

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
Re: Badword Filter
« Reply #6 on: July 24, 2008, 05:47:15 pm »
The RegExpMatch string of DorkeyDear filters more than one word. It covers a large amount of words, for example:

ffffff_......uUUU__....CKK
feck
feck
f__\/.cccckkkYOU
fuuu_ck_||||||noob
.
.
.

 There are thousands of  different possibilities the string matches with.
Using only containsstring, uppercase, lowercase and a simple string compare, restricts the whole progress ;)
Just think about it ...

@DorkeyDear:
In this case a positive look-ahead assertion or rather a positive look-behind assertion would be fine :)

Edit: The swear filter works :P -  partly
« Last Edit: July 24, 2008, 05:49:18 pm by Markus Quär »
Soldat Global Account System: #soldat.sgas @ quakenet

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Badword Filter
« Reply #7 on: July 24, 2008, 07:48:35 pm »
If regular expresions are to be used, be sure not to filter out commonly used words that really arn't swearing/cussing/any of that.

@jrgp definitly not. Like Markus said, theres extremely a lot of ways to cuss / swear / all of that, too many to just list just for one word, and then there's many other words.

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Re: Badword Filter
« Reply #8 on: July 24, 2008, 09:27:29 pm »
Edit: The swear filter works :P -  partly
What do you mean 'partly'? I spent a while making sure it didn't have bugs, but seeing as this is my second pascal program bugs are likely.

Now I see what you are saying about the regex, can someone please point me in the direction I need to go to rewrite the word detecting part of the program? Thanks in advance. :)
There are other worlds than these

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Badword Filter
« Reply #9 on: July 24, 2008, 09:49:18 pm »
http://www.regular-expressions.info/quickstart.html
Anyhoo I made a suggestion for EnEsCe in the suggestions thread that you should be able to modify the result of OnPlayerSpeak and similar things, so that you could actually filter stuff instead of just warning people.

Offline CurryWurst

  • Camper
  • ***
  • Posts: 265
    • Soldat Global Account System
Re: Badword Filter
« Reply #10 on: July 25, 2008, 04:44:52 am »
Edit: The swear filter works :P -  partly
What do you mean 'partly'? I spent a while making sure it didn't have bugs, but seeing as this is my second pascal program bugs are likely.

In this relation I meant the swear filter of forums.soldat.pl lol^^

Now I see what you are saying about the regex, can someone please point me in the direction I need to go to rewrite the word detecting part of the program? Thanks in advance. :)

First of all try to understand how regular expressions works.  For this purpose I recommend to take a look at the pages I listed below:

http://regexpstudio.com/TRegExpr/Help/RegExp_Syntax.html  (Haven't read this page, but it seems to explain very well how to use RegExpMatch)
http://en.wikipedia.org/wiki/Regular_expression


Good Luck!
Soldat Global Account System: #soldat.sgas @ quakenet

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Badword Filter
« Reply #11 on: July 25, 2008, 09:03:33 pm »
Anyhoo I made a suggestion for EnEsCe in the suggestions thread that you should be able to modify the result of OnPlayerSpeak and similar things, so that you could actually filter stuff instead of just warning people.
Its not going to happen. Already been suggested a million times by a million people, and yet still nothing. Besides, capability issues..

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Badword Filter
« Reply #12 on: September 04, 2008, 05:33:21 pm »
Edit: The swear filter works :P -  partly
What do you mean 'partly'? I spent a while making sure it didn't have bugs, but seeing as this is my second pascal program bugs are likely.

Now I see what you are saying about the regex, can someone please point me in the direction I need to go to rewrite the word detecting part of the program? Thanks in advance. :)

Like Marcus said, the NoobLottery i made is an example how to use regexp to filter out words and their leet substances. It contains three kinds of regular expressions:
1. Symbols, containing all forms of a letter/symbol/whatever (in a text file)
2. Banned Words, build out of Symbols (hard coded)
3. Exceptions Words, words that contain or are similar to banned words but are still allowed (in a text file)

This is just one method how to filter words with regexps

http://forums.soldat.pl/index.php?topic=25613.0
pm me if you want an update symbol and exception list or more info
Come join: EliteCTF
Listen to: My Music