Skip to content
Snippets Groups Projects
Commit c2454fa5 authored by Patric Plattner's avatar Patric Plattner
Browse files

Adding the ability to unselect a role.

parent 27943b3a
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,6 @@ const checkPerm = require('../util/perm');
// slashcommand handler
async function addRoleMenu(interaction) {
console.log('test');
if (!(await checkPerm(interaction.member, 'role_menu'))) {
await interaction.reply({content: 'You are not authorized to do this.', ephemeral: true})
return;
......@@ -20,8 +19,8 @@ async function addRoleMenu(interaction) {
.setPlaceholder("Select a role.")
.addOptions([
{
label: 'Placeholder',
value: 'placeholder'
label: 'Reset Selection',
value: 'select_reset'
}
])
);
......@@ -92,9 +91,6 @@ async function addRoleToMenu(interaction) {
});
if (menu != null) {
let components = message.components;
if (components[0].components[0].options[0].value === 'placeholder') {
components[0].components[0].options = [];
}
if (!menu.roles.map((role) => role.roleID).includes(role.id.toString())) {
components[0].components[0].addOptions({
label: role.name,
......@@ -164,12 +160,6 @@ async function deleteRoleFromMenu(interaction) {
const value = menu.roles[menu.roles.map(role => role.roleID).indexOf(role.id.toString())].value;
const index1 = menu.roles.map(role => role.value).indexOf(value);
menu.roles.splice(index1, 1);
if (message.components[0].components[0].options.length === 1) {
message.components[0].components[0].addOptions({
label: "Placeholder",
value: "placeholder"
});
}
const index2 = message.components[0].components[0].options
.map(option => option.value).indexOf(value);
message.components[0].components[0].options
......@@ -255,7 +245,6 @@ async function editRoleMenu(interaction) {
}
const slashCommandHandler = async (interaction) => {
console.log('slashCommandHandler');
if (interaction.commandName === 'add_role_menu') {
await addRoleMenu(interaction);
} else if (interaction.commandName === 'delete_role_menu') {
......@@ -283,12 +272,23 @@ const selectMenuHandler = async (interaction) => {
channelID: channel.id,
messageID: message.id
});
console.log("1");
if (interaction.values[0] != 'placeholder') {
console.log("2");
if (menu != null) {
const roleIDs = menu.roles.map(role => role.roleID);
roleIDs.forEach(roleID => interaction.member.roles.remove(roleID));
interaction.member.roles.add(roleIDs[menu.roles.map(role => role.value).indexOf(interaction.values[0])]);
await interaction.reply({content: 'You have received your role.', ephemeral: true});
console.log("3");
if (interaction.values[0] === 'select_reset') {
console.log("4");
const roleIDs = menu.roles.map(role => role.roleID);
roleIDs.forEach(roleID => interaction.member.roles.remove(roleID));
await interaction.reply({content: 'Your role has been removed.', ephemeral: true});
} else {
console.log("5");
const roleIDs = menu.roles.map(role => role.roleID);
roleIDs.forEach(roleID => interaction.member.roles.remove(roleID));
interaction.member.roles.add(roleIDs[menu.roles.map(role => role.value).indexOf(interaction.values[0])]);
await interaction.reply({content: 'You have received your role.', ephemeral: true});
}
} else {
await interaction.reply({content: 'Internal Error. Please contact admins.', ephemeral: true});
}
......
......@@ -8,10 +8,10 @@ module.exports = async (member, permission) => {
return false;
}
if (permission === 'role_menu') {
console.log(member.roles.cache);
console.log(config.permissions.roleMenu);
return member.roles.cache.some((role) => config.permissions.roleMenu.some((prole) => prole == role.id.toString()))
|| member.permissions.has(Permissions.FLAGS.ADMINISTRATOR);
//console.log(member.roles.cache);
//console.log(config.permissions.roleMenu);
console.log("ASD");
return member.roles.cache.some((role) => config.permissions.roleMenu.some((prole) => prole == role.id.toString())) || member.permissions.has(Permissions.FLAGS.ADMINISTRATOR);
}
return false;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment