2020-07-16 22:54:02 +02:00
|
|
|
import { PluginOptions } from "knub";
|
2020-10-01 01:43:38 +03:00
|
|
|
import { GuildReminders } from "../../data/GuildReminders";
|
2021-06-06 23:51:32 +02:00
|
|
|
import { TimeAndDatePlugin } from "../TimeAndDate/TimeAndDatePlugin";
|
|
|
|
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
2020-07-16 22:54:02 +02:00
|
|
|
import { RemindCmd } from "./commands/RemindCmd";
|
|
|
|
import { RemindersCmd } from "./commands/RemindersCmd";
|
|
|
|
import { RemindersDeleteCmd } from "./commands/RemindersDeleteCmd";
|
2021-06-06 23:51:32 +02:00
|
|
|
import { ConfigSchema, RemindersPluginType } from "./types";
|
|
|
|
import { postDueRemindersLoop } from "./utils/postDueRemindersLoop";
|
2020-07-16 22:54:02 +02:00
|
|
|
|
|
|
|
const defaultOptions: PluginOptions<RemindersPluginType> = {
|
|
|
|
config: {
|
|
|
|
can_use: false,
|
|
|
|
},
|
|
|
|
overrides: [
|
|
|
|
{
|
|
|
|
level: ">=50",
|
|
|
|
config: {
|
|
|
|
can_use: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2021-05-23 14:35:16 +03:00
|
|
|
export const RemindersPlugin = zeppelinGuildPlugin<RemindersPluginType>()({
|
|
|
|
name: "reminders",
|
2020-07-30 13:08:06 +03:00
|
|
|
showInDocs: true,
|
|
|
|
info: {
|
|
|
|
prettyName: "Reminders",
|
|
|
|
},
|
|
|
|
|
2020-08-19 00:19:12 +03:00
|
|
|
dependencies: [TimeAndDatePlugin],
|
2020-07-16 22:54:02 +02:00
|
|
|
configSchema: ConfigSchema,
|
|
|
|
defaultOptions,
|
|
|
|
|
|
|
|
// prettier-ignore
|
|
|
|
commands: [
|
|
|
|
RemindCmd,
|
|
|
|
RemindersCmd,
|
|
|
|
RemindersDeleteCmd,
|
|
|
|
],
|
|
|
|
|
2021-05-23 17:13:11 +03:00
|
|
|
beforeLoad(pluginData) {
|
2020-07-16 22:54:02 +02:00
|
|
|
const { state, guild } = pluginData;
|
|
|
|
|
|
|
|
state.reminders = GuildReminders.getGuildInstance(guild.id);
|
|
|
|
state.tries = new Map();
|
|
|
|
state.unloaded = false;
|
|
|
|
|
|
|
|
state.postRemindersTimeout = null;
|
2021-05-23 17:13:11 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
afterLoad(pluginData) {
|
2020-07-16 22:54:02 +02:00
|
|
|
postDueRemindersLoop(pluginData);
|
|
|
|
},
|
|
|
|
|
2021-05-23 14:35:16 +03:00
|
|
|
beforeUnload(pluginData) {
|
2020-07-16 22:54:02 +02:00
|
|
|
clearTimeout(pluginData.state.postRemindersTimeout);
|
|
|
|
pluginData.state.unloaded = true;
|
|
|
|
},
|
|
|
|
});
|