From a7efa1d728eb87bc7ba75f2a03f04cbe79933313 Mon Sep 17 00:00:00 2001 From: Dark <7890309+DarkView@users.noreply.github.com> Date: Fri, 19 Mar 2021 01:56:48 +0100 Subject: [PATCH] Allow filtering !cases to certain types using switches in args --- .../ModActions/commands/CasesUserCmd.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/backend/src/plugins/ModActions/commands/CasesUserCmd.ts b/backend/src/plugins/ModActions/commands/CasesUserCmd.ts index 12fdf125..2c15e392 100644 --- a/backend/src/plugins/ModActions/commands/CasesUserCmd.ts +++ b/backend/src/plugins/ModActions/commands/CasesUserCmd.ts @@ -15,10 +15,17 @@ import { getGuildPrefix } from "../../../utils/getGuildPrefix"; import { EmbedOptions, User } from "eris"; import { getChunkedEmbedFields } from "../../../utils/getChunkedEmbedFields"; import { asyncMap } from "../../../utils/async"; +import { CaseTypes } from "../../../data/CaseTypes"; const opts = { expand: ct.bool({ option: true, isSwitch: true, shortcut: "e" }), hidden: ct.bool({ option: true, isSwitch: true, shortcut: "h" }), + onlyNotes: ct.switchOption({ shortcut: "n" }), + onlyWarns: ct.switchOption({ shortcut: "w" }), + onlyMutes: ct.switchOption({ shortcut: "m" }), + onyUnmutes: ct.switchOption({ shortcut: "um" }), + onlyBans: ct.switchOption({ shortcut: "b" }), + onyUnbans: ct.switchOption({ shortcut: "ub" }), }; export const CasesUserCmd = modActionsCmd({ @@ -41,7 +48,17 @@ export const CasesUserCmd = modActionsCmd({ return; } - const cases = await pluginData.state.cases.with("notes").getByUserId(user.id); + let cases = await pluginData.state.cases.with("notes").getByUserId(user.id); + + const typesToShow: CaseTypes[] = []; + if (args.onlyNotes) typesToShow.push(CaseTypes.Note); + if (args.onlyWarns) typesToShow.push(CaseTypes.Warn); + if (args.onlyMutes) typesToShow.push(CaseTypes.Mute); + if (args.onyUnmutes) typesToShow.push(CaseTypes.Unmute); + if (args.onlyBans) typesToShow.push(CaseTypes.Ban); + if (args.onyUnbans) typesToShow.push(CaseTypes.Unban); + if (typesToShow.length > 0) cases = cases.filter(c => typesToShow.includes(c.type)); + const normalCases = cases.filter(c => !c.is_hidden); const hiddenCases = cases.filter(c => c.is_hidden);