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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26