forked from ZeppelinBot/Zeppelin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddCaseSlashCmd.ts
More file actions
70 lines (62 loc) · 2.51 KB
/
AddCaseSlashCmd.ts
File metadata and controls
70 lines (62 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { GuildMember } from "discord.js";
import { slashOptions } from "knub";
import { CaseTypes } from "../../../../data/CaseTypes.js";
import { hasPermission } from "../../../../pluginUtils.js";
import { resolveMember } from "../../../../utils.js";
import { generateAttachmentSlashOptions, retrieveMultipleOptions } from "../../../../utils/multipleSlashOptions.js";
import { modActionsSlashCmd } from "../../types.js";
import { NUMBER_ATTACHMENTS_CASE_CREATION } from "../constants.js";
import { actualAddCaseCmd } from "./actualAddCaseCmd.js";
const opts = [
slashOptions.string({ name: "reason", description: "The reason", required: false }),
slashOptions.user({ name: "mod", description: "The moderator to add this case as", required: false }),
...generateAttachmentSlashOptions(NUMBER_ATTACHMENTS_CASE_CREATION, {
name: "attachment",
description: "An attachment to add to the reason",
}),
];
export const AddCaseSlashCmd = modActionsSlashCmd({
name: "addcase",
configPermission: "can_addcase",
description: "Add an arbitrary case to the specified user without taking any action",
allowDms: false,
signature: [
slashOptions.string({
name: "type",
description: "The type of case to add",
required: true,
choices: Object.keys(CaseTypes)
.filter((key) => isNaN(Number(key)))
.map((key) => ({ name: key, value: key })),
}),
slashOptions.user({ name: "user", description: "The user to add a case to", required: true }),
...opts,
],
async run({ interaction, options, pluginData }) {
await interaction.deferReply({ ephemeral: true });
const attachments = retrieveMultipleOptions(NUMBER_ATTACHMENTS_CASE_CREATION, options, "attachment");
// The moderator who did the action is the message author or, if used, the specified -mod
let mod = interaction.member as GuildMember;
const canActAsOther = await hasPermission(pluginData, "can_act_as_other", {
channel: interaction.channel,
member: interaction.member,
});
if (options.mod) {
if (!canActAsOther) {
pluginData.state.common.sendErrorMessage(interaction, "You don't have permission to act as another moderator");
return;
}
mod = (await resolveMember(pluginData.client, pluginData.guild, options.mod.id))!;
}
actualAddCaseCmd(
pluginData,
interaction,
interaction.member as GuildMember,
mod,
attachments,
options.user,
options.type as keyof CaseTypes,
options.reason || "",
);
},
});