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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 102 by rakin, Mon Jul 29 17:28:36 2024 UTC revision 335 by rakin, Mon Jul 29 17:29:36 2024 UTC
# Line 1  Line 1 
1  import { BanOptions, CommandInteraction, Guild, GuildMember, Interaction, Message, User } from 'discord.js';  import { BanOptions, CommandInteraction, Guild, GuildMember, Interaction, Message, Permissions, User } from 'discord.js';
2  import BaseCommand from '../../utils/structures/BaseCommand';  import BaseCommand from '../../utils/structures/BaseCommand';
3  import DiscordClient from '../../client/Client';  import DiscordClient from '../../client/Client';
4  import CommandOptions from '../../types/CommandOptions';  import CommandOptions from '../../types/CommandOptions';
# Line 15  export async function unmute(client: Dis Line 15  export async function unmute(client: Dis
15      try {                  try {            
16          await History.create(user.id, user.guild!, 'unmute', d.id, null);          await History.create(user.id, user.guild!, 'unmute', d.id, null);
17    
18          const role = await user.guild!.roles.fetch(client.config.get('mute_role'));          const role = await user.guild!.roles.fetch(client.config.props[user.guild.id].mute_role);
19          await user.roles.remove(role!);          try {
20                await user.roles.remove(role!, 'Unmuting user');
21            }
22            catch (e) {
23                console.log(e);
24            }
25    
26          const { default: Punishment } = await import('../../models/Punishment');          const { default: Punishment } = await import('../../models/Punishment');
27    
28          const { getTimeouts, clearTimeoutv2 } = await import('../../utils/setTimeout');          const { getTimeouts, clearTimeoutv2 } = await import('../../utils/setTimeout');
29    
30            const { default: Hardmute } = await import("../../models/Hardmute");
31            const { default: MuteRecord } = await import("../../models/MuteRecord");
32    
33            const hardmute = await Hardmute.findOne({
34                user_id: user.id,
35                guild_id: user.guild.id
36            });
37    
38            if (hardmute) {
39                for await (const roleID of hardmute.roles) {
40                    try {
41                        const role = await user.guild.roles.fetch(roleID);
42    
43                        if (role) {
44                            await user.roles.add(role, 'Adding the roles which were removed due to hardmute');
45                        }
46                    }
47                    catch (e) {
48                        console.log(e);                    
49                    }
50                }
51    
52                await hardmute.delete();
53            }
54    
55          const timeouts = getTimeouts();          const timeouts = getTimeouts();
56                    
57          for (const timeout of timeouts.values()) {          for (const timeout of timeouts.values()) {
# Line 30  export async function unmute(client: Dis Line 60  export async function unmute(client: Dis
60                      const json = JSON.parse(timeout.row.params);                      const json = JSON.parse(timeout.row.params);
61    
62                      if (json) {                      if (json) {
63                          if (json[1] === user.id) {                          if (json[1] === user.id && timeout.row.filePath.endsWith('unmute-job')) {
64                              await clearTimeoutv2(timeout);                              await clearTimeoutv2(timeout);
65                          }                          }
66                      }                      }
# Line 49  export async function unmute(client: Dis Line 79  export async function unmute(client: Dis
79              mod_tag: d.tag,              mod_tag: d.tag,
80          });          });
81    
82          await user.send({          const muteRecord = await MuteRecord.findOne({
83              embeds: [              user_id: user.user.id,
84                  new MessageEmbed()              guild_id: user.guild.id
                 .setAuthor({  
                     iconURL: <string> user.guild!.iconURL(),  
                     name: `\tYou have been unmuted in ${user.guild!.name}`  
                 })  
             ]  
85          });          });
86    
87            if (muteRecord) {
88                await muteRecord.delete();
89            }
90    
91            try {
92                await user.send({
93                    embeds: [
94                        new MessageEmbed()
95                        .setAuthor({
96                            iconURL: <string> user.guild!.iconURL(),
97                            name: `\tYou have been unmuted in ${user.guild!.name}`
98                        })
99                    ]
100                });
101            }
102            catch (e) {
103                console.log(e);
104            }
105    
106          await client.logger.logUnmute(user, d);          await client.logger.logUnmute(user, d);
107      }      }
108      catch (e) {      catch (e) {
# Line 68  export async function unmute(client: Dis Line 112  export async function unmute(client: Dis
112    
113  export default class UnmuteCommand extends BaseCommand {  export default class UnmuteCommand extends BaseCommand {
114      supportsInteractions: boolean = true;      supportsInteractions: boolean = true;
115        permissions = [Permissions.FLAGS.MODERATE_MEMBERS];
116    
117      constructor() {      constructor() {
118          super('unmute', 'moderation', []);          super('unmute', 'moderation', []);
# Line 86  export default class UnmuteCommand exten Line 131  export default class UnmuteCommand exten
131              return;              return;
132          }          }
133    
134            if (msg instanceof CommandInteraction)  
135                await msg.deferReply();
136    
137          let user: GuildMember;          let user: GuildMember;
138    
139          if (options.isInteraction) {          if (options.isInteraction) {
140              user = await <GuildMember> options.options.getMember('member');              user = await <GuildMember> options.options.getMember('member');
141    
142              if (!user) {              if (!user) {
143                  await msg.reply({                  await this.deferReply(msg, {
144                      embeds: [                      embeds: [
145                          new MessageEmbed()                          new MessageEmbed()
146                          .setColor('#f14a60')                          .setColor('#f14a60')
# Line 114  export default class UnmuteCommand exten Line 162  export default class UnmuteCommand exten
162                  user = user2;                  user = user2;
163              }              }
164              catch (e) {              catch (e) {
165                  await msg.reply({                  await this.deferReply(msg, {
166                      embeds: [                      embeds: [
167                          new MessageEmbed()                          new MessageEmbed()
168                          .setColor('#f14a60')                          .setColor('#f14a60')
# Line 130  export default class UnmuteCommand exten Line 178  export default class UnmuteCommand exten
178    
179          await unmute(client, user, msg.member!.user as User);          await unmute(client, user, msg.member!.user as User);
180    
181          await msg.reply({          await this.deferReply(msg, {
182              embeds: [              embeds: [
183                  new MessageEmbed()                  new MessageEmbed()
184                  .setAuthor({                  .setAuthor({
# Line 147  export default class UnmuteCommand exten Line 195  export default class UnmuteCommand exten
195              ]              ]
196          });          });
197      }      }
 }  
198    }

Legend:
Removed from v.102  
changed lines
  Added in v.335

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26