Remove bad banned words implementation
This commit is contained in:
parent
d1c90c8c09
commit
444e815690
@ -1,7 +1,7 @@
|
|||||||
import "missing-native-js-functions";
|
import "missing-native-js-functions";
|
||||||
import { Server, ServerOptions } from "lambert-server";
|
import { Server, ServerOptions } from "lambert-server";
|
||||||
import { Authentication, CORS } from "./middlewares/";
|
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 { ErrorHandler } from "./middlewares/ErrorHandler";
|
||||||
import { BodyParser } from "./middlewares/BodyParser";
|
import { BodyParser } from "./middlewares/BodyParser";
|
||||||
import { Router, Request, Response, NextFunction } from "express";
|
import { Router, Request, Response, NextFunction } from "express";
|
||||||
@ -38,7 +38,6 @@ export class FosscordServer extends Server {
|
|||||||
await Config.init();
|
await Config.init();
|
||||||
await initEvent();
|
await initEvent();
|
||||||
await initInstance();
|
await initInstance();
|
||||||
await BannedWords.init();
|
|
||||||
|
|
||||||
let logRequests = process.env["LOG_REQUESTS"] != undefined;
|
let logRequests = process.env["LOG_REQUESTS"] != undefined;
|
||||||
if (logRequests) {
|
if (logRequests) {
|
||||||
|
@ -12,7 +12,6 @@ import {
|
|||||||
Snowflake,
|
Snowflake,
|
||||||
uploadFile,
|
uploadFile,
|
||||||
MessageCreateSchema,
|
MessageCreateSchema,
|
||||||
BannedWords,
|
|
||||||
DiscordApiErrors,
|
DiscordApiErrors,
|
||||||
} from "@fosscord/util";
|
} from "@fosscord/util";
|
||||||
import { Router, Response, Request } from "express";
|
import { Router, Response, Request } from "express";
|
||||||
@ -44,10 +43,6 @@ router.patch(
|
|||||||
const { message_id, channel_id } = req.params;
|
const { message_id, channel_id } = req.params;
|
||||||
var body = req.body as MessageCreateSchema;
|
var body = req.body as MessageCreateSchema;
|
||||||
|
|
||||||
if (body.content)
|
|
||||||
if (BannedWords.find(body.content))
|
|
||||||
throw DiscordApiErrors.AUTOMODERATOR_BLOCK;
|
|
||||||
|
|
||||||
const message = await Message.findOneOrFail({
|
const message = await Message.findOneOrFail({
|
||||||
where: { id: message_id, channel_id },
|
where: { id: message_id, channel_id },
|
||||||
relations: ["attachments"],
|
relations: ["attachments"],
|
||||||
|
@ -15,7 +15,6 @@ import {
|
|||||||
Role,
|
Role,
|
||||||
MessageCreateSchema,
|
MessageCreateSchema,
|
||||||
ReadState,
|
ReadState,
|
||||||
BannedWords,
|
|
||||||
DiscordApiErrors,
|
DiscordApiErrors,
|
||||||
} from "@fosscord/util";
|
} from "@fosscord/util";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
@ -192,10 +191,6 @@ router.post(
|
|||||||
var body = req.body as MessageCreateSchema;
|
var body = req.body as MessageCreateSchema;
|
||||||
const attachments: Attachment[] = [];
|
const attachments: Attachment[] = [];
|
||||||
|
|
||||||
if (body.content)
|
|
||||||
if (BannedWords.find(body.content))
|
|
||||||
throw DiscordApiErrors.AUTOMODERATOR_BLOCK;
|
|
||||||
|
|
||||||
const channel = await Channel.findOneOrFail({
|
const channel = await Channel.findOneOrFail({
|
||||||
where: { id: channel_id },
|
where: { id: channel_id },
|
||||||
relations: ["recipients", "recipients.user"],
|
relations: ["recipients", "recipients.user"],
|
||||||
|
@ -7,7 +7,7 @@ import * as Gateway from "@fosscord/gateway";
|
|||||||
import { CDNServer } from "@fosscord/cdn";
|
import { CDNServer } from "@fosscord/cdn";
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import { green, bold, yellow } from "picocolors";
|
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 Sentry from "@sentry/node";
|
||||||
import * as Tracing from "@sentry/tracing";
|
import * as Tracing from "@sentry/tracing";
|
||||||
import * as Integrations from "@sentry/integrations";
|
import * as Integrations from "@sentry/integrations";
|
||||||
@ -30,7 +30,6 @@ process.on("SIGTERM", async () => {
|
|||||||
async function main() {
|
async function main() {
|
||||||
await initDatabase();
|
await initDatabase();
|
||||||
await Config.init();
|
await Config.init();
|
||||||
await BannedWords.init();
|
|
||||||
|
|
||||||
//Sentry
|
//Sentry
|
||||||
if (Config.get().sentry.enabled) {
|
if (Config.get().sentry.enabled) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import "missing-native-js-functions";
|
import "missing-native-js-functions";
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
import { BannedWords, closeDatabase, Config, initDatabase, initEvent } from "@fosscord/util";
|
import { closeDatabase, Config, initDatabase, initEvent } from "@fosscord/util";
|
||||||
import ws from "ws";
|
import ws from "ws";
|
||||||
import { Connection } from "./events/Connection";
|
import { Connection } from "./events/Connection";
|
||||||
import http from "http";
|
import http from "http";
|
||||||
@ -50,7 +50,6 @@ export class Server {
|
|||||||
await initDatabase();
|
await initDatabase();
|
||||||
await Config.init();
|
await Config.init();
|
||||||
await initEvent();
|
await initEvent();
|
||||||
await BannedWords.init();
|
|
||||||
if (!this.server.listening) {
|
if (!this.server.listening) {
|
||||||
this.server.listen(this.port);
|
this.server.listen(this.port);
|
||||||
console.log(`[Gateway] online on 0.0.0.0:${this.port}`);
|
console.log(`[Gateway] online on 0.0.0.0:${this.port}`);
|
||||||
|
@ -15,7 +15,7 @@ import {
|
|||||||
RelationId,
|
RelationId,
|
||||||
} from "typeorm";
|
} from "typeorm";
|
||||||
import { Guild } from "./Guild";
|
import { Guild } from "./Guild";
|
||||||
import { Config, emitEvent, BannedWords, FieldErrors } from "../util";
|
import { Config, emitEvent, FieldErrors } from "../util";
|
||||||
import {
|
import {
|
||||||
GuildCreateEvent,
|
GuildCreateEvent,
|
||||||
GuildDeleteEvent,
|
GuildDeleteEvent,
|
||||||
@ -126,10 +126,6 @@ export class Member extends BaseClassWithoutId {
|
|||||||
if (this.nick) {
|
if (this.nick) {
|
||||||
this.nick = this.nick.split("\n").join("");
|
this.nick = this.nick.split("\n").join("");
|
||||||
this.nick = this.nick.split("\t").join("");
|
this.nick = this.nick.split("\t").join("");
|
||||||
if (BannedWords.find(this.nick))
|
|
||||||
throw FieldErrors({
|
|
||||||
nick: { message: "Bad nickname", code: "INVALID_NICKNAME" },
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ import {
|
|||||||
FieldErrors,
|
FieldErrors,
|
||||||
Snowflake,
|
Snowflake,
|
||||||
trimSpecial,
|
trimSpecial,
|
||||||
BannedWords,
|
|
||||||
adjustEmail,
|
adjustEmail,
|
||||||
} from "..";
|
} from "..";
|
||||||
import { Member, Session } from ".";
|
import { Member, Session } from ".";
|
||||||
@ -242,12 +241,6 @@ export class User extends BaseClass {
|
|||||||
});
|
});
|
||||||
this.discriminator = discrim.toString().padStart(4, "0");
|
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() {
|
toPublicUser() {
|
||||||
|
@ -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;
|
|
||||||
},
|
|
||||||
};
|
|
@ -20,4 +20,3 @@ export * from "./String";
|
|||||||
export * from "./Array";
|
export * from "./Array";
|
||||||
export * from "./TraverseDirectory";
|
export * from "./TraverseDirectory";
|
||||||
export * from "./InvisibleCharacters";
|
export * from "./InvisibleCharacters";
|
||||||
export * from "./BannedWords";
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user