Implement chat banned words filter from a vague memory of a snippet

This commit is contained in:
Hri7566 2024-07-13 14:10:20 -04:00
parent a67be0889e
commit 1f16715aa7
2 changed files with 18 additions and 4 deletions

View File

@ -146,8 +146,13 @@ export class Channel extends EventEmitter {
}
});
this.on("message", async (msg: ServerEvents["a"], socket: Socket) => {
if (!msg.message) return;
const BANNED_WORDS = [
"AMIGHTYWIND",
"CHECKLYHQ"
];
this.on("a", async (msg: ServerEvents["a"], socket: Socket) => {
if (typeof msg.message !== "string") return;
const userFlags = socket.getUserFlags();
@ -155,9 +160,18 @@ export class Channel extends EventEmitter {
if (userFlags.cant_chat) return;
}
if (!this.settings.chat) return;
if (msg.message.length > 512) return;
// Sanitize
for (const word of BANNED_WORDS) {
if (msg.message.toLowerCase().split(" ").join("").includes(word.toLowerCase())) {
return;
}
}
// Sanitize chat message
// Regex originally written by chacha
msg.message = msg.message
.replace(/\p{C}+/gu, "")
.replace(/(\p{Mc}{5})\p{Mc}+/gu, "$1")

View File

@ -16,6 +16,6 @@ export const a: ServerEventListener<"a"> = {
// msg.m
// Permission denied: msg.m
// sudo msg.m
ch.emit("message", msg, socket);
ch.emit("a", msg, socket);
}
};