/[sudobot]/branches/7.x/src/commands/moderation/ShotCommand.ts
ViewVC logotype

Annotation of /branches/7.x/src/commands/moderation/ShotCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (hide annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 4338 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 rakinar2 577 /**
2     * This file is part of SudoBot.
3     *
4     * Copyright (C) 2021-2023 OSN Developers.
5     *
6     * SudoBot is free software; you can redistribute it and/or modify it
7     * under the terms of the GNU Affero General Public License as published by
8     * the Free Software Foundation, either version 3 of the License, or
9     * (at your option) any later version.
10     *
11     * SudoBot is distributed in the hope that it will be useful, but
12     * WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU Affero General Public License for more details.
15     *
16     * You should have received a copy of the GNU Affero General Public License
17     * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18     */
19    
20     import { PermissionsBitField, SlashCommandBuilder, User, escapeMarkdown } from "discord.js";
21     import Command, { ArgumentType, BasicCommandContext, CommandMessage, CommandReturn, ValidationRule } from "../../core/Command";
22     import { protectSystemAdminsFromCommands } from "../../utils/troll";
23     import { createModerationEmbed } from "../../utils/utils";
24    
25     export default class ShotCommand extends Command {
26     public readonly name = "shot";
27     public readonly validationRules: ValidationRule[] = [
28     {
29     types: [ArgumentType.User],
30     entity: true,
31     errors: {
32     required: "You must specify a user to give shot!",
33     "type:invalid": "You have specified an invalid user mention or ID.",
34     "entity:null": "The given user does not exist!"
35     },
36     name: "user"
37     },
38     {
39     types: [ArgumentType.StringRest],
40     optional: true,
41     errors: {
42     "type:invalid": "You have specified an invalid shot reason.",
43     "string:rest:length:max": "The shot reason must be less than 4000 characters long."
44     },
45     string: {
46     maxLength: 3999
47     },
48     name: "reason"
49     }
50     ];
51     public readonly permissions = [PermissionsBitField.Flags.ManageMessages];
52     public readonly permissionMode = "or";
53    
54     public readonly description = "Gives shot to a user.";
55     public readonly detailedDescription =
56     "This command doesn't do anything special except DMing the user and telling them that they've been given a shot.";
57    
58     public readonly slashCommandBuilder = new SlashCommandBuilder()
59     .addUserOption(option => option.setName("user").setDescription("The target user").setRequired(true))
60     .addStringOption(option => option.setName("reason").setDescription("Reason for giving shot to this user"));
61    
62     async execute(message: CommandMessage, context: BasicCommandContext): Promise<CommandReturn> {
63     await this.deferIfInteraction(message);
64    
65     const user = context.isLegacy ? context.parsedNamedArgs.user : context.options.getUser("user", true);
66    
67     if (await protectSystemAdminsFromCommands(this.client, message, user.id, "shot_safe")) {
68     return;
69     }
70    
71     const {
72     commands: { moderation_command_behaviour }
73     } = context.config;
74     const deleteResponse = moderation_command_behaviour === "delete";
75     const reason = context.isLegacy ? context.parsedNamedArgs.reason : context.options.getString("reason");
76    
77     const id = await this.client.infractionManager.createUserShot(user, {
78     reason,
79     guild: message.guild!,
80     moderator: message.member!.user as User
81     });
82    
83     await this.deferredReply(
84     message,
85     {
86     embeds: [
87     await createModerationEmbed({
88     moderator: message.member!.user as User,
89     user,
90     id,
91     color: 0x007bff,
92     reason,
93     description: `**${escapeMarkdown(user.username)}** has been given a shot.`,
94     fields: [
95     {
96     name: "💉 Doctor",
97     value: `${message.member!.user.username}`
98     }
99     ]
100     })
101     ]
102     },
103     deleteResponse ? "delete" : "default"
104     );
105     }
106     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26