1 |
rakin |
344 |
import { CommandInteraction, ContextMenuInteraction, GuildMember, Message, User } from 'discord.js'; |
2 |
rakin |
51 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
|
|
import DiscordClient from '../../client/Client'; |
4 |
|
|
import CommandOptions from '../../types/CommandOptions'; |
5 |
|
|
import InteractionOptions from '../../types/InteractionOptions'; |
6 |
|
|
import MessageEmbed from '../../client/MessageEmbed'; |
7 |
|
|
import getMember from '../../utils/getMember'; |
8 |
rakin |
86 |
import Punishment from '../../models/Punishment'; |
9 |
|
|
import PunishmentType from '../../types/PunishmentType'; |
10 |
rakin |
51 |
|
11 |
rakin |
197 |
export default class ShotCommand extends BaseCommand { |
12 |
rakin |
51 |
supportsInteractions: boolean = true; |
13 |
rakin |
125 |
supportsContextMenu: boolean = true; |
14 |
rakin |
51 |
|
15 |
|
|
constructor() { |
16 |
rakin |
197 |
super('shot', 'moderation', ['Shot']); |
17 |
rakin |
51 |
} |
18 |
|
|
|
19 |
rakin |
125 |
async run(client: DiscordClient, msg: Message | CommandInteraction | ContextMenuInteraction, options: CommandOptions | InteractionOptions) { |
20 |
rakin |
51 |
if (!options.isInteraction && typeof options.args[0] === 'undefined') { |
21 |
|
|
await msg.reply({ |
22 |
|
|
embeds: [ |
23 |
|
|
new MessageEmbed() |
24 |
|
|
.setColor('#f14a60') |
25 |
|
|
.setDescription(`This command requires at least one argument.`) |
26 |
|
|
] |
27 |
|
|
}); |
28 |
|
|
|
29 |
|
|
return; |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
let user: GuildMember; |
33 |
rakin |
160 |
let dm = true; |
34 |
rakin |
51 |
let reason: string | undefined; |
35 |
rakin |
363 |
|
36 |
rakin |
51 |
if (options.isInteraction) { |
37 |
rakin |
125 |
user = await <GuildMember> (msg instanceof ContextMenuInteraction ? options.options.getMember('user') : options.options.getMember('member')); |
38 |
rakin |
51 |
|
39 |
|
|
if (!user) { |
40 |
|
|
await msg.reply({ |
41 |
|
|
embeds: [ |
42 |
|
|
new MessageEmbed() |
43 |
|
|
.setColor('#f14a60') |
44 |
rakin |
125 |
.setDescription("Invalid member given.") |
45 |
rakin |
51 |
] |
46 |
|
|
}); |
47 |
|
|
|
48 |
|
|
return; |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
if (options.options.getString('reason')) { |
52 |
|
|
reason = await <string> options.options.getString('reason'); |
53 |
|
|
} |
54 |
|
|
} |
55 |
|
|
else { |
56 |
|
|
try { |
57 |
|
|
const user2 = await getMember((msg as Message), options); |
58 |
|
|
|
59 |
|
|
if (!user2) { |
60 |
|
|
throw new Error('Invalid user'); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
user = user2; |
64 |
|
|
} |
65 |
|
|
catch (e) { |
66 |
|
|
await msg.reply({ |
67 |
|
|
embeds: [ |
68 |
|
|
new MessageEmbed() |
69 |
|
|
.setColor('#f14a60') |
70 |
|
|
.setDescription(`Invalid user given.`) |
71 |
|
|
] |
72 |
|
|
}); |
73 |
|
|
|
74 |
|
|
return; |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
console.log(user); |
78 |
|
|
|
79 |
|
|
if (options.args[1]) { |
80 |
|
|
const args = [...options.args]; |
81 |
|
|
args.shift(); |
82 |
|
|
reason = await args.join(' '); |
83 |
|
|
} |
84 |
|
|
} |
85 |
|
|
|
86 |
rakin |
384 |
if (user.id === client.user?.id) { |
87 |
rakin |
392 |
const random = Math.random() >= 0.5; |
88 |
|
|
|
89 |
rakin |
391 |
await msg.reply({ |
90 |
rakin |
392 |
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?"}`, |
91 |
|
|
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'] |
92 |
rakin |
391 |
}); |
93 |
|
|
|
94 |
rakin |
384 |
return; |
95 |
|
|
} |
96 |
|
|
|
97 |
rakin |
363 |
const anonymous = options.isInteraction ? options.options.getBoolean('anonymous') ?? false : false; |
98 |
|
|
|
99 |
rakin |
51 |
try { |
100 |
rakin |
86 |
await Punishment.create({ |
101 |
rakin |
197 |
type: PunishmentType.SHOT, |
102 |
rakin |
86 |
user_id: user.id, |
103 |
|
|
guild_id: msg.guild!.id, |
104 |
|
|
mod_id: msg.member!.user.id, |
105 |
|
|
mod_tag: (msg.member!.user as User).tag, |
106 |
rakin |
336 |
reason, |
107 |
|
|
createdAt: new Date() |
108 |
rakin |
86 |
}); |
109 |
|
|
|
110 |
rakin |
197 |
// await History.create(user.id, msg.guild!, 'bean', msg.member!.user.id, typeof reason === 'undefined' ? null : reason); |
111 |
rakin |
51 |
|
112 |
rakin |
189 |
try { |
113 |
|
|
await user.send({ |
114 |
|
|
embeds: [ |
115 |
|
|
new MessageEmbed() |
116 |
|
|
.setAuthor({ |
117 |
|
|
iconURL: <string> msg.guild!.iconURL(), |
118 |
rakin |
197 |
name: `\tYou got a shot in ${msg.guild!.name}` |
119 |
rakin |
189 |
}) |
120 |
|
|
.addFields([ |
121 |
|
|
{ |
122 |
|
|
name: "Reason", |
123 |
|
|
value: typeof reason === 'undefined' ? '*No reason provided*' : reason |
124 |
rakin |
363 |
}, |
125 |
|
|
...(!anonymous ? [{ |
126 |
|
|
name: "💉 Doctor", |
127 |
|
|
value: `${(msg.member?.user as User).tag}` |
128 |
|
|
}] : []) |
129 |
rakin |
189 |
]) |
130 |
|
|
] |
131 |
|
|
}); |
132 |
rakin |
160 |
} |
133 |
|
|
catch (e) { |
134 |
|
|
console.log(e); |
135 |
|
|
dm = false; |
136 |
|
|
} |
137 |
rakin |
51 |
|
138 |
rakin |
197 |
// await client.logger.logBeaned(user, typeof reason === 'undefined' ? '*No reason provided*' : reason, msg.member!.user as User); |
139 |
rakin |
51 |
} |
140 |
|
|
catch (e) { |
141 |
|
|
console.log(e); |
142 |
|
|
} |
143 |
|
|
|
144 |
rakin |
197 |
await msg.reply({ |
145 |
rakin |
51 |
embeds: [ |
146 |
|
|
new MessageEmbed() |
147 |
|
|
.setAuthor({ |
148 |
|
|
name: user.user.tag, |
149 |
|
|
iconURL: user.user.displayAvatarURL(), |
150 |
|
|
}) |
151 |
rakin |
197 |
.setDescription(user.user.tag + " got a shot." + (!dm ? "\nThey have DMs disabled. They will not know that they got a shot." : '')) |
152 |
rakin |
51 |
.addFields([ |
153 |
|
|
{ |
154 |
rakin |
363 |
name: "💉 Doctor", |
155 |
rakin |
51 |
value: (msg.member!.user as User).tag |
156 |
|
|
}, |
157 |
|
|
{ |
158 |
|
|
name: "Reason", |
159 |
|
|
value: reason === undefined ? "*No reason provided*" : reason |
160 |
|
|
} |
161 |
|
|
]) |
162 |
|
|
] |
163 |
|
|
}); |
164 |
|
|
} |
165 |
rakin |
160 |
} |