1 |
import { BanOptions, CommandInteraction, GuildMember, Interaction, Message, User } from 'discord.js'; |
import { CommandInteraction, ContextMenuInteraction, GuildMember, Message, User } from 'discord.js'; |
2 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
import DiscordClient from '../../client/Client'; |
import DiscordClient from '../../client/Client'; |
4 |
import CommandOptions from '../../types/CommandOptions'; |
import CommandOptions from '../../types/CommandOptions'; |
5 |
import InteractionOptions from '../../types/InteractionOptions'; |
import InteractionOptions from '../../types/InteractionOptions'; |
6 |
import MessageEmbed from '../../client/MessageEmbed'; |
import MessageEmbed from '../../client/MessageEmbed'; |
|
import getUser from '../../utils/getUser'; |
|
7 |
import getMember from '../../utils/getMember'; |
import getMember from '../../utils/getMember'; |
8 |
import History from '../../automod/History'; |
import Punishment from '../../models/Punishment'; |
9 |
|
import PunishmentType from '../../types/PunishmentType'; |
10 |
|
|
11 |
export default class BeanCommand extends BaseCommand { |
export default class ShotCommand extends BaseCommand { |
12 |
supportsInteractions: boolean = true; |
supportsInteractions: boolean = true; |
13 |
|
supportsContextMenu: boolean = true; |
14 |
|
|
15 |
constructor() { |
constructor() { |
16 |
super('bean', 'moderation', []); |
super('shot', 'moderation', ['Shot']); |
17 |
} |
} |
18 |
|
|
19 |
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
async run(client: DiscordClient, msg: Message | CommandInteraction | ContextMenuInteraction, options: CommandOptions | InteractionOptions) { |
20 |
if (!options.isInteraction && typeof options.args[0] === 'undefined') { |
if (!options.isInteraction && typeof options.args[0] === 'undefined') { |
21 |
await msg.reply({ |
await msg.reply({ |
22 |
embeds: [ |
embeds: [ |
30 |
} |
} |
31 |
|
|
32 |
let user: GuildMember; |
let user: GuildMember; |
33 |
|
let dm = true; |
34 |
let reason: string | undefined; |
let reason: string | undefined; |
35 |
|
|
36 |
if (options.isInteraction) { |
if (options.isInteraction) { |
37 |
user = await <GuildMember> options.options.getMember('member'); |
user = await <GuildMember> (msg instanceof ContextMenuInteraction ? options.options.getMember('user') : options.options.getMember('member')); |
38 |
|
|
39 |
if (!user) { |
if (!user) { |
40 |
await msg.reply({ |
await msg.reply({ |
41 |
embeds: [ |
embeds: [ |
42 |
new MessageEmbed() |
new MessageEmbed() |
43 |
.setColor('#f14a60') |
.setColor('#f14a60') |
44 |
.setDescription("Invalid user given.") |
.setDescription("Invalid member given.") |
45 |
] |
] |
46 |
}); |
}); |
47 |
|
|
83 |
} |
} |
84 |
} |
} |
85 |
|
|
86 |
try { |
if (user.id === client.user?.id) { |
87 |
await History.create(user.id, msg.guild!, 'bean', msg.member!.user.id, typeof reason === 'undefined' ? null : reason); |
await msg.reply("Oh no no no... wait wait, you can't just do that with me!?!? Can you? :grin:"); |
88 |
|
return; |
89 |
|
} |
90 |
|
|
91 |
await user.send({ |
const anonymous = options.isInteraction ? options.options.getBoolean('anonymous') ?? false : false; |
92 |
embeds: [ |
|
93 |
new MessageEmbed() |
try { |
94 |
.setAuthor({ |
await Punishment.create({ |
95 |
iconURL: <string> msg.guild!.iconURL(), |
type: PunishmentType.SHOT, |
96 |
name: `\tYou have been beaned in ${msg.guild!.name}` |
user_id: user.id, |
97 |
}) |
guild_id: msg.guild!.id, |
98 |
.addFields([ |
mod_id: msg.member!.user.id, |
99 |
{ |
mod_tag: (msg.member!.user as User).tag, |
100 |
name: "Reason", |
reason, |
101 |
value: typeof reason === 'undefined' ? '*No reason provided*' : reason |
createdAt: new Date() |
|
} |
|
|
]) |
|
|
] |
|
102 |
}); |
}); |
103 |
|
|
104 |
await client.logger.logBeaned(user, typeof reason === 'undefined' ? '*No reason provided*' : reason, msg.member!.user as User); |
// await History.create(user.id, msg.guild!, 'bean', msg.member!.user.id, typeof reason === 'undefined' ? null : reason); |
105 |
|
|
106 |
|
try { |
107 |
|
await user.send({ |
108 |
|
embeds: [ |
109 |
|
new MessageEmbed() |
110 |
|
.setAuthor({ |
111 |
|
iconURL: <string> msg.guild!.iconURL(), |
112 |
|
name: `\tYou got a shot in ${msg.guild!.name}` |
113 |
|
}) |
114 |
|
.addFields([ |
115 |
|
{ |
116 |
|
name: "Reason", |
117 |
|
value: typeof reason === 'undefined' ? '*No reason provided*' : reason |
118 |
|
}, |
119 |
|
...(!anonymous ? [{ |
120 |
|
name: "💉 Doctor", |
121 |
|
value: `${(msg.member?.user as User).tag}` |
122 |
|
}] : []) |
123 |
|
]) |
124 |
|
] |
125 |
|
}); |
126 |
|
} |
127 |
|
catch (e) { |
128 |
|
console.log(e); |
129 |
|
dm = false; |
130 |
|
} |
131 |
|
|
132 |
|
// await client.logger.logBeaned(user, typeof reason === 'undefined' ? '*No reason provided*' : reason, msg.member!.user as User); |
133 |
} |
} |
134 |
catch (e) { |
catch (e) { |
135 |
console.log(e); |
console.log(e); |
142 |
name: user.user.tag, |
name: user.user.tag, |
143 |
iconURL: user.user.displayAvatarURL(), |
iconURL: user.user.displayAvatarURL(), |
144 |
}) |
}) |
145 |
.setDescription(user.user.tag + " has been beaned.") |
.setDescription(user.user.tag + " got a shot." + (!dm ? "\nThey have DMs disabled. They will not know that they got a shot." : '')) |
146 |
.addFields([ |
.addFields([ |
147 |
{ |
{ |
148 |
name: "Beaned by", |
name: "💉 Doctor", |
149 |
value: (msg.member!.user as User).tag |
value: (msg.member!.user as User).tag |
150 |
}, |
}, |
151 |
{ |
{ |
156 |
] |
] |
157 |
}); |
}); |
158 |
} |
} |
|
} |
|
159 |
|
} |