3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

Allow hidecase, unhidecase and deletecase to take multiple case numbers

This commit is contained in:
Dark 2020-10-12 14:48:54 +02:00
parent dda4313b26
commit 52ee007770
3 changed files with 116 additions and 52 deletions

View file

@ -9,18 +9,37 @@ export const UnhideCaseCmd = modActionsCmd({
signature: [
{
caseNum: ct.number(),
caseNum: ct.number({ rest: true }),
},
],
async run({ pluginData, message: msg, args }) {
const theCase = await pluginData.state.cases.findByCaseNumber(args.caseNum);
if (!theCase) {
sendErrorMessage(pluginData, msg.channel, "Case not found!");
return;
const failed = [];
for (const num of args.caseNum) {
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);
sendSuccessMessage(pluginData, msg.channel, `Case #${theCase.case_number} is no longer hidden!`);
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(
pluginData,
msg.channel,
`${amt} case${amt === 1 ? " is" : "s are"} no longer hidden!${failedAddendum}`,
);
},
});