/[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 125 - (show annotations)
Mon Jul 29 17:28:41 2024 UTC (8 months, 1 week ago) by rakin
Original Path: trunk/src/commands/moderation/BeanCommand.ts
File MIME type: application/typescript
File size: 4880 byte(s)
Added support of context menu commands
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
13 export default class BeanCommand extends BaseCommand {
14 supportsInteractions: boolean = true;
15 supportsContextMenu: boolean = true;
16
17 constructor() {
18 super('bean', 'moderation', ['Bean']);
19 }
20
21 async run(client: DiscordClient, msg: Message | CommandInteraction | ContextMenuInteraction, options: CommandOptions | InteractionOptions) {
22 if (!options.isInteraction && typeof options.args[0] === 'undefined') {
23 await msg.reply({
24 embeds: [
25 new MessageEmbed()
26 .setColor('#f14a60')
27 .setDescription(`This command requires at least one argument.`)
28 ]
29 });
30
31 return;
32 }
33
34 let user: GuildMember;
35 let reason: string | undefined;
36
37 if (options.isInteraction) {
38 user = await <GuildMember> (msg instanceof ContextMenuInteraction ? options.options.getMember('user') : options.options.getMember('member'));
39
40 if (!user) {
41 await msg.reply({
42 embeds: [
43 new MessageEmbed()
44 .setColor('#f14a60')
45 .setDescription("Invalid member given.")
46 ]
47 });
48
49 return;
50 }
51
52 if (options.options.getString('reason')) {
53 reason = await <string> options.options.getString('reason');
54 }
55 }
56 else {
57 try {
58 const user2 = await getMember((msg as Message), options);
59
60 if (!user2) {
61 throw new Error('Invalid user');
62 }
63
64 user = user2;
65 }
66 catch (e) {
67 await msg.reply({
68 embeds: [
69 new MessageEmbed()
70 .setColor('#f14a60')
71 .setDescription(`Invalid user given.`)
72 ]
73 });
74
75 return;
76 }
77
78 console.log(user);
79
80 if (options.args[1]) {
81 const args = [...options.args];
82 args.shift();
83 reason = await args.join(' ');
84 }
85 }
86
87 try {
88 await Punishment.create({
89 type: PunishmentType.BEAN,
90 user_id: user.id,
91 guild_id: msg.guild!.id,
92 mod_id: msg.member!.user.id,
93 mod_tag: (msg.member!.user as User).tag,
94 reason
95 });
96
97 await History.create(user.id, msg.guild!, 'bean', msg.member!.user.id, typeof reason === 'undefined' ? null : reason);
98
99 await user.send({
100 embeds: [
101 new MessageEmbed()
102 .setAuthor({
103 iconURL: <string> msg.guild!.iconURL(),
104 name: `\tYou have been beaned in ${msg.guild!.name}`
105 })
106 .addFields([
107 {
108 name: "Reason",
109 value: typeof reason === 'undefined' ? '*No reason provided*' : reason
110 }
111 ])
112 ]
113 });
114
115 await client.logger.logBeaned(user, typeof reason === 'undefined' ? '*No reason provided*' : reason, msg.member!.user as User);
116 }
117 catch (e) {
118 console.log(e);
119 }
120
121 await msg.reply({
122 embeds: [
123 new MessageEmbed()
124 .setAuthor({
125 name: user.user.tag,
126 iconURL: user.user.displayAvatarURL(),
127 })
128 .setDescription(user.user.tag + " has been beaned.")
129 .addFields([
130 {
131 name: "Beaned by",
132 value: (msg.member!.user as User).tag
133 },
134 {
135 name: "Reason",
136 value: reason === undefined ? "*No reason provided*" : reason
137 }
138 ])
139 ]
140 });
141 }
142 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26