mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
59 lines
2.1 KiB
TypeScript
59 lines
2.1 KiB
TypeScript
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
|
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
|
import { slowmodeCmd } from "../types";
|
|
import { clearBotSlowmodeFromUserId } from "../util/clearBotSlowmodeFromUserId";
|
|
import { asSingleLine, disableInlineCode } from "../../../utils";
|
|
import { getMissingChannelPermissions } from "../../../utils/getMissingChannelPermissions";
|
|
import { BOT_SLOWMODE_CLEAR_PERMISSIONS } from "../requiredPermissions";
|
|
import { missingPermissionError } from "../../../utils/missingPermissionError";
|
|
|
|
export const SlowmodeClearCmd = slowmodeCmd({
|
|
trigger: ["slowmode clear", "slowmode c"],
|
|
permission: "can_manage",
|
|
|
|
signature: {
|
|
channel: ct.textChannel(),
|
|
user: ct.resolvedUserLoose(),
|
|
|
|
force: ct.bool({ option: true, isSwitch: true }),
|
|
},
|
|
|
|
async run({ message: msg, args, pluginData }) {
|
|
const channelSlowmode = await pluginData.state.slowmodes.getChannelSlowmode(args.channel.id);
|
|
if (!channelSlowmode) {
|
|
sendErrorMessage(pluginData, msg.channel, "Channel doesn't have slowmode!");
|
|
return;
|
|
}
|
|
|
|
const me = pluginData.guild.members.cache.get(pluginData.client.user!.id)!;
|
|
const missingPermissions = getMissingChannelPermissions(me, args.channel, BOT_SLOWMODE_CLEAR_PERMISSIONS);
|
|
if (missingPermissions) {
|
|
sendErrorMessage(
|
|
pluginData,
|
|
msg.channel,
|
|
`Unable to clear slowmode. ${missingPermissionError(missingPermissions)}`,
|
|
);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await clearBotSlowmodeFromUserId(pluginData, args.channel, args.user.id, args.force);
|
|
} catch (e) {
|
|
sendErrorMessage(
|
|
pluginData,
|
|
msg.channel,
|
|
asSingleLine(`
|
|
Failed to clear slowmode from **${args.user.username}#${args.user.discriminator}** in <#${args.channel.id}>:
|
|
\`${disableInlineCode(e.message)}\`
|
|
`),
|
|
);
|
|
return;
|
|
}
|
|
|
|
sendSuccessMessage(
|
|
pluginData,
|
|
msg.channel,
|
|
`Slowmode cleared from **${args.user.username}#${args.user.discriminator}** in <#${args.channel.id}>`,
|
|
);
|
|
},
|
|
});
|