1 |
rakin |
25 |
const History = require("../src/History"); |
2 |
rakin |
5 |
const MessageEmbed = require("../src/MessageEmbed"); |
3 |
|
|
|
4 |
|
|
module.exports = { |
5 |
|
|
async handle(msg, cm) { |
6 |
|
|
if (typeof cm.args[0] === 'undefined') { |
7 |
|
|
await msg.reply({ |
8 |
|
|
embeds: [ |
9 |
|
|
new MessageEmbed() |
10 |
|
|
.setColor('#f14a60') |
11 |
|
|
.setDescription(`This command requires at least one argument.`) |
12 |
|
|
] |
13 |
|
|
}); |
14 |
|
|
|
15 |
|
|
return; |
16 |
|
|
} |
17 |
|
|
|
18 |
|
|
var user = await msg.mentions.members.first(); |
19 |
|
|
|
20 |
|
|
if (typeof user !== 'object') { |
21 |
|
|
try { |
22 |
|
|
user = await msg.guild.members.fetch(cm.args[0]); |
23 |
|
|
} |
24 |
|
|
catch(e) { |
25 |
|
|
|
26 |
|
|
} |
27 |
|
|
} |
28 |
|
|
|
29 |
|
|
if (typeof user !== 'object') { |
30 |
|
|
await msg.reply({ |
31 |
|
|
embeds: [ |
32 |
|
|
new MessageEmbed() |
33 |
|
|
.setColor('#f14a60') |
34 |
|
|
.setDescription(`Invalid user given.`) |
35 |
|
|
] |
36 |
|
|
}); |
37 |
|
|
|
38 |
|
|
return; |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
this.unmute(user, msg); |
42 |
|
|
}, |
43 |
rakin |
25 |
async unmute(user, msg, guild, log, t) { |
44 |
rakin |
5 |
if (guild === undefined) { |
45 |
|
|
guild = msg.guild; |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
try { |
49 |
|
|
let mutedRole = await guild.roles.cache.find(role => role.id === app.config.get('mute_role')); |
50 |
|
|
let generalRole = await guild.roles.cache.find(role => role.id === app.config.get('gen_role')); |
51 |
|
|
|
52 |
|
|
if (typeof mutedRole !== 'object' || mutedRole === null) { |
53 |
|
|
await msg?.reply({ |
54 |
|
|
embeds: [ |
55 |
|
|
new MessageEmbed() |
56 |
|
|
.setColor('#f14a60') |
57 |
|
|
.setDescription(`No muted role is set.`) |
58 |
|
|
] |
59 |
|
|
}); |
60 |
|
|
|
61 |
|
|
return; |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
if (typeof generalRole !== 'object' || generalRole === null) { |
65 |
|
|
await msg?.reply({ |
66 |
|
|
embeds: [ |
67 |
|
|
new MessageEmbed() |
68 |
|
|
.setColor('#f14a60') |
69 |
|
|
.setDescription(`No general role is set.`) |
70 |
|
|
] |
71 |
|
|
}); |
72 |
|
|
|
73 |
|
|
return; |
74 |
|
|
} |
75 |
|
|
|
76 |
rakin |
25 |
if (!log) |
77 |
|
|
await History.create(user.id, guild, 'unmute', msg.author.id, async (data2) => {}); |
78 |
|
|
|
79 |
rakin |
5 |
await user.roles.add(generalRole); |
80 |
|
|
await user.roles.remove(mutedRole); |
81 |
rakin |
25 |
|
82 |
|
|
|
83 |
|
|
await app.logger.logUnmute(user, t === undefined ? msg.author : t); |
84 |
|
|
|
85 |
rakin |
5 |
} |
86 |
|
|
catch(e) { |
87 |
|
|
console.log(e); |
88 |
|
|
|
89 |
|
|
await msg?.reply({ |
90 |
|
|
embeds: [ |
91 |
|
|
new MessageEmbed() |
92 |
|
|
.setColor('#f14a60') |
93 |
|
|
.setDescription(`:x: I don't have enough permission to remove the muted role to this user.`) |
94 |
|
|
] |
95 |
|
|
}); |
96 |
|
|
|
97 |
|
|
return; |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
await app.db.get("DELETE FROM unmutes WHERE user_id = ? AND guild_id = ?", [user.id, guild.id], async (err) => { |
101 |
|
|
|
102 |
|
|
}); |
103 |
|
|
|
104 |
|
|
await user.send({ |
105 |
|
|
embeds: [ |
106 |
|
|
new MessageEmbed() |
107 |
|
|
.setAuthor({ |
108 |
|
|
iconURL: guild.iconURL(), |
109 |
|
|
name: `\tYou have been unmuted in ${guild.name}` |
110 |
|
|
}) |
111 |
|
|
] |
112 |
|
|
}); |
113 |
|
|
|
114 |
|
|
await msg?.reply({ |
115 |
|
|
embeds: [ |
116 |
|
|
new MessageEmbed() |
117 |
|
|
.setDescription(`The user ${user.user.tag} has been unmuted`) |
118 |
|
|
] |
119 |
|
|
}); |
120 |
|
|
} |
121 |
|
|
}; |