3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-06-08 00:05:01 +00:00

Fixes, refactoring and PR feedback

This commit is contained in:
Lily Bergonzat 2024-04-15 15:51:45 +02:00
parent 0be54912c4
commit 893a77d562
202 changed files with 1037 additions and 1069 deletions

View file

@ -9,6 +9,7 @@ import { VoiceStateUpdateAlertEvt } from "./events/SendAlertsEvts";
import { LocateUserPluginType, zLocateUserConfig } from "./types";
import { clearExpiredAlert } from "./utils/clearExpiredAlert";
import { fillActiveAlertsList } from "./utils/fillAlertsList";
import { CommonPlugin } from "../Common/CommonPlugin";
const defaultOptions: PluginOptions<LocateUserPluginType> = {
config: {
@ -53,6 +54,10 @@ export const LocateUserPlugin = guildPlugin<LocateUserPluginType>()({
state.usersWithAlerts = [];
},
beforeStart(pluginData) {
pluginData.state.common = pluginData.getPlugin(CommonPlugin);
},
afterLoad(pluginData) {
const { state, guild } = pluginData;

View file

@ -27,9 +27,7 @@ export const FollowCmd = locateUserCmd({
const active = args.active || false;
if (time < 30 * SECONDS) {
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(msg, "Sorry, but the minimum duration for an alert is 30 seconds!");
void pluginData.state.common.sendErrorMessage(msg, "Sorry, but the minimum duration for an alert is 30 seconds!");
return;
}
@ -48,18 +46,14 @@ export const FollowCmd = locateUserCmd({
}
if (active) {
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(
void pluginData.state.common.sendSuccessMessage(
msg,
`Every time <@${args.member.id}> joins or switches VC in the next ${humanizeDuration(
time,
)} i will notify and move you.\nPlease make sure to be in a voice channel, otherwise i cannot move you!`,
);
} else {
pluginData
.getPlugin(CommonPlugin)
.sendSuccessMessage(
void pluginData.state.common.sendSuccessMessage(
msg,
`Every time <@${args.member.id}> joins or switches VC in the next ${humanizeDuration(
time,

View file

@ -13,7 +13,7 @@ export const ListFollowCmd = locateUserCmd({
async run({ message: msg, pluginData }) {
const alerts = await pluginData.state.alerts.getAlertsByRequestorId(msg.member.id);
if (alerts.length === 0) {
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You have no active alerts!");
void pluginData.state.common.sendErrorMessage(msg, "You have no active alerts!");
return;
}
@ -46,7 +46,7 @@ export const DeleteFollowCmd = locateUserCmd({
alerts.sort(sorter("expires_at"));
if (args.num > alerts.length || args.num <= 0) {
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Unknown alert!");
void pluginData.state.common.sendErrorMessage(msg, "Unknown alert!");
return;
}
@ -54,6 +54,6 @@ export const DeleteFollowCmd = locateUserCmd({
clearExpiringVCAlert(toDelete);
await pluginData.state.alerts.delete(toDelete.id);
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, "Alert deleted");
void pluginData.state.common.sendSuccessMessage(msg, "Alert deleted");
},
});

View file

@ -1,6 +1,7 @@
import { BasePluginType, guildPluginEventListener, guildPluginMessageCommand } from "knub";
import { BasePluginType, guildPluginEventListener, guildPluginMessageCommand, pluginUtils } from "knub";
import z from "zod";
import { GuildVCAlerts } from "../../data/GuildVCAlerts";
import { CommonPlugin } from "../Common/CommonPlugin";
export const zLocateUserConfig = z.strictObject({
can_where: z.boolean(),
@ -13,6 +14,7 @@ export interface LocateUserPluginType extends BasePluginType {
alerts: GuildVCAlerts;
usersWithAlerts: string[];
unregisterGuildEventListener: () => void;
common: pluginUtils.PluginPublicInterface<typeof CommonPlugin>;
};
}

View file

@ -16,14 +16,10 @@ export async function moveMember(
channel: target.voice.channelId,
});
} catch {
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(errorChannel, "Failed to move you. Are you in a voice channel?");
void pluginData.state.common.sendErrorMessage(errorChannel, "Failed to move you. Are you in a voice channel?");
return;
}
} else {
pluginData
.getPlugin(CommonPlugin)
.sendErrorMessage(errorChannel, "Failed to move you. Are you in a voice channel?");
void pluginData.state.common.sendErrorMessage(errorChannel, "Failed to move you. Are you in a voice channel?");
}
}

View file

@ -22,7 +22,7 @@ export async function sendWhere(
try {
invite = await createOrReuseInvite(voice);
} catch {
pluginData.getPlugin(CommonPlugin).sendErrorMessage(channel, "Cannot create an invite to that channel!");
void pluginData.state.common.sendErrorMessage(channel, "Cannot create an invite to that channel!");
return;
}
channel.send({