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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26