mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 14:11:50 +00:00
Allow hidecase, unhidecase and deletecase to take multiple case numbers
This commit is contained in:
parent
dda4313b26
commit
52ee007770
3 changed files with 116 additions and 52 deletions
|
@ -19,57 +19,87 @@ export const DeleteCaseCmd = modActionsCmd({
|
||||||
`),
|
`),
|
||||||
|
|
||||||
signature: {
|
signature: {
|
||||||
caseNumber: ct.number(),
|
caseNumber: ct.number({ rest: true }),
|
||||||
|
|
||||||
force: ct.switchOption({ shortcut: "f" }),
|
force: ct.switchOption({ shortcut: "f" }),
|
||||||
},
|
},
|
||||||
|
|
||||||
async run({ pluginData, message, args }) {
|
async run({ pluginData, message, args }) {
|
||||||
const theCase = await pluginData.state.cases.findByCaseNumber(args.caseNumber);
|
const failed = [];
|
||||||
if (!theCase) {
|
const validCases = [];
|
||||||
sendErrorMessage(pluginData, message.channel, "Case not found");
|
let cancelled = 0;
|
||||||
|
|
||||||
|
for (const num of args.caseNumber) {
|
||||||
|
const theCase = await pluginData.state.cases.findByCaseNumber(num);
|
||||||
|
if (!theCase) {
|
||||||
|
failed.push(num);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
validCases.push(theCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failed.length === args.caseNumber.length) {
|
||||||
|
sendErrorMessage(pluginData, message.channel, "None of the cases were found!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!args.force) {
|
for (const theCase of validCases) {
|
||||||
const cases = pluginData.getPlugin(CasesPlugin);
|
if (!args.force) {
|
||||||
const embedContent = await cases.getCaseEmbed(theCase);
|
const cases = pluginData.getPlugin(CasesPlugin);
|
||||||
message.channel.createMessage({
|
const embedContent = await cases.getCaseEmbed(theCase);
|
||||||
content: "Delete the following case? Answer 'Yes' to continue, 'No' to cancel.",
|
message.channel.createMessage({
|
||||||
embed: embedContent.embed,
|
content: "Delete the following case? Answer 'Yes' to continue, 'No' to cancel.",
|
||||||
});
|
embed: embedContent.embed,
|
||||||
|
});
|
||||||
|
|
||||||
const reply = await helpers.waitForReply(
|
const reply = await helpers.waitForReply(
|
||||||
pluginData.client,
|
pluginData.client,
|
||||||
message.channel as TextChannel,
|
message.channel as TextChannel,
|
||||||
message.author.id,
|
message.author.id,
|
||||||
15 * SECONDS,
|
15 * SECONDS,
|
||||||
);
|
);
|
||||||
const normalizedReply = (reply?.content || "").toLowerCase().trim();
|
const normalizedReply = (reply?.content || "").toLowerCase().trim();
|
||||||
if (normalizedReply !== "yes" && normalizedReply !== "y") {
|
if (normalizedReply !== "yes" && normalizedReply !== "y") {
|
||||||
message.channel.createMessage("Cancelled. Case was not deleted.");
|
message.channel.createMessage("Cancelled. Case was not deleted.");
|
||||||
return;
|
cancelled++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deletedByName = `${message.author.username}#${message.author.discriminator}`;
|
||||||
|
|
||||||
|
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
||||||
|
const deletedAt = timeAndDate.inGuildTz().format(timeAndDate.getDateFormat("pretty_datetime"));
|
||||||
|
|
||||||
|
await pluginData.state.cases.softDelete(
|
||||||
|
theCase.id,
|
||||||
|
message.author.id,
|
||||||
|
deletedByName,
|
||||||
|
`Case deleted by **${deletedByName}** (\`${message.author.id}\`) on ${deletedAt}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const logs = pluginData.getPlugin(LogsPlugin);
|
||||||
|
logs.log(LogType.CASE_DELETE, {
|
||||||
|
mod: stripObjectToScalars(message.member, ["user", "roles"]),
|
||||||
|
case: stripObjectToScalars(theCase),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const deletedByName = `${message.author.username}#${message.author.discriminator}`;
|
const failedAddendum =
|
||||||
|
failed.length > 0
|
||||||
|
? `\nThe following cases were not found: ${failed.toString().replace(new RegExp(",", "g"), ", ")}`
|
||||||
|
: "";
|
||||||
|
const amt = validCases.length - cancelled;
|
||||||
|
if (amt === 0) {
|
||||||
|
sendErrorMessage(pluginData, message.channel, "All deletions were cancelled, no cases were deleted.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
sendSuccessMessage(
|
||||||
const deletedAt = timeAndDate.inGuildTz().format(timeAndDate.getDateFormat("pretty_datetime"));
|
pluginData,
|
||||||
|
message.channel,
|
||||||
await pluginData.state.cases.softDelete(
|
`${amt} case${amt === 1 ? " was" : "s were"} deleted!${failedAddendum}`,
|
||||||
theCase.id,
|
|
||||||
message.author.id,
|
|
||||||
deletedByName,
|
|
||||||
`Case deleted by **${deletedByName}** (\`${message.author.id}\`) on ${deletedAt}`,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const logs = pluginData.getPlugin(LogsPlugin);
|
|
||||||
logs.log(LogType.CASE_DELETE, {
|
|
||||||
mod: stripObjectToScalars(message.member, ["user", "roles"]),
|
|
||||||
case: stripObjectToScalars(theCase),
|
|
||||||
});
|
|
||||||
|
|
||||||
sendSuccessMessage(pluginData, message.channel, `Case #${theCase.case_number} deleted!`);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,22 +9,37 @@ export const HideCaseCmd = modActionsCmd({
|
||||||
|
|
||||||
signature: [
|
signature: [
|
||||||
{
|
{
|
||||||
caseNum: ct.number(),
|
caseNum: ct.number({ rest: true }),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
async run({ pluginData, message: msg, args }) {
|
async run({ pluginData, message: msg, args }) {
|
||||||
const theCase = await pluginData.state.cases.findByCaseNumber(args.caseNum);
|
const failed = [];
|
||||||
if (!theCase) {
|
|
||||||
sendErrorMessage(pluginData, msg.channel, "Case not found!");
|
for (const num of args.caseNum) {
|
||||||
return;
|
const theCase = await pluginData.state.cases.findByCaseNumber(num);
|
||||||
|
if (!theCase) {
|
||||||
|
failed.push(num);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
await pluginData.state.cases.setHidden(theCase.id, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
await pluginData.state.cases.setHidden(theCase.id, true);
|
if (failed.length === args.caseNum.length) {
|
||||||
|
sendErrorMessage(pluginData, msg.channel, "None of the cases were found!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const failedAddendum =
|
||||||
|
failed.length > 0
|
||||||
|
? `\nThe following cases were not found: ${failed.toString().replace(new RegExp(",", "g"), ", ")}`
|
||||||
|
: "";
|
||||||
|
|
||||||
|
const amt = args.caseNum.length - failed.length;
|
||||||
sendSuccessMessage(
|
sendSuccessMessage(
|
||||||
pluginData,
|
pluginData,
|
||||||
msg.channel,
|
msg.channel,
|
||||||
`Case #${theCase.case_number} is now hidden! Use \`unhidecase\` to unhide it.`,
|
`${amt} case${amt === 1 ? " is" : "s are"} now hidden! Use \`unhidecase\` to unhide them.${failedAddendum}`,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,18 +9,37 @@ export const UnhideCaseCmd = modActionsCmd({
|
||||||
|
|
||||||
signature: [
|
signature: [
|
||||||
{
|
{
|
||||||
caseNum: ct.number(),
|
caseNum: ct.number({ rest: true }),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
async run({ pluginData, message: msg, args }) {
|
async run({ pluginData, message: msg, args }) {
|
||||||
const theCase = await pluginData.state.cases.findByCaseNumber(args.caseNum);
|
const failed = [];
|
||||||
if (!theCase) {
|
|
||||||
sendErrorMessage(pluginData, msg.channel, "Case not found!");
|
for (const num of args.caseNum) {
|
||||||
return;
|
const theCase = await pluginData.state.cases.findByCaseNumber(num);
|
||||||
|
if (!theCase) {
|
||||||
|
failed.push(num);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
await pluginData.state.cases.setHidden(theCase.id, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
await pluginData.state.cases.setHidden(theCase.id, false);
|
if (failed.length === args.caseNum.length) {
|
||||||
sendSuccessMessage(pluginData, msg.channel, `Case #${theCase.case_number} is no longer hidden!`);
|
sendErrorMessage(pluginData, msg.channel, "None of the cases were found!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const failedAddendum =
|
||||||
|
failed.length > 0
|
||||||
|
? `\nThe following cases were not found: ${failed.toString().replace(new RegExp(",", "g"), ", ")}`
|
||||||
|
: "";
|
||||||
|
|
||||||
|
const amt = args.caseNum.length - failed.length;
|
||||||
|
sendSuccessMessage(
|
||||||
|
pluginData,
|
||||||
|
msg.channel,
|
||||||
|
`${amt} case${amt === 1 ? " is" : "s are"} no longer hidden!${failedAddendum}`,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue