/[sudobot]/trunk/src/commands/moderation/ShotCommand.ts
ViewVC logotype

Contents of /trunk/src/commands/moderation/ShotCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 363 - (show annotations)
Mon Jul 29 17:29:47 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 5386 byte(s)
feat: show the shot doctor name (#74)
1 import { CommandInteraction, ContextMenuInteraction, GuildMember, Message, User } from 'discord.js';
2 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 import Punishment from '../../models/Punishment';
9 import PunishmentType from '../../types/PunishmentType';
10
11 export default class ShotCommand extends BaseCommand {
12 supportsInteractions: boolean = true;
13 supportsContextMenu: boolean = true;
14
15 constructor() {
16 super('shot', 'moderation', ['Shot']);
17 }
18
19 async run(client: DiscordClient, msg: Message | CommandInteraction | ContextMenuInteraction, options: CommandOptions | InteractionOptions) {
20 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 let dm = true;
34 let reason: string | undefined;
35
36 if (options.isInteraction) {
37 user = await <GuildMember> (msg instanceof ContextMenuInteraction ? options.options.getMember('user') : options.options.getMember('member'));
38
39 if (!user) {
40 await msg.reply({
41 embeds: [
42 new MessageEmbed()
43 .setColor('#f14a60')
44 .setDescription("Invalid member given.")
45 ]
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 const anonymous = options.isInteraction ? options.options.getBoolean('anonymous') ?? false : false;
87
88 try {
89 await Punishment.create({
90 type: PunishmentType.SHOT,
91 user_id: user.id,
92 guild_id: msg.guild!.id,
93 mod_id: msg.member!.user.id,
94 mod_tag: (msg.member!.user as User).tag,
95 reason,
96 createdAt: new Date()
97 });
98
99 // await History.create(user.id, msg.guild!, 'bean', msg.member!.user.id, typeof reason === 'undefined' ? null : reason);
100
101 try {
102 await user.send({
103 embeds: [
104 new MessageEmbed()
105 .setAuthor({
106 iconURL: <string> msg.guild!.iconURL(),
107 name: `\tYou got a shot in ${msg.guild!.name}`
108 })
109 .addFields([
110 {
111 name: "Reason",
112 value: typeof reason === 'undefined' ? '*No reason provided*' : reason
113 },
114 ...(!anonymous ? [{
115 name: "💉 Doctor",
116 value: `${(msg.member?.user as User).tag}`
117 }] : [])
118 ])
119 ]
120 });
121 }
122 catch (e) {
123 console.log(e);
124 dm = false;
125 }
126
127 // await client.logger.logBeaned(user, typeof reason === 'undefined' ? '*No reason provided*' : reason, msg.member!.user as User);
128 }
129 catch (e) {
130 console.log(e);
131 }
132
133 await msg.reply({
134 embeds: [
135 new MessageEmbed()
136 .setAuthor({
137 name: user.user.tag,
138 iconURL: user.user.displayAvatarURL(),
139 })
140 .setDescription(user.user.tag + " got a shot." + (!dm ? "\nThey have DMs disabled. They will not know that they got a shot." : ''))
141 .addFields([
142 {
143 name: "💉 Doctor",
144 value: (msg.member!.user as User).tag
145 },
146 {
147 name: "Reason",
148 value: reason === undefined ? "*No reason provided*" : reason
149 }
150 ])
151 ]
152 });
153 }
154 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26