Remove bad banned words implementation

This commit is contained in:
Madeline 2022-12-17 18:45:42 +11:00
parent d1c90c8c09
commit 444e815690
9 changed files with 5 additions and 60 deletions

View File

@ -1,7 +1,7 @@
import "missing-native-js-functions";
import { Server, ServerOptions } from "lambert-server";
import { Authentication, CORS } from "./middlewares/";
import { BannedWords, Config, initDatabase, initEvent } from "@fosscord/util";
import { Config, initDatabase, initEvent } from "@fosscord/util";
import { ErrorHandler } from "./middlewares/ErrorHandler";
import { BodyParser } from "./middlewares/BodyParser";
import { Router, Request, Response, NextFunction } from "express";
@ -38,7 +38,6 @@ export class FosscordServer extends Server {
await Config.init();
await initEvent();
await initInstance();
await BannedWords.init();
let logRequests = process.env["LOG_REQUESTS"] != undefined;
if (logRequests) {

View File

@ -12,7 +12,6 @@ import {
Snowflake,
uploadFile,
MessageCreateSchema,
BannedWords,
DiscordApiErrors,
} from "@fosscord/util";
import { Router, Response, Request } from "express";
@ -44,10 +43,6 @@ router.patch(
const { message_id, channel_id } = req.params;
var body = req.body as MessageCreateSchema;
if (body.content)
if (BannedWords.find(body.content))
throw DiscordApiErrors.AUTOMODERATOR_BLOCK;
const message = await Message.findOneOrFail({
where: { id: message_id, channel_id },
relations: ["attachments"],

View File

@ -15,7 +15,6 @@ import {
Role,
MessageCreateSchema,
ReadState,
BannedWords,
DiscordApiErrors,
} from "@fosscord/util";
import { HTTPError } from "lambert-server";
@ -192,10 +191,6 @@ router.post(
var body = req.body as MessageCreateSchema;
const attachments: Attachment[] = [];
if (body.content)
if (BannedWords.find(body.content))
throw DiscordApiErrors.AUTOMODERATOR_BLOCK;
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
relations: ["recipients", "recipients.user"],

View File

@ -7,7 +7,7 @@ import * as Gateway from "@fosscord/gateway";
import { CDNServer } from "@fosscord/cdn";
import express from "express";
import { green, bold, yellow } from "picocolors";
import { Config, initDatabase, BannedWords } from "@fosscord/util";
import { Config, initDatabase } from "@fosscord/util";
import * as Sentry from "@sentry/node";
import * as Tracing from "@sentry/tracing";
import * as Integrations from "@sentry/integrations";
@ -30,7 +30,6 @@ process.on("SIGTERM", async () => {
async function main() {
await initDatabase();
await Config.init();
await BannedWords.init();
//Sentry
if (Config.get().sentry.enabled) {

View File

@ -1,7 +1,7 @@
import "missing-native-js-functions";
import dotenv from "dotenv";
dotenv.config();
import { BannedWords, closeDatabase, Config, initDatabase, initEvent } from "@fosscord/util";
import { closeDatabase, Config, initDatabase, initEvent } from "@fosscord/util";
import ws from "ws";
import { Connection } from "./events/Connection";
import http from "http";
@ -50,7 +50,6 @@ export class Server {
await initDatabase();
await Config.init();
await initEvent();
await BannedWords.init();
if (!this.server.listening) {
this.server.listen(this.port);
console.log(`[Gateway] online on 0.0.0.0:${this.port}`);

View File

@ -15,7 +15,7 @@ import {
RelationId,
} from "typeorm";
import { Guild } from "./Guild";
import { Config, emitEvent, BannedWords, FieldErrors } from "../util";
import { Config, emitEvent, FieldErrors } from "../util";
import {
GuildCreateEvent,
GuildDeleteEvent,
@ -126,10 +126,6 @@ export class Member extends BaseClassWithoutId {
if (this.nick) {
this.nick = this.nick.split("\n").join("");
this.nick = this.nick.split("\t").join("");
if (BannedWords.find(this.nick))
throw FieldErrors({
nick: { message: "Bad nickname", code: "INVALID_NICKNAME" },
});
}
}

View File

@ -16,7 +16,6 @@ import {
FieldErrors,
Snowflake,
trimSpecial,
BannedWords,
adjustEmail,
} from "..";
import { Member, Session } from ".";
@ -242,12 +241,6 @@ export class User extends BaseClass {
});
this.discriminator = discrim.toString().padStart(4, "0");
}
if (/*!update ||*/ this.username)
if (BannedWords.find(this.username))
throw FieldErrors({
username: { message: "Bad username", code: "INVALID_USERNAME" },
});
}
toPublicUser() {

View File

@ -1,30 +0,0 @@
import fs from "fs/promises";
import path from "path";
import { InvisibleCharacters } from "./InvisibleCharacters";
var words: string[];
export const BannedWords = {
init: async function init() {
if (words) return words;
const file = (
await fs.readFile(path.join(process.cwd(), "bannedWords"))
).toString();
if (!file) {
words = [];
return [];
}
words = file.trim().split("\r").join("").split("\n");
return words;
},
get: () => words,
find: (val: string) => {
InvisibleCharacters.forEach(x => val = val.replaceAll(x, ""));
var normal = words.some((x) => val.indexOf(x) != -1);
val = val.split("").reverse().join("");
var rtlOverride = words.some((x) => val.indexOf(x) != -1);
return normal || rtlOverride;
},
};

View File

@ -19,5 +19,4 @@ export * from "./Snowflake";
export * from "./String";
export * from "./Array";
export * from "./TraverseDirectory";
export * from "./InvisibleCharacters";
export * from "./BannedWords";
export * from "./InvisibleCharacters";