/[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 86 by rakin, Mon Jul 29 17:28:32 2024 UTC revision 227 by rakin, Mon Jul 29 17:29:07 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 11  import ms from 'ms'; Line 11  import ms from 'ms';
11    
12  import PunishmentType from '../../types/PunishmentType';  import PunishmentType from '../../types/PunishmentType';
13    
14  export async function unmute(client: DiscordClient, user: GuildMember, msg: Message | CommandInteraction, d: User) {  export async function unmute(client: DiscordClient, user: GuildMember, d: User) {
15      try {                  try {            
16          await History.create(user.id, msg.guild!, 'unmute', msg.member!.user.id, null);          await History.create(user.id, user.guild!, 'unmute', d.id, null);
17    
18          const role = await msg.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!);          await user.roles.remove(role!, 'Unmuting user');
20    
21          const { default: Punishment } = await import('../../models/Punishment');          const { default: Punishment } = await import('../../models/Punishment');
22    
23            const { getTimeouts, clearTimeoutv2 } = await import('../../utils/setTimeout');
24    
25            const { default: Hardmute } = await import("../../models/Hardmute");
26            const { default: MuteRecord } = await import("../../models/MuteRecord");
27    
28            const hardmute = await Hardmute.findOne({
29                where: {
30                    user_id: user.id,
31                    guild_id: user.guild.id,
32                },
33                order: [
34                    ['id', 'DESC']
35                ]
36            });
37    
38            if (hardmute) {
39                for await (const roleID of hardmute.get().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.destroy();
53            }
54    
55            const timeouts = getTimeouts();
56            
57            for (const timeout of timeouts.values()) {
58                if (timeout.row.params) {
59                    try {
60                        const json = JSON.parse(timeout.row.params);
61    
62                        if (json) {
63                            if (json[1] === user.id && timeout.row.filePath.endsWith('unmute-job')) {
64                                await clearTimeoutv2(timeout);
65                            }
66                        }
67                    }
68                    catch (e) {
69                        console.log(e);                    
70                    }
71                }
72            }
73    
74          await Punishment.create({          await Punishment.create({
75              type: PunishmentType.UNMUTE,              type: PunishmentType.UNMUTE,
76              user_id: user.id,              user_id: user.id,
77              guild_id: msg.guild!.id,              guild_id: user.guild!.id,
78              mod_id: d.id,              mod_id: d.id,
79              mod_tag: d.tag,              mod_tag: d.tag,
80          });          });
81    
82          await user.send({          const muteRecord = await MuteRecord.findOne({
83              embeds: [              where: {
84                  new MessageEmbed()                  user_id: user.user.id,
85                  .setAuthor({                  guild_id: user.guild.id
86                      iconURL: <string> msg.guild!.iconURL(),              }
                     name: `\tYou have been unmuted in ${msg.guild!.name}`  
                 })  
             ]  
87          });          });
88    
89            if (muteRecord) {
90                await muteRecord.destroy();
91            }
92    
93            try {
94                await user.send({
95                    embeds: [
96                        new MessageEmbed()
97                        .setAuthor({
98                            iconURL: <string> user.guild!.iconURL(),
99                            name: `\tYou have been unmuted in ${user.guild!.name}`
100                        })
101                    ]
102                });
103            }
104            catch (e) {
105                console.log(e);
106            }
107    
108          await client.logger.logUnmute(user, d);          await client.logger.logUnmute(user, d);
109      }      }
110      catch (e) {      catch (e) {
# Line 47  export async function unmute(client: Dis Line 114  export async function unmute(client: Dis
114    
115  export default class UnmuteCommand extends BaseCommand {  export default class UnmuteCommand extends BaseCommand {
116      supportsInteractions: boolean = true;      supportsInteractions: boolean = true;
117        permissions = [Permissions.FLAGS.MODERATE_MEMBERS];
118    
119      constructor() {      constructor() {
120          super('unmute', 'moderation', []);          super('unmute', 'moderation', []);
# Line 65  export default class UnmuteCommand exten Line 133  export default class UnmuteCommand exten
133              return;              return;
134          }          }
135    
136            if (msg instanceof CommandInteraction)  
137                await msg.deferReply();
138    
139          let user: GuildMember;          let user: GuildMember;
140    
141          if (options.isInteraction) {          if (options.isInteraction) {
142              user = await <GuildMember> options.options.getMember('member');              user = await <GuildMember> options.options.getMember('member');
143    
144              if (!user) {              if (!user) {
145                  await msg.reply({                  await this.deferReply(msg, {
146                      embeds: [                      embeds: [
147                          new MessageEmbed()                          new MessageEmbed()
148                          .setColor('#f14a60')                          .setColor('#f14a60')
# Line 93  export default class UnmuteCommand exten Line 164  export default class UnmuteCommand exten
164                  user = user2;                  user = user2;
165              }              }
166              catch (e) {              catch (e) {
167                  await msg.reply({                  await this.deferReply(msg, {
168                      embeds: [                      embeds: [
169                          new MessageEmbed()                          new MessageEmbed()
170                          .setColor('#f14a60')                          .setColor('#f14a60')
# Line 107  export default class UnmuteCommand exten Line 178  export default class UnmuteCommand exten
178              console.log(user);              console.log(user);
179          }          }
180    
181          await unmute(client, user, msg, msg.member!.user as User);          await unmute(client, user, msg.member!.user as User);
182    
183          await msg.reply({          await this.deferReply(msg, {
184              embeds: [              embeds: [
185                  new MessageEmbed()                  new MessageEmbed()
186                  .setAuthor({                  .setAuthor({
# Line 126  export default class UnmuteCommand exten Line 197  export default class UnmuteCommand exten
197              ]              ]
198          });          });
199      }      }
 }  
200    }

Legend:
Removed from v.86  
changed lines
  Added in v.227

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26