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