2020-07-23 01:23:36 +02:00
|
|
|
import { zeppelinPlugin } from "../ZeppelinPluginBlueprint";
|
|
|
|
import { PluginOptions } from "knub";
|
|
|
|
import { ConfigSchema, CensorPluginType } from "./types";
|
|
|
|
import { GuildLogs } from "src/data/GuildLogs";
|
|
|
|
import { GuildSavedMessages } from "src/data/GuildSavedMessages";
|
|
|
|
import { onMessageCreate } from "./util/onMessageCreate";
|
|
|
|
import { onMessageUpdate } from "./util/onMessageUpdate";
|
2020-07-30 13:08:06 +03:00
|
|
|
import { trimPluginDescription } from "../../utils";
|
2020-08-05 01:15:36 +03:00
|
|
|
import { discardRegExpRunner, getRegExpRunner } from "../../regExpRunners";
|
|
|
|
import { LogsPlugin } from "../Logs/LogsPlugin";
|
2020-07-23 01:23:36 +02:00
|
|
|
|
|
|
|
const defaultOptions: PluginOptions<CensorPluginType> = {
|
|
|
|
config: {
|
|
|
|
filter_zalgo: false,
|
2020-07-30 13:08:06 +03:00
|
|
|
filter_invites: false,
|
2020-07-23 01:23:36 +02:00
|
|
|
invite_guild_whitelist: null,
|
|
|
|
invite_guild_blacklist: null,
|
|
|
|
invite_code_whitelist: null,
|
|
|
|
invite_code_blacklist: null,
|
|
|
|
allow_group_dm_invites: false,
|
|
|
|
|
|
|
|
filter_domains: false,
|
|
|
|
domain_whitelist: null,
|
|
|
|
domain_blacklist: null,
|
|
|
|
|
|
|
|
blocked_tokens: null,
|
|
|
|
blocked_words: null,
|
|
|
|
blocked_regex: null,
|
|
|
|
},
|
|
|
|
|
|
|
|
overrides: [
|
|
|
|
{
|
|
|
|
level: ">=50",
|
|
|
|
config: {
|
|
|
|
filter_zalgo: false,
|
|
|
|
filter_invites: false,
|
|
|
|
filter_domains: false,
|
|
|
|
blocked_tokens: null,
|
|
|
|
blocked_words: null,
|
|
|
|
blocked_regex: null,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
export const CensorPlugin = zeppelinPlugin<CensorPluginType>()("censor", {
|
2020-07-30 13:08:06 +03:00
|
|
|
showInDocs: true,
|
|
|
|
info: {
|
|
|
|
prettyName: "Censor",
|
|
|
|
description: trimPluginDescription(`
|
|
|
|
Censor words, tokens, links, regex, etc.
|
|
|
|
For more advanced filtering, check out the Automod plugin!
|
|
|
|
`),
|
|
|
|
},
|
|
|
|
|
2020-08-05 01:15:36 +03:00
|
|
|
dependencies: [LogsPlugin],
|
2020-07-23 01:23:36 +02:00
|
|
|
configSchema: ConfigSchema,
|
|
|
|
defaultOptions,
|
|
|
|
|
|
|
|
onLoad(pluginData) {
|
|
|
|
const { state, guild } = pluginData;
|
|
|
|
|
|
|
|
state.serverLogs = new GuildLogs(guild.id);
|
|
|
|
state.savedMessages = GuildSavedMessages.getGuildInstance(guild.id);
|
|
|
|
|
2020-08-05 01:15:36 +03:00
|
|
|
state.regexRunner = getRegExpRunner(`guild-${pluginData.guild.id}`);
|
|
|
|
|
2020-07-23 01:23:36 +02:00
|
|
|
state.onMessageCreateFn = msg => onMessageCreate(pluginData, msg);
|
|
|
|
state.savedMessages.events.on("create", state.onMessageCreateFn);
|
|
|
|
|
|
|
|
state.onMessageUpdateFn = msg => onMessageUpdate(pluginData, msg);
|
|
|
|
state.savedMessages.events.on("update", state.onMessageUpdateFn);
|
|
|
|
},
|
|
|
|
|
|
|
|
onUnload(pluginData) {
|
2020-08-05 01:15:36 +03:00
|
|
|
discardRegExpRunner(`guild-${pluginData.guild.id}`);
|
|
|
|
|
2020-07-23 01:23:36 +02:00
|
|
|
pluginData.state.savedMessages.events.off("create", pluginData.state.onMessageCreateFn);
|
|
|
|
pluginData.state.savedMessages.events.off("update", pluginData.state.onMessageUpdateFn);
|
|
|
|
},
|
|
|
|
});
|