-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathungag.js
71 lines (65 loc) · 2.95 KB
/
ungag.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const { SlashCommandBuilder } = require("@discordjs/builders")
const { MessageEmbed } = require('discord.js');
const Enmap = require('enmap');
const types = [
{ name: "Ball-gag", value: 0, plural: "ged" }, // Default
{ name: "Muzzle", value: 1, plural: "d" }, //
{ name: "Ring-gag", value: 2, plural: "ged" }, //
{ name: "Cock-gag", value: 3, plural: "ged"},
{ name: "Bit-gag", value: 4, plural: "ged"},
{ name: "Sound-Proof Hood", value: 5, plural: "ed" }, // Just straight up deletes all messages.
{ name: "Synth Gag", value: 6, plural: "ged" }, // Also known as the emoji gag.
]
const run = async (client, interaction) => {
//Settings and gaglist needs to be up to date so we get it inside of the run.
const settings = new Enmap({
name: "settings",
fetchAll: false,
autoFetch: true,
cloneLevel: 'deep',
});
const gaglist = new Enmap({
name: "gaglist",
fetchAll: false,
autoFetch: true,
cloneLevel: 'deep'
})
const hierarchy = settings.get(interaction.guild.id, "toggleHierarchy") // checks if the hierarchy command is on
let member = interaction.options.getMember("user")
const key = `${interaction.guild.id}-${member.id}`;
const embed = new MessageEmbed()
try {
// If the user is not on the list.
if (!gaglist.has(key)) return interaction.reply({ content: `That user is currently not gagged!`, ephemeral: true })
// If hierarchy is on, we check if the gagger's top role is equal to or higher than the ungagger. If it is, we prevent them from ungagging.
if (hierarchy === 1 && gaglist.get(key, "applierRolePower") >= interaction.member.roles.highest.rawPosition) return interaction.reply({ content: `This gag was applied by someone with the ${interaction.guild.roles.find(element => element === gaglist.get(key, "applierRolePower"))} `, ephemeral: true })
// If hierarchy isn't on this always happens.
else {
const gagType = gaglist.get(key, "gagtype")
embed.setColor(0x9af76f)
embed.addField('Ungagged!', `${member.user} has been freed from their ${types[gagType].name.toLowerCase()}!`, true);
gaglist.delete(key);
return interaction.reply({ embeds: [embed] })
}
} catch (error) {
console.error('Error trying to ungag: ', error);
embed.setColor(0xe61b00)
embed.addField('Error!', 'Failed to ungag' + member.user + '. Error:' + error + ', please yell at the developer, as this is a serious issue.', true);
return interaction.reply({ embeds: [embed] })
}
}
module.exports = {
data: new SlashCommandBuilder().setName("ungag").setDescription("Ungags a member."),
name: "ungag",
description: "Ungags a member",
perm: "useperms",
options: [
{
name: "user",
description: "The user to ungag",
type: "USER",
required: true
},
],
run
}