3
0
Fork 0
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:
Dragory 2020-07-22 22:08:59 +03:00
parent 479cb56928
commit ccff7384ba
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
11 changed files with 797 additions and 0 deletions

View 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!`);
},
});