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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 86 - (hide annotations)
Mon Jul 29 17:28:32 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 4704 byte(s)
Updated the database system
1 rakin 51 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 rakin 86 import Punishment from '../../models/Punishment';
11     import PunishmentType from '../../types/PunishmentType';
12 rakin 51
13     export default class BeanCommand extends BaseCommand {
14     supportsInteractions: boolean = true;
15    
16     constructor() {
17     super('bean', 'moderation', []);
18     }
19    
20     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
21     if (!options.isInteraction && typeof options.args[0] === 'undefined') {
22     await msg.reply({
23     embeds: [
24     new MessageEmbed()
25     .setColor('#f14a60')
26     .setDescription(`This command requires at least one argument.`)
27     ]
28     });
29    
30     return;
31     }
32    
33     let user: GuildMember;
34     let reason: string | undefined;
35    
36     if (options.isInteraction) {
37     user = await <GuildMember> options.options.getMember('member');
38    
39     if (!user) {
40     await msg.reply({
41     embeds: [
42     new MessageEmbed()
43     .setColor('#f14a60')
44     .setDescription("Invalid user 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     try {
87 rakin 86 await Punishment.create({
88     type: PunishmentType.BEAN,
89     user_id: user.id,
90     guild_id: msg.guild!.id,
91     mod_id: msg.member!.user.id,
92     mod_tag: (msg.member!.user as User).tag,
93     reason
94     });
95    
96 rakin 51 await History.create(user.id, msg.guild!, 'bean', msg.member!.user.id, typeof reason === 'undefined' ? null : reason);
97    
98     await user.send({
99     embeds: [
100     new MessageEmbed()
101     .setAuthor({
102     iconURL: <string> msg.guild!.iconURL(),
103     name: `\tYou have been beaned in ${msg.guild!.name}`
104     })
105     .addFields([
106     {
107     name: "Reason",
108     value: typeof reason === 'undefined' ? '*No reason provided*' : reason
109     }
110     ])
111     ]
112     });
113    
114     await client.logger.logBeaned(user, typeof reason === 'undefined' ? '*No reason provided*' : reason, msg.member!.user as User);
115     }
116     catch (e) {
117     console.log(e);
118     }
119    
120     await msg.reply({
121     embeds: [
122     new MessageEmbed()
123     .setAuthor({
124     name: user.user.tag,
125     iconURL: user.user.displayAvatarURL(),
126     })
127     .setDescription(user.user.tag + " has been beaned.")
128     .addFields([
129     {
130     name: "Beaned by",
131     value: (msg.member!.user as User).tag
132     },
133     {
134     name: "Reason",
135     value: reason === undefined ? "*No reason provided*" : reason
136     }
137     ])
138     ]
139     });
140     }
141     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26