const express = require('express'), app = express(); const badWordFilter = ["herobrine", "blobs"]; app.use(express.json()); /* { "response": // Boolean - If this is true it goes to "passThrough" (Not filtered!) "hashed": // String - If not present, it gets fully filtered (removed) - if this is here then `hashes` is required! "hashes": // Json Array - The bad words found } */ app.all('/*', (req, res, next) => { console.log(`${req.ip} ${req.method} ${req.originalUrl}`); console.log(req.headers); console.log(req.body); next(); }); app.post('/v1/join', (req, res) => { res.status(200).json({ response: true }) }); app.post('/v1/leave', (req, res) => { res.status(200).json({ response: true }) }); app.post('/v1/chat', (req, res) => { const body = req.body; // Notch is exempt from the chat filter! if (body.player_display_name === 'Notch') { return res.status(200).json({ response: true }); } const text = body.text.toLowerCase(); let filteredText = text; const badWords = []; for (badWord of badWordFilter) { if (text.includes(badWord)) { badWords.push(badWord); filteredText = filteredText.replace(badWord, '*'.repeat(badWord.length)); } } // There's a bad word if (badWords.length > 0) { res.status(200).json({ response: false, hashed: filteredText, hashes: badWords }) } else { // No filtering needed res.status(200).json({ response: true }) } }); app.listen(8000, () => console.log('Listening on :8000'));