summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--bun.lockbbin3873 -> 4242 bytes
-rw-r--r--config.json1
-rw-r--r--index.js7
-rw-r--r--package.json1
5 files changed, 10 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 9b1ee42..043ddbb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -173,3 +173,6 @@ dist
 
 # Finder (MacOS) folder config
 .DS_Store
+
+db
+db/users.json
diff --git a/bun.lockb b/bun.lockb
index 3cef471..bcc5104 100644
--- a/bun.lockb
+++ b/bun.lockb
Binary files differdiff --git a/config.json b/config.json
index 6d94004..884e06d 100644
--- a/config.json
+++ b/config.json
@@ -2,5 +2,6 @@
     "name": "wsChat server",
     "motd": "Welcome to $(serverName)$\nRun /help to see a list of commands",
     "max": 20,
+    "profanity": false,
     "fullMessage": "Sorry, but the server is full right now, come back later"
 }
\ No newline at end of file
diff --git a/index.js b/index.js
index 73c92db..ed778b0 100644
--- a/index.js
+++ b/index.js
@@ -1,9 +1,11 @@
 import { WebSocketServer } from "ws";
 import { getRandomInt } from "./lib.js"
+import { profanity } from '@2toad/profanity';
 import { commands } from "./commands.js";
 import * as accounts from "./accounts.js"
 import cuid from 'cuid';
 import fs from 'fs';
+profanity.options.grawlixChar = "*"
 
 const server = {
     config: JSON.parse(String(fs.readFileSync("config.json"))),
@@ -123,8 +125,9 @@ ws.on('connection', (socket, request) => {
             }
             return
         }
-        if (rawData.length < 1) return socket.send("Error: message too short!")
-        if (rawData.length >= 2000) return socket.send("Error: message too long!")
+        if (rawData.length < 1) return socket.send("Error: message too short!");
+        if (rawData.length >= 2000) return socket.send("Error: message too long!");
+        if (!server.profanity) rawData = profanity.censor(String(rawData));
         sendInChannel(`<${user.name()}${user.guest ? " (guest)" : ""}> ${rawData}`, server.users[userID].channel)
         console.log(`(#${server.users[userID].channel}) <${user.name()}> ${rawData}`)
     })
diff --git a/package.json b/package.json
index c6e9096..a81284c 100644
--- a/package.json
+++ b/package.json
@@ -16,6 +16,7 @@
     "typescript": "^5.0.0"
   },
   "dependencies": {
+    "@2toad/profanity": "^2.2.0",
     "cuid": "^3.0.0",
     "ws": "^8.17.1"
   }