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

Annotation of /branches/4.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: 7360 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-2022 OSN Inc.
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 { CommandInteraction, ContextMenuInteraction, GuildMember, Message, Permissions, User } from 'discord.js';
21     import BaseCommand from '../../utils/structures/BaseCommand';
22     import DiscordClient from '../../client/Client';
23     import CommandOptions from '../../types/CommandOptions';
24     import InteractionOptions from '../../types/InteractionOptions';
25     import MessageEmbed from '../../client/MessageEmbed';
26     import getMember from '../../utils/getMember';
27     import Punishment from '../../models/Punishment';
28     import PunishmentType from '../../types/PunishmentType';
29    
30     export default class ShotCommand extends BaseCommand {
31     supportsInteractions: boolean = true;
32     supportsContextMenu: boolean = true;
33     permissions = [Permissions.FLAGS.MANAGE_MESSAGES];
34    
35     constructor() {
36     super('shot', 'moderation', ['Shot']);
37     }
38    
39     async run(client: DiscordClient, msg: Message | CommandInteraction | ContextMenuInteraction, options: CommandOptions | InteractionOptions) {
40     if (!options.isInteraction && typeof options.args[0] === 'undefined') {
41     await msg.reply({
42     embeds: [
43     new MessageEmbed()
44     .setColor('#f14a60')
45     .setDescription(`This command requires at least one argument.`)
46     ]
47     });
48    
49     return;
50     }
51    
52     let user: GuildMember;
53     let dm = true;
54     let reason: string | undefined;
55    
56     if (msg instanceof CommandInteraction || msg instanceof ContextMenuInteraction) {
57     await msg.deferReply();
58     }
59    
60     if (options.isInteraction) {
61     user = await <GuildMember> (msg instanceof ContextMenuInteraction ? options.options.getMember('user') : options.options.getMember('member'));
62    
63     if (!user) {
64     await this.deferReply(msg, {
65     embeds: [
66     new MessageEmbed()
67     .setColor('#f14a60')
68     .setDescription("Invalid member given.")
69     ]
70     });
71    
72     return;
73     }
74    
75     if (options.options.getString('reason')) {
76     reason = await <string> options.options.getString('reason');
77     }
78     }
79     else {
80     try {
81     const user2 = await getMember((msg as Message), options);
82    
83     if (!user2) {
84     throw new Error('Invalid user');
85     }
86    
87     user = user2;
88     }
89     catch (e) {
90     await this.deferReply(msg, {
91     embeds: [
92     new MessageEmbed()
93     .setColor('#f14a60')
94     .setDescription(`Invalid user given.`)
95     ]
96     });
97    
98     return;
99     }
100    
101     console.log(user);
102    
103     if (options.args[1]) {
104     const args = [...options.args];
105     args.shift();
106     reason = await args.join(' ');
107     }
108     }
109    
110     if (user.id === client.user?.id) {
111     const random = Math.random() >= 0.5;
112    
113     await this.deferReply(msg, {
114     content: `Oh no no no... wait wait, you can't just do that with me${random ? "... I'm such an innocent bot :innocent:, PWEASE don't do that :pleading_face:" : "!?!? Can you?"}`,
115     files: [random ? "https://tenor.com/view/folded-hands-emoji-funny-animals-gray-cat-cute-pwease-gif-14039745.gif" : 'https://tenor.com/view/are-you-even-capable-vera-bennett-wentworth-can-you-handle-this-are-you-qualified-gif-22892513.gif']
116     });
117    
118     return;
119     }
120    
121     const anonymous = options.isInteraction ? options.options.getBoolean('anonymous') ?? false : false;
122    
123     try {
124     const { numericId: id } = await Punishment.create({
125     type: PunishmentType.SHOT,
126     user_id: user.id,
127     guild_id: msg.guild!.id,
128     mod_id: msg.member!.user.id,
129     mod_tag: (msg.member!.user as User).tag,
130     reason,
131     createdAt: new Date()
132     });
133    
134     // await History.create(user.id, msg.guild!, 'bean', msg.member!.user.id, typeof reason === 'undefined' ? null : reason);
135    
136     try {
137     await user.send({
138     embeds: [
139     new MessageEmbed()
140     .setAuthor({
141     iconURL: <string> msg.guild!.iconURL(),
142     name: `\tYou got a shot in ${msg.guild!.name}`
143     })
144     .addFields([
145     {
146     name: "Reason",
147     value: typeof reason === 'undefined' ? '*No reason provided*' : reason
148     },
149     ...(!anonymous ? [{
150     name: "💉 Doctor",
151     value: `${(msg.member?.user as User).tag}`
152     }] : []),
153     {
154     name: 'Shot ID',
155     value: id + ''
156     }
157     ])
158     ]
159     });
160     }
161     catch (e) {
162     console.log(e);
163     dm = false;
164     }
165    
166     client.logger.onMemberShot(user, msg.member!.user as User, reason);
167    
168     await this.deferReply(msg, {
169     embeds: [
170     new MessageEmbed()
171     .setAuthor({
172     name: user.user.tag,
173     iconURL: user.user.displayAvatarURL(),
174     })
175     .setDescription(user.user.tag + " got a shot." + (!dm ? "\nThey have DMs disabled. They will not know that they got a shot." : ''))
176     .addFields([
177     {
178     name: "💉 Doctor",
179     value: (msg.member!.user as User).tag
180     },
181     {
182     name: "Reason",
183     value: reason === undefined ? "*No reason provided*" : reason
184     },
185     {
186     name: 'Shot ID',
187     value: id + ''
188     }
189     ])
190     ]
191     });
192     }
193     catch (e) {
194     console.log(e);
195     }
196     }
197     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26