mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
WIP ModActions
This commit is contained in:
parent
a3d0ec03d9
commit
ebcb28261b
25 changed files with 1162 additions and 6 deletions
78
backend/src/plugins/ModActions/commands/MuteCmd.ts
Normal file
78
backend/src/plugins/ModActions/commands/MuteCmd.ts
Normal file
|
@ -0,0 +1,78 @@
|
|||
import { modActionsCommand } from "../types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { Case } from "../../../data/entities/Case";
|
||||
import { canActOn, hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
||||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { errorMessage, resolveMember, resolveUser, stripObjectToScalars } from "../../../utils";
|
||||
import { isBanned } from "../functions/isBanned";
|
||||
import { waitForReaction } from "knub/dist/helpers";
|
||||
import { readContactMethodsFromArgs } from "../functions/readContactMethodsFromArgs";
|
||||
import { warnMember } from "../functions/warnMember";
|
||||
import { TextChannel } from "eris";
|
||||
import { actualMuteUserCmd } from "../functions/actualMuteUserCmd";
|
||||
|
||||
const opts = {
|
||||
mod: ct.member({ option: true }),
|
||||
notify: ct.string({ option: true }),
|
||||
"notify-channel": ct.textChannel({ option: true }),
|
||||
};
|
||||
|
||||
export const MuteCmd = modActionsCommand({
|
||||
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);
|
||||
if (!user) return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
|
||||
const memberToMute = await resolveMember(pluginData.client, pluginData.guild, user.id);
|
||||
|
||||
if (!memberToMute) {
|
||||
const _isBanned = await isBanned(pluginData, user.id);
|
||||
const prefix = pluginData.guildConfig.prefix;
|
||||
if (_isBanned) {
|
||||
sendErrorMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
`User is banned. Use \`${prefix}forcemute\` if you want to mute them anyway.`,
|
||||
);
|
||||
} else {
|
||||
sendErrorMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
`User is not on the server. Use \`${prefix}forcemute\` if you want to mute them anyway.`,
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 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);
|
||||
},
|
||||
});
|
44
backend/src/plugins/ModActions/commands/NoteCmd.ts
Normal file
44
backend/src/plugins/ModActions/commands/NoteCmd.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import { modActionsCommand } from "../types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { Case } from "../../../data/entities/Case";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
||||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { resolveUser, stripObjectToScalars } from "../../../utils";
|
||||
|
||||
export const NoteCmd = modActionsCommand({
|
||||
trigger: "note",
|
||||
permission: "can_note",
|
||||
description: "Add a note to the specified user",
|
||||
|
||||
signature: {
|
||||
user: ct.string(),
|
||||
note: ct.string({ catchAll: true }),
|
||||
},
|
||||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
const user = await resolveUser(pluginData.client, args.user);
|
||||
if (!user) return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
|
||||
const userName = `${user.username}#${user.discriminator}`;
|
||||
const reason = formatReasonWithAttachments(args.note, msg.attachments);
|
||||
|
||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||
const createdCase = await casesPlugin.createCase({
|
||||
userId: user.id,
|
||||
modId: msg.author.id,
|
||||
type: CaseTypes.Note,
|
||||
reason,
|
||||
});
|
||||
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_NOTE, {
|
||||
mod: stripObjectToScalars(msg.author),
|
||||
user: stripObjectToScalars(user, ["user", "roles"]),
|
||||
reason,
|
||||
});
|
||||
|
||||
sendSuccessMessage(pluginData, msg.channel, `Note added on **${userName}** (Case #${createdCase.case_number})`);
|
||||
},
|
||||
});
|
57
backend/src/plugins/ModActions/commands/UpdateCmd.ts
Normal file
57
backend/src/plugins/ModActions/commands/UpdateCmd.ts
Normal file
|
@ -0,0 +1,57 @@
|
|||
import { modActionsCommand } from "../types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { Case } from "../../../data/entities/Case";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
||||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
|
||||
export const UpdateCmd = modActionsCommand({
|
||||
trigger: "update",
|
||||
permission: "can_note",
|
||||
description:
|
||||
"Update the specified case (or, if case number is omitted, your latest case) by adding more notes/details to it",
|
||||
|
||||
signature: {
|
||||
caseNumber: ct.number(),
|
||||
note: ct.string({ required: false, catchAll: true }),
|
||||
},
|
||||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
let theCase: Case;
|
||||
if (args.caseNumber != null) {
|
||||
theCase = await pluginData.state.cases.findByCaseNumber(args.caseNumber);
|
||||
} else {
|
||||
theCase = await pluginData.state.cases.findLatestByModId(msg.author.id);
|
||||
}
|
||||
|
||||
if (!theCase) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Case not found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args.note && msg.attachments.length === 0) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Text or attachment required");
|
||||
return;
|
||||
}
|
||||
|
||||
const note = formatReasonWithAttachments(args.note, msg.attachments);
|
||||
|
||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||
await casesPlugin.createCaseNote({
|
||||
caseId: theCase.id,
|
||||
modId: msg.author.id,
|
||||
body: note,
|
||||
});
|
||||
|
||||
pluginData.state.serverLogs.log(LogType.CASE_UPDATE, {
|
||||
mod: msg.author,
|
||||
caseNumber: theCase.case_number,
|
||||
caseType: CaseTypes[theCase.type],
|
||||
note,
|
||||
});
|
||||
|
||||
sendSuccessMessage(pluginData, msg.channel, `Case \`#${theCase.case_number}\` updated`);
|
||||
},
|
||||
});
|
113
backend/src/plugins/ModActions/commands/WarnCmd.ts
Normal file
113
backend/src/plugins/ModActions/commands/WarnCmd.ts
Normal file
|
@ -0,0 +1,113 @@
|
|||
import { modActionsCommand } from "../types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { Case } from "../../../data/entities/Case";
|
||||
import { canActOn, hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { formatReasonWithAttachments } from "../functions/formatReasonWithAttachments";
|
||||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { errorMessage, resolveMember, resolveUser, stripObjectToScalars } from "../../../utils";
|
||||
import { isBanned } from "../functions/isBanned";
|
||||
import { waitForReaction } from "knub/dist/helpers";
|
||||
import { readContactMethodsFromArgs } from "../functions/readContactMethodsFromArgs";
|
||||
import { warnMember } from "../functions/warnMember";
|
||||
import { TextChannel } from "eris";
|
||||
|
||||
export const WarnCmd = modActionsCommand({
|
||||
trigger: "warn",
|
||||
permission: "can_warn",
|
||||
description: "Send a warning to the specified user",
|
||||
|
||||
signature: {
|
||||
user: ct.string(),
|
||||
reason: ct.string({ catchAll: true }),
|
||||
|
||||
mod: ct.member({ option: true }),
|
||||
notify: ct.string({ option: true }),
|
||||
"notify-channel": ct.textChannel({ option: true }),
|
||||
},
|
||||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
const user = await resolveUser(pluginData.client, args.user);
|
||||
if (!user) return sendErrorMessage(pluginData, msg.channel, `User not found`);
|
||||
|
||||
const memberToWarn = await resolveMember(pluginData.client, pluginData.guild, user.id);
|
||||
|
||||
if (!memberToWarn) {
|
||||
const _isBanned = await isBanned(pluginData, user.id);
|
||||
if (_isBanned) {
|
||||
sendErrorMessage(pluginData, msg.channel, `User is banned`);
|
||||
} else {
|
||||
sendErrorMessage(pluginData, msg.channel, `User not found on the server`);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure we're allowed to warn this member
|
||||
if (!canActOn(pluginData, msg.member, memberToWarn)) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Cannot warn: insufficient permissions");
|
||||
return;
|
||||
}
|
||||
|
||||
// The moderator who did the action is the message author or, if used, the specified -mod
|
||||
let mod = msg.member;
|
||||
if (args.mod) {
|
||||
if (!hasPermission(pluginData, "can_act_as_other", { message: msg })) {
|
||||
msg.channel.createMessage(errorMessage("No permission for -mod"));
|
||||
return;
|
||||
}
|
||||
|
||||
mod = args.mod;
|
||||
}
|
||||
|
||||
const config = pluginData.config.get();
|
||||
const reason = formatReasonWithAttachments(args.reason, msg.attachments);
|
||||
|
||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||
const priorWarnAmount = await casesPlugin.getCaseTypeAmountForUserId(memberToWarn.id, CaseTypes.Warn);
|
||||
if (config.warn_notify_enabled && priorWarnAmount >= config.warn_notify_threshold) {
|
||||
const tooManyWarningsMsg = await msg.channel.createMessage(
|
||||
config.warn_notify_message.replace("{priorWarnings}", `${priorWarnAmount}`),
|
||||
);
|
||||
|
||||
const reply = await waitForReaction(pluginData.client, tooManyWarningsMsg, ["✅", "❌"]);
|
||||
tooManyWarningsMsg.delete();
|
||||
if (!reply || reply.name === "❌") {
|
||||
msg.channel.createMessage(errorMessage("Warn cancelled by moderator"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let contactMethods;
|
||||
try {
|
||||
contactMethods = readContactMethodsFromArgs(args);
|
||||
} catch (e) {
|
||||
sendErrorMessage(pluginData, msg.channel, e.message);
|
||||
return;
|
||||
}
|
||||
|
||||
const warnResult = await warnMember(pluginData, memberToWarn, reason, {
|
||||
contactMethods,
|
||||
caseArgs: {
|
||||
modId: mod.id,
|
||||
ppId: mod.id !== msg.author.id ? msg.author.id : null,
|
||||
reason,
|
||||
},
|
||||
retryPromptChannel: msg.channel as TextChannel,
|
||||
});
|
||||
|
||||
if (warnResult.status === "failed") {
|
||||
sendErrorMessage(pluginData, msg.channel, "Failed to warn user");
|
||||
return;
|
||||
}
|
||||
|
||||
const messageResultText = warnResult.notifyResult.text ? ` (${warnResult.notifyResult.text})` : "";
|
||||
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
`Warned **${memberToWarn.user.username}#${memberToWarn.user.discriminator}** (Case #${warnResult.case.case_number})${messageResultText}`,
|
||||
);
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue