2020-10-01 01:43:38 +03:00
|
|
|
import { modActionsCmd } from "../types";
|
2020-07-23 00:37:33 +03:00
|
|
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
2021-06-02 04:07:50 +02:00
|
|
|
import { canActOn, sendErrorMessage } from "../../../pluginUtils";
|
|
|
|
import { noop, resolveMember, resolveUser } from "../../../utils";
|
2020-07-23 00:37:33 +03:00
|
|
|
import { isBanned } from "../functions/isBanned";
|
2021-06-01 02:05:55 +02:00
|
|
|
|
2020-07-23 00:37:33 +03:00
|
|
|
import { actualMuteUserCmd } from "../functions/actualMuteUserCmd";
|
2021-06-02 23:41:05 +02:00
|
|
|
import { waitForButtonConfirm } from "../../../utils/waitForInteraction";
|
2020-07-23 00:37:33 +03:00
|
|
|
|
|
|
|
const opts = {
|
|
|
|
mod: ct.member({ option: true }),
|
|
|
|
notify: ct.string({ option: true }),
|
|
|
|
"notify-channel": ct.textChannel({ option: true }),
|
|
|
|
};
|
|
|
|
|
2020-10-01 01:43:38 +03:00
|
|
|
export const MuteCmd = modActionsCmd({
|
2020-07-23 00:37:33 +03:00
|
|
|
trigger: "mute",
|
|
|
|
permission: "can_mute",
|
|
|
|
description: "Mute the specified member",
|
|
|
|
|
|
|
|
signature: [
|
|
|
|
{
|
|
|
|
user: ct.string(),
|
|
|
|
time: ct.delay(),
|
|
|
|
reason: ct.string({ required: false, catchAll: true }),
|
|
|
|
|
|
|
|
...opts,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
user: ct.string(),
|
|
|
|
reason: ct.string({ required: false, catchAll: true }),
|
|
|
|
|
|
|
|
...opts,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
|
|
|
async run({ pluginData, message: msg, args }) {
|
|
|
|
const user = await resolveUser(pluginData.client, args.user);
|
2020-12-17 04:12:49 +02:00
|
|
|
if (!user.id) {
|
2021-01-17 21:21:18 +02:00
|
|
|
sendErrorMessage(pluginData, msg.channel, `User not found`);
|
|
|
|
return;
|
2020-12-17 04:12:49 +02:00
|
|
|
}
|
2020-07-23 00:37:33 +03:00
|
|
|
|
|
|
|
const memberToMute = await resolveMember(pluginData.client, pluginData.guild, user.id);
|
|
|
|
|
|
|
|
if (!memberToMute) {
|
|
|
|
const _isBanned = await isBanned(pluginData, user.id);
|
2020-10-01 01:43:38 +03:00
|
|
|
const prefix = pluginData.fullConfig.prefix;
|
2020-07-23 00:37:33 +03:00
|
|
|
if (_isBanned) {
|
|
|
|
sendErrorMessage(
|
|
|
|
pluginData,
|
|
|
|
msg.channel,
|
|
|
|
`User is banned. Use \`${prefix}forcemute\` if you want to mute them anyway.`,
|
|
|
|
);
|
2021-04-02 15:53:09 +02:00
|
|
|
return;
|
2020-07-23 00:37:33 +03:00
|
|
|
} else {
|
2021-04-02 15:53:09 +02:00
|
|
|
// Ask the mod if we should upgrade to a forcemute as the user is not on the server
|
2021-06-02 23:41:05 +02:00
|
|
|
const reply = await waitForButtonConfirm(
|
|
|
|
msg.channel,
|
|
|
|
{ content: "User not found on the server, forcemute instead?" },
|
|
|
|
{ confirmText: "Yes", cancelText: "No", restrictToId: msg.member.id },
|
|
|
|
);
|
2020-07-23 00:37:33 +03:00
|
|
|
|
2021-06-02 23:41:05 +02:00
|
|
|
if (!reply) {
|
2021-04-02 15:53:09 +02:00
|
|
|
sendErrorMessage(pluginData, msg.channel, "User not on server, mute cancelled by moderator");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-07-23 00:37:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we're allowed to mute this member
|
|
|
|
if (memberToMute && !canActOn(pluginData, msg.member, memberToMute)) {
|
|
|
|
sendErrorMessage(pluginData, msg.channel, "Cannot mute: insufficient permissions");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
actualMuteUserCmd(pluginData, user, msg, args);
|
|
|
|
},
|
|
|
|
});
|