1

I plan on putting this list of bad words (https://github.com/shutterstock/List-of-Dirty-Naughty-Obscene-and-Otherwise-Bad-Words/blob/master/en) into a .txt file on my web server. How can I this javascript check the variable "userNickName" against the .txt file named "blacklist.txt" on my web server.

(This is the code I want the bad word check implemented on, how would I do that?)

if (wsIsOpen() && null != userNickName) {
  var msg = prepareData(1 + 2 * userNickName.length);
  msg.setUint8(0, 0);
  for (var i = 0; i < userNickName.length; ++i) msg.setUint16(1 + 2 * i, userNickName.charCodeAt(i), true);
  wsSend(msg)
Andrew Tran
  • 13
  • 2
  • 7

2 Answers2

1

Make an JS array like badWords = ["boob","boobs","..."];

this could be done with Get file contents in java script and How do I split a string, breaking at a particular character?

Or directly with PHP on the server side.

$badWords = file_get_contents('https://raw.githubusercontent.com/shutterstock/List-of-Dirty-Naughty-Obscene-and-Otherwise-Bad-Words/master/en');

$badWords = explode("\n", $badWords);
echo 'badWords = ["'.implode('","', $badWords).'"];';

After that, How to find if an array contains a specific string in JavaScript/jQuery? (2nd answer for a not-JQuery one)

Community
  • 1
  • 1
Blag
  • 5,818
  • 2
  • 22
  • 45
  • Lets say someone names them self "|BADWORD|", will it still work if I use the link you gave me? – Andrew Tran Jan 30 '16 at 19:15
  • @AndrewTran no, it's not an aggressive filter. You can make it, but with "tit" or "ass" you'll match white word too : "ASSumption" or "TITo" / "TITanic" this may go too far... ; an idea could be removing anything other than letter in the nickname before checking against the badwords list : http://stackoverflow.com/questions/9364400/remove-not-alphanumeric-characters-from-string-having-trouble-with-the-char – Blag Jan 30 '16 at 19:27
  • ok thanks; My final solution was to loop the array, check if the nickname contained a space and if it did I would do badWords[i] + " " otherwise I would just use badWords[i] and do something like if (userNickname.toLowerCase().indexOf(badWords[i]) < 0 – Andrew Tran Jan 31 '16 at 16:57
0
message.save((err) => {
    if (err)
        sendStatus(500)

    Messages.findOne({ message: 'badword' }, (err, censored) => {
        if (censored) {
            console.log('cendsored words found', censored)

            message.remove({ _id: censored.id }, (err) => {
                console.log('removed censored message')
            })
        }
    })

    io.emit('message', req.body)
    res.sendStatus(200);
})## Heading ##
Martin
  • 2,411
  • 11
  • 28
  • 30
ubair noor
  • 91
  • 1
  • 1