3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-19 07:20:00 +00:00
zeppelin/backend/src/plugins/Mutes/commands/ClearMutesCmd.ts

40 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-07-22 22:08:59 +03:00
import { command } from "knub";
import { MutesPluginType } from "../types";
import { User } from "eris";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { commandTypeHelpers as ct } from "../../../commandTypes";
export const ClearMutesCmd = command<MutesPluginType>()({
trigger: "clear_mutes",
permission: "can_cleanup",
description: "Clear dangling mute records from the bot. Be careful not to clear valid mutes.",
signature: {
userIds: ct.string({ rest: true }),
},
async run({ pluginData, message: msg, args }) {
const failed = [];
for (const id of args.userIds) {
const mute = await pluginData.state.mutes.findExistingMuteForUserId(id);
if (!mute) {
failed.push(id);
continue;
}
await pluginData.state.mutes.clear(id);
}
if (failed.length !== args.userIds.length) {
sendSuccessMessage(pluginData, msg.channel, `**${args.userIds.length - failed.length} active mute(s) cleared**`);
}
if (failed.length) {
sendErrorMessage(
pluginData,
msg.channel,
`**${failed.length}/${args.userIds.length} IDs failed**, they are not muted: ${failed.join(" ")}`,
);
}
},
});