/[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 336 - (show annotations)
Mon Jul 29 17:29:36 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 5208 byte(s)
refactor(moderation): use mongodb
1 import { BanOptions, CommandInteraction, ContextMenuInteraction, GuildMember, Interaction, 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 getUser from '../../utils/getUser';
8 import getMember from '../../utils/getMember';
9 import History from '../../automod/History';
10 import Punishment from '../../models/Punishment';
11 import PunishmentType from '../../types/PunishmentType';
12 import ModerationEmbed from '../../utils/ModerationEmbed';
13
14 export default class ShotCommand extends BaseCommand {
15 supportsInteractions: boolean = true;
16 supportsContextMenu: boolean = true;
17
18 constructor() {
19 super('shot', 'moderation', ['Shot']);
20 }
21
22 async run(client: DiscordClient, msg: Message | CommandInteraction | ContextMenuInteraction, options: CommandOptions | InteractionOptions) {
23 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 let dm = true;
37 let reason: string | undefined;
38
39 if (options.isInteraction) {
40 user = await <GuildMember> (msg instanceof ContextMenuInteraction ? options.options.getMember('user') : options.options.getMember('member'));
41
42 if (!user) {
43 await msg.reply({
44 embeds: [
45 new MessageEmbed()
46 .setColor('#f14a60')
47 .setDescription("Invalid member given.")
48 ]
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 await Punishment.create({
91 type: PunishmentType.SHOT,
92 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 reason,
97 createdAt: new Date()
98 });
99
100 // await History.create(user.id, msg.guild!, 'bean', msg.member!.user.id, typeof reason === 'undefined' ? null : reason);
101
102 try {
103 await user.send({
104 embeds: [
105 new MessageEmbed()
106 .setAuthor({
107 iconURL: <string> msg.guild!.iconURL(),
108 name: `\tYou got a shot in ${msg.guild!.name}`
109 })
110 .addFields([
111 {
112 name: "Reason",
113 value: typeof reason === 'undefined' ? '*No reason provided*' : reason
114 }
115 ])
116 ]
117 });
118 }
119 catch (e) {
120 console.log(e);
121 dm = false;
122 }
123
124 // await client.logger.logBeaned(user, typeof reason === 'undefined' ? '*No reason provided*' : reason, msg.member!.user as User);
125 }
126 catch (e) {
127 console.log(e);
128 }
129
130 await msg.reply({
131 embeds: [
132 new MessageEmbed()
133 .setAuthor({
134 name: user.user.tag,
135 iconURL: user.user.displayAvatarURL(),
136 })
137 .setDescription(user.user.tag + " got a shot." + (!dm ? "\nThey have DMs disabled. They will not know that they got a shot." : ''))
138 .addFields([
139 {
140 name: "Given by",
141 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 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26