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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26