2020-10-01 01:43:38 +03:00
|
|
|
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
2020-07-23 00:25:40 +02:00
|
|
|
import { PluginOptions } from "knub";
|
2020-08-09 16:58:36 +03:00
|
|
|
import { ConfigSchema, SlowmodePluginType } from "./types";
|
2020-10-01 01:43:38 +03:00
|
|
|
import { GuildSlowmodes } from "../../data/GuildSlowmodes";
|
|
|
|
import { GuildSavedMessages } from "../../data/GuildSavedMessages";
|
|
|
|
import { GuildLogs } from "../../data/GuildLogs";
|
|
|
|
import { SECONDS } from "../../utils";
|
2020-07-23 00:25:40 +02:00
|
|
|
import { onMessageCreate } from "./util/onMessageCreate";
|
|
|
|
import { clearExpiredSlowmodes } from "./util/clearExpiredSlowmodes";
|
|
|
|
import { SlowmodeDisableCmd } from "./commands/SlowmodeDisableCmd";
|
|
|
|
import { SlowmodeClearCmd } from "./commands/SlowmodeClearCmd";
|
|
|
|
import { SlowmodeListCmd } from "./commands/SlowmodeListCmd";
|
2020-08-09 16:58:36 +03:00
|
|
|
import { SlowmodeGetCmd } from "./commands/SlowmodeGetCmd";
|
|
|
|
import { SlowmodeSetCmd } from "./commands/SlowmodeSetCmd";
|
|
|
|
import { LogsPlugin } from "../Logs/LogsPlugin";
|
2020-07-23 00:25:40 +02:00
|
|
|
|
|
|
|
const BOT_SLOWMODE_CLEAR_INTERVAL = 60 * SECONDS;
|
|
|
|
|
|
|
|
const defaultOptions: PluginOptions<SlowmodePluginType> = {
|
|
|
|
config: {
|
|
|
|
use_native_slowmode: true,
|
|
|
|
|
|
|
|
can_manage: false,
|
|
|
|
is_affected: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
overrides: [
|
|
|
|
{
|
|
|
|
level: ">=50",
|
|
|
|
config: {
|
|
|
|
can_manage: true,
|
|
|
|
is_affected: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2021-05-23 14:35:16 +03:00
|
|
|
export const SlowmodePlugin = zeppelinGuildPlugin<SlowmodePluginType>()({
|
|
|
|
name: "slowmode",
|
2020-07-30 13:08:06 +03:00
|
|
|
showInDocs: true,
|
|
|
|
info: {
|
|
|
|
prettyName: "Slowmode",
|
|
|
|
},
|
|
|
|
|
2020-08-09 16:58:36 +03:00
|
|
|
dependencies: [LogsPlugin],
|
2020-07-23 00:25:40 +02:00
|
|
|
configSchema: ConfigSchema,
|
|
|
|
defaultOptions,
|
|
|
|
|
|
|
|
// prettier-ignore
|
|
|
|
commands: [
|
|
|
|
SlowmodeDisableCmd,
|
|
|
|
SlowmodeClearCmd,
|
|
|
|
SlowmodeListCmd,
|
2020-08-09 16:58:36 +03:00
|
|
|
SlowmodeGetCmd,
|
|
|
|
SlowmodeSetCmd,
|
2020-07-23 00:25:40 +02:00
|
|
|
],
|
|
|
|
|
2021-05-23 14:35:16 +03:00
|
|
|
afterLoad(pluginData) {
|
2020-07-23 00:25:40 +02:00
|
|
|
const { state, guild } = pluginData;
|
|
|
|
|
|
|
|
state.slowmodes = GuildSlowmodes.getGuildInstance(guild.id);
|
|
|
|
state.savedMessages = GuildSavedMessages.getGuildInstance(guild.id);
|
|
|
|
state.logs = new GuildLogs(guild.id);
|
|
|
|
state.clearInterval = setInterval(() => clearExpiredSlowmodes(pluginData), BOT_SLOWMODE_CLEAR_INTERVAL);
|
|
|
|
|
|
|
|
state.onMessageCreateFn = msg => onMessageCreate(pluginData, msg);
|
|
|
|
state.savedMessages.events.on("create", state.onMessageCreateFn);
|
|
|
|
},
|
|
|
|
|
2021-05-23 14:35:16 +03:00
|
|
|
beforeUnload(pluginData) {
|
2020-07-23 00:25:40 +02:00
|
|
|
pluginData.state.savedMessages.events.off("create", pluginData.state.onMessageCreateFn);
|
|
|
|
},
|
|
|
|
});
|