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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26