add word filter

This commit is contained in:
Elijah R 2024-07-12 15:58:40 -04:00
parent dab1b26429
commit 1d19098ca7
3 changed files with 9 additions and 0 deletions

View file

@ -14,6 +14,7 @@ charlimit = 100
agentsDir = "agents/"
maxConnectionsPerIP = 2
adminPasswordHash = "f52fbd32b2b3b86ff88ef6c490628285f482af15ddcb29541f94bcf526a3f6c7"
bannedWords = []
[chat.ratelimits]
chat = {seconds = 10, limit = 8}

View file

@ -103,6 +103,10 @@ export class Client extends EventEmitter {
return;
}
let username = htmlentities.encode(joinMsg.data.username);
if (this.room.config.bannedWords.some(w => username.indexOf(w) !== -1)) {
this.socket.close();
return;
}
if (this.room.clients.some(u => u.username === username)) {
let i = 1;
let uo = username;
@ -125,6 +129,9 @@ export class Client extends EventEmitter {
return;
}
if (talkMsg.data.msg.length > this.room.config.charlimit) return;
if (this.room.config.bannedWords.some(w => talkMsg.data.msg.indexOf(w) !== -1)) {
return;
}
this.emit('talk', talkMsg.data.msg);
break;
}

View file

@ -24,6 +24,7 @@ export interface ChatConfig {
agentsDir: string;
maxConnectionsPerIP: number;
adminPasswordHash: string;
bannedWords: string[];
ratelimits: {
chat: RateLimitConfig;
}