mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-11 20:55:01 +00:00
Port Mutes plugin
This commit is contained in:
parent
479cb56928
commit
ccff7384ba
11 changed files with 797 additions and 0 deletions
34
backend/src/plugins/Mutes/commands/ClearBannedMutesCmd.ts
Normal file
34
backend/src/plugins/Mutes/commands/ClearBannedMutesCmd.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { command } from "knub";
|
||||
import { MutesPluginType } from "../types";
|
||||
import { User } from "eris";
|
||||
import { sendSuccessMessage } from "../../../pluginUtils";
|
||||
|
||||
export const ClearBannedMutesCmd = command<MutesPluginType>()({
|
||||
trigger: "clear_banned_mutes",
|
||||
permission: "can_cleanup",
|
||||
description: "Clear dangling mutes for members who have been banned",
|
||||
|
||||
async run({ pluginData, message: msg }) {
|
||||
await msg.channel.createMessage("Clearing mutes from banned users...");
|
||||
|
||||
const activeMutes = await pluginData.state.mutes.getActiveMutes();
|
||||
|
||||
// Mismatch in Eris docs and actual result here, based on Eris's code comments anyway
|
||||
const bans: Array<{ reason: string; user: User }> = (await pluginData.guild.getBans()) as any;
|
||||
const bannedIds = bans.map(b => b.user.id);
|
||||
|
||||
await msg.channel.createMessage(
|
||||
`Found ${activeMutes.length} mutes and ${bannedIds.length} bans, cross-referencing...`,
|
||||
);
|
||||
|
||||
let cleared = 0;
|
||||
for (const mute of activeMutes) {
|
||||
if (bannedIds.includes(mute.user_id)) {
|
||||
await pluginData.state.mutes.clear(mute.user_id);
|
||||
cleared++;
|
||||
}
|
||||
}
|
||||
|
||||
sendSuccessMessage(pluginData, msg.channel, `Cleared ${cleared} mutes from banned users!`);
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue