zappyzep/backend/src/plugins/LocateUser/LocateUserPlugin.ts

79 lines
2.2 KiB
TypeScript
Raw Normal View History

import { PluginOptions } from "knub";
import { ConfigSchema, LocateUserPluginType } from "./types";
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
import { GuildVCAlerts } from "../../data/GuildVCAlerts";
import { outdatedAlertsLoop } from "./utils/outdatedLoop";
import { fillActiveAlertsList } from "./utils/fillAlertsList";
import { WhereCmd } from "./commands/WhereCmd";
import { FollowCmd } from "./commands/FollowCmd";
import { DeleteFollowCmd, ListFollowCmd } from "./commands/ListFollowCmd";
import { ChannelJoinAlertsEvt, ChannelLeaveAlertsEvt, ChannelSwitchAlertsEvt } from "./events/SendAlertsEvts";
import { GuildBanRemoveAlertsEvt } from "./events/BanRemoveAlertsEvt";
2020-07-30 13:08:06 +03:00
import { trimPluginDescription } from "../../utils";
import Timeout = NodeJS.Timeout;
const defaultOptions: PluginOptions<LocateUserPluginType> = {
config: {
can_where: false,
can_alert: false,
},
overrides: [
{
level: ">=50",
config: {
can_where: true,
can_alert: true,
},
},
],
};
export const LocateUserPlugin = zeppelinGuildPlugin<LocateUserPluginType>()({
name: "locate_user",
2020-07-30 13:08:06 +03:00
showInDocs: true,
info: {
prettyName: "Locate user",
description: trimPluginDescription(`
This plugin allows users with access to the commands the following:
* Instantly receive an invite to the voice channel of a user
* Be notified as soon as a user switches or joins a voice channel
`),
},
configSchema: ConfigSchema,
defaultOptions,
// prettier-ignore
commands: [
2020-07-08 03:01:14 +02:00
WhereCmd,
FollowCmd,
ListFollowCmd,
DeleteFollowCmd,
],
2020-07-08 03:01:14 +02:00
// prettier-ignore
events: [
ChannelJoinAlertsEvt,
ChannelSwitchAlertsEvt,
ChannelLeaveAlertsEvt,
GuildBanRemoveAlertsEvt
2020-07-08 03:01:14 +02:00
],
afterLoad(pluginData) {
const { state, guild } = pluginData;
state.alerts = GuildVCAlerts.getGuildInstance(guild.id);
state.outdatedAlertsTimeout = null;
state.usersWithAlerts = [];
state.unloaded = false;
outdatedAlertsLoop(pluginData);
fillActiveAlertsList(pluginData);
},
beforeUnload(pluginData) {
clearTimeout(pluginData.state.outdatedAlertsTimeout as Timeout);
pluginData.state.unloaded = true;
},
});