3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-25 18:25:03 +00:00
zeppelin/backend/src/plugins/LocateUser/LocateUserPlugin.ts
Dragory 076d69b989 Centralize periodic checks for mutes, tempbans, vcalerts, reminders, and scheduled posts
This should result in a significant performance improvement.
The new method is also more precise than the old one, allowing
the aforementioned checks to be performed with second-precision.
2021-09-25 21:34:07 +03:00

77 lines
2.2 KiB
TypeScript

import { PluginOptions } from "knub";
import { GuildVCAlerts } from "../../data/GuildVCAlerts";
import { trimPluginDescription } from "../../utils";
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
import { FollowCmd } from "./commands/FollowCmd";
import { DeleteFollowCmd, ListFollowCmd } from "./commands/ListFollowCmd";
import { WhereCmd } from "./commands/WhereCmd";
import { GuildBanRemoveAlertsEvt } from "./events/BanRemoveAlertsEvt";
import { VoiceStateUpdateAlertEvt } from "./events/SendAlertsEvts";
import { ConfigSchema, LocateUserPluginType } from "./types";
import { fillActiveAlertsList } from "./utils/fillAlertsList";
import { onGuildEvent } from "../../data/GuildEvents";
import { clearExpiredAlert } from "./utils/clearExpiredAlert";
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",
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: [
WhereCmd,
FollowCmd,
ListFollowCmd,
DeleteFollowCmd,
],
// prettier-ignore
events: [
VoiceStateUpdateAlertEvt,
GuildBanRemoveAlertsEvt
],
beforeLoad(pluginData) {
const { state, guild } = pluginData;
state.alerts = GuildVCAlerts.getGuildInstance(guild.id);
state.usersWithAlerts = [];
},
afterLoad(pluginData) {
pluginData.state.unregisterGuildEventListener = onGuildEvent(pluginData.guild.id, "expiredVCAlert", (alert) =>
clearExpiredAlert(pluginData, alert),
);
fillActiveAlertsList(pluginData);
},
beforeUnload(pluginData) {
pluginData.state.unregisterGuildEventListener();
},
});