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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26