From 2fb4c6e4f61143341ab45cb44854cb89d08d2c85 Mon Sep 17 00:00:00 2001 From: AcdSoftCo <106219586+AcdSoftCo@users.noreply.github.com> Date: Sun, 8 Oct 2023 23:53:24 +1100 Subject: [PATCH 1/8] course-chat-fix-2, make new roles where there arent any in /rolespermoverride and also remove individual permission overwrites, and also updates to /course join to catch when there doesn't exist a role for a course and also /course leave to attempt to remove individual permission overwrites along with removing course role PLEASE TEST THOROUGHLY AND INSPECT CODE THOROUGHLY. I wrote this ASAP and haven't got time to properly review it. --- commands/course.js | 64 ++++++++++++++++++++++++++++------- commands/rolesPermOverride.js | 53 +++++++++++++++++++++++++++-- 2 files changed, 103 insertions(+), 14 deletions(-) diff --git a/commands/course.js b/commands/course.js index b55544c1..10ccda0e 100644 --- a/commands/course.js +++ b/commands/course.js @@ -126,12 +126,13 @@ module.exports = { content: `✅ | Added you to the chat for \`${course_with_alias}\`.`, ephemeral: true, }); + } else { + // if there isn't a role that matches the name of the course + return await interaction.reply({ + content: `There doesn't exist a role for \`${course_with_alias}\`.`, + ephemeral: true, + }); } - - return await interaction.reply({ - content: `✅ | End of command - ${course_with_alias}.`, - ephemeral: true, - }); } else if (interaction.options.getSubcommand() === COMMAND_LEAVE) { const input_course = await interaction.options.getString("course"); const course = get_real_course_name(input_course); @@ -151,18 +152,57 @@ module.exports = { // If there is, let's see if the member already has that role if (role !== undefined) { if (!interaction.member.roles.cache.has(role.id)) { + // Find a channel with the same name as the course + const channel = await interaction.guild.channels.cache.find( + (c) => c.name.toLowerCase() === course.toLowerCase(), + ); + + // Otherwise, make sure that the channel exists, and is a text channel + if (channel === undefined) { + return await interaction.reply({ + content: `❌ | The course chat for \`${course}\` does not exist.`, + ephemeral: true, + }); + } else if (channel.type !== "GUILD_TEXT") { + return await interaction.reply({ + content: `❌ | The course chat for \`${course}\` is not a text channel.`, + ephemeral: true, + }); + } + + const permissions = new Permissions( + channel.permissionsFor(interaction.user.id).bitfield, + ); + + // Check if the member already has an entry in the channel's permission overwrites + if ( + !permissions.has([ + Permissions.FLAGS.VIEW_CHANNEL, + Permissions.FLAGS.SEND_MESSAGES, + ]) + ) { + // If they don't have an entry in the channel perm overwrites, + // let's remove the role from them + await interaction.member.roles.remove(role); + return await interaction.reply({ + content: `✅ | Removed you from the role and chat for \`${course}\`.`, + ephemeral: true, + }); + } + + // Remove the member from the channel's permission overwrites + await channel.permissionOverwrites.delete(interaction.member); + + return await interaction.reply({ + content: `✅ | Removed you from the course chat for \`${course}\`.`, + ephemeral: true, + }); + } else { return await interaction.reply({ content: `❌ | You do not have the role for \`${course}\`.`, ephemeral: true, }); } - - // If they do, let's remove the role from them - await interaction.member.roles.remove(role); - return await interaction.reply({ - content: `✅ | Removed you from the role and chat for \`${course}\`.`, - ephemeral: true, - }); } } return await interaction.reply("Error: invalid subcommand."); diff --git a/commands/rolesPermOverride.js b/commands/rolesPermOverride.js index 21e05e75..87e6e65e 100644 --- a/commands/rolesPermOverride.js +++ b/commands/rolesPermOverride.js @@ -1,7 +1,7 @@ const { SlashCommandBuilder } = require("@discordjs/builders"); const { Permissions } = require("discord.js"); -const is_valid_course = (course) => { +const is_valid_course_name = (course) => { const reg_comp_course = /^comp\d{4}$/; const reg_math_course = /^math\d{4}$/; const reg_binf_course = /^binf\d{4}$/; @@ -24,6 +24,26 @@ function editChannels(interaction, channels, role) { channel.type === "GUILD_TEXT" && channel.name.toLowerCase() === role.name.toLowerCase() ) { + // clear every individual user permission overwrite for the channel + for (const userID of channel.members) { + const permissions = new Permissions(channel.permissionsFor(userID).bitfield); + // Check if the member already has an entry in the channel's permission overwrites + if ( + !permissions.has([ + Permissions.FLAGS.VIEW_CHANNEL, + Permissions.FLAGS.SEND_MESSAGES, + ]) + ) { + console.log( + `❌ | You do not have permission overwrite entry in the course channel \`${channel.name}\`.`, + ); + } + // Remove the member from the channel's permission overwrites + channel.permissionOverwrites.delete( + interaction.guild.members.cache.get(`${userID}`), + ); + } + // Remove all permissions from a role role.setPermissions(0n) .then((updated) => @@ -37,13 +57,42 @@ function editChannels(interaction, channels, role) { SEND_MESSAGES: true, }); console.log(channel.name, role.name); + } else if ( + // if a course role doesn't exist for an existing course chat, then make one + channel.type === "GUILD_TEXT" && + is_valid_course_name(channel.name.toLowerCase()) && + channel.name.toLowerCase() !== role.name.toLowerCase() + ) { + // create a role and do the channel permission overwrite to the new role + + const newRole = interaction.guild.roles.create({ + name: channel.name.toLowerCase(), + color: "BLUE", + }); + + // set the permissions for the new role on a channel + // const channel = interaction.guild.channels.cache.get('CHANNEL_ID'); + channel.permissionOverwrites.create(newRole, { + VIEW_CHANNEL: true, + SEND_MESSAGES: true, + }); + + console.log(`Added permission overwrite for ${newRole.name} in ${channel.name}`); + } + + // now remove all the existing individual user permission overwrites + // and give them the role of the channel + + for (const memberID of channel.members) { + const member = interaction.guild.members.cache.get(`${memberID}`); + member.setPermissions(); } }); } function editRoles(interaction, roles) { roles.forEach((role) => { - if (is_valid_course(role.name)) { + if (is_valid_course_name(role.name)) { interaction.guild.channels .fetch() .then( From 8fe97dcf40321a62ed5ce792bf34a45da65994cf Mon Sep 17 00:00:00 2001 From: Wolfdragon24 Date: Mon, 9 Oct 2023 23:17:08 +1100 Subject: [PATCH 2/8] Modified functions for course channel fixes --- commands/course.js | 39 +++++------ commands/rolesPermOverride.js | 119 +++++++++------------------------- 2 files changed, 49 insertions(+), 109 deletions(-) diff --git a/commands/course.js b/commands/course.js index 10ccda0e..36c31a01 100644 --- a/commands/course.js +++ b/commands/course.js @@ -1,7 +1,5 @@ const { SlashCommandBuilder } = require("@discordjs/builders"); -const { Permissions } = require("discord.js"); -const MODERATION_REQUEST_CHANNEL = 824506830641561600; const COMMAND_JOIN = "join"; const COMMAND_LEAVE = "leave"; @@ -54,6 +52,8 @@ const is_valid_course = (course) => { ); }; +const in_overwrites = (overwrites, id) => overwrites.some((v, k) => k === id); + module.exports = { data: new SlashCommandBuilder() .setName("course") @@ -126,13 +126,13 @@ module.exports = { content: `✅ | Added you to the chat for \`${course_with_alias}\`.`, ephemeral: true, }); - } else { - // if there isn't a role that matches the name of the course - return await interaction.reply({ - content: `There doesn't exist a role for \`${course_with_alias}\`.`, - ephemeral: true, - }); } + + // if there isn't a role that matches the name of the course + return await interaction.reply({ + content: `There doesn't exist a role for \`${course_with_alias}\`. If you believe there should be, please inform a member of the Discord Bot team or staff.`, + ephemeral: true, + }); } else if (interaction.options.getSubcommand() === COMMAND_LEAVE) { const input_course = await interaction.options.getString("course"); const course = get_real_course_name(input_course); @@ -170,19 +170,11 @@ module.exports = { }); } - const permissions = new Permissions( - channel.permissionsFor(interaction.user.id).bitfield, - ); + const permissions = channel.permissionOverwrites.cache; - // Check if the member already has an entry in the channel's permission overwrites - if ( - !permissions.has([ - Permissions.FLAGS.VIEW_CHANNEL, - Permissions.FLAGS.SEND_MESSAGES, - ]) - ) { - // If they don't have an entry in the channel perm overwrites, - // let's remove the role from them + // Check if the member has access via role + if (in_overwrites(permissions, role.id)) { + // If they do remove the role await interaction.member.roles.remove(role); return await interaction.reply({ content: `✅ | Removed you from the role and chat for \`${course}\`.`, @@ -190,8 +182,11 @@ module.exports = { }); } - // Remove the member from the channel's permission overwrites - await channel.permissionOverwrites.delete(interaction.member); + // Check if the member has access via individual perms + if (in_overwrites(permissions, interaction.member.id)) { + // Remove the member from the channel's permission overwrites + await channel.permissionOverwrites.delete(interaction.member); + } return await interaction.reply({ content: `✅ | Removed you from the course chat for \`${course}\`.`, diff --git a/commands/rolesPermOverride.js b/commands/rolesPermOverride.js index 87e6e65e..76b36436 100644 --- a/commands/rolesPermOverride.js +++ b/commands/rolesPermOverride.js @@ -18,96 +18,45 @@ const is_valid_course_name = (course) => { ); }; -function editChannels(interaction, channels, role) { - channels.forEach((channel) => { - if ( - channel.type === "GUILD_TEXT" && - channel.name.toLowerCase() === role.name.toLowerCase() - ) { - // clear every individual user permission overwrite for the channel - for (const userID of channel.members) { - const permissions = new Permissions(channel.permissionsFor(userID).bitfield); - // Check if the member already has an entry in the channel's permission overwrites - if ( - !permissions.has([ - Permissions.FLAGS.VIEW_CHANNEL, - Permissions.FLAGS.SEND_MESSAGES, - ]) - ) { - console.log( - `❌ | You do not have permission overwrite entry in the course channel \`${channel.name}\`.`, - ); - } - // Remove the member from the channel's permission overwrites - channel.permissionOverwrites.delete( - interaction.guild.members.cache.get(`${userID}`), - ); - } +const in_overwrites = (overwrites, id) => overwrites.some((v, k) => k === id); - // Remove all permissions from a role - role.setPermissions(0n) - .then((updated) => - console.log(`Updated permissions to ${updated.permissions.bitfield}`), - ) - .catch(console.error); - // Set the permissions of the role - // Add the member to the channel's permission overwrites - channel.permissionOverwrites.create(role, { - VIEW_CHANNEL: true, - SEND_MESSAGES: true, - }); - console.log(channel.name, role.name); - } else if ( - // if a course role doesn't exist for an existing course chat, then make one - channel.type === "GUILD_TEXT" && - is_valid_course_name(channel.name.toLowerCase()) && - channel.name.toLowerCase() !== role.name.toLowerCase() - ) { - // create a role and do the channel permission overwrite to the new role +async function editChannels(interaction, channels) { + for (const channel in channels) { + const is_valid = is_valid_course_name(channel.name); + + if (!is_valid || channel.type !== "GUILD_TEXT") continue; - const newRole = interaction.guild.roles.create({ + let role = await interaction.guild.roles.cache.find( + (r) => r.name.toLowerCase() === channel.name.toLowerCase(), + ); + + if (!role) { + role = interaction.guild.roles.create({ name: channel.name.toLowerCase(), color: "BLUE", }); - - // set the permissions for the new role on a channel - // const channel = interaction.guild.channels.cache.get('CHANNEL_ID'); - channel.permissionOverwrites.create(newRole, { - VIEW_CHANNEL: true, - SEND_MESSAGES: true, - }); - - console.log(`Added permission overwrite for ${newRole.name} in ${channel.name}`); } - // now remove all the existing individual user permission overwrites - // and give them the role of the channel + // clear every individual user permission overwrite for the channel + for (const user of channel.members) { + const userId = user[0]; + const permissions = channel.permissionOverwrites.cache; - for (const memberID of channel.members) { - const member = interaction.guild.members.cache.get(`${memberID}`); - member.setPermissions(); + // Check if the member has access via individual perms + if (in_overwrites(permissions, userId)) { + // Remove the member from the channel's permission overwrites + channel.permissionOverwrites.delete(interaction.guild.members.cache.get(userId)); + } + user[1].roles.add(role); } - }); -} -function editRoles(interaction, roles) { - roles.forEach((role) => { - if (is_valid_course_name(role.name)) { - interaction.guild.channels - .fetch() - .then( - (channels) => ( - editChannels(interaction, channels, role), - console.log(`There are ${channels.size} channels.`) - ), - ) - .catch(console.error); - } - }); - interaction.reply({ - content: `✅ | found course chats and matching roles, cleared and set permission overwrites for roles.`, - ephemeral: true, - }); + // set the permissions for the new role on a channel + // const channel = interaction.guild.channels.cache.get('CHANNEL_ID'); + channel.permissionOverwrites.create(role, { + VIEW_CHANNEL: true, + SEND_MESSAGES: true, + }); + } } module.exports = { @@ -126,14 +75,10 @@ module.exports = { } // for all roles with name == chat name involving 4 letter prefix comp, seng, engg or binf, - // give the role the permission override to participate in the matching channel. - interaction.guild.roles + // Get all channels and run function + interaction.guild.channels .fetch() - .then( - (roles) => ( - editRoles(interaction, roles), console.log(`There are ${roles.size} roles.`) - ), - ) + .then(async (channels) => editChannels(interaction, channels)) .catch(console.error); } catch (error) { await interaction.reply("Error: " + error); From 24b6f1d6d6069fd6ab918bd4e019519ba2927262 Mon Sep 17 00:00:00 2001 From: Wolfdragon24 Date: Tue, 10 Oct 2023 17:52:24 +1100 Subject: [PATCH 3/8] Check for if user only has read perms for overwrite replacing and fix looping over members --- commands/course.js | 3 ++- commands/rolesPermOverride.js | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/commands/course.js b/commands/course.js index 36c31a01..d30ece6f 100644 --- a/commands/course.js +++ b/commands/course.js @@ -52,7 +52,8 @@ const is_valid_course = (course) => { ); }; -const in_overwrites = (overwrites, id) => overwrites.some((v, k) => k === id); +const in_overwrites = (overwrites, id) => + overwrites.find((v, k) => k === id).allow.bitfield === 1024n; module.exports = { data: new SlashCommandBuilder() diff --git a/commands/rolesPermOverride.js b/commands/rolesPermOverride.js index 76b36436..eb8b5240 100644 --- a/commands/rolesPermOverride.js +++ b/commands/rolesPermOverride.js @@ -18,7 +18,8 @@ const is_valid_course_name = (course) => { ); }; -const in_overwrites = (overwrites, id) => overwrites.some((v, k) => k === id); +const in_overwrites = (overwrites, id) => + overwrites.find((v, k) => k === id).allow.bitfield === 1024n; async function editChannels(interaction, channels) { for (const channel in channels) { @@ -40,14 +41,15 @@ async function editChannels(interaction, channels) { // clear every individual user permission overwrite for the channel for (const user of channel.members) { const userId = user[0]; + const userObj = user[1]; const permissions = channel.permissionOverwrites.cache; // Check if the member has access via individual perms if (in_overwrites(permissions, userId)) { // Remove the member from the channel's permission overwrites - channel.permissionOverwrites.delete(interaction.guild.members.cache.get(userId)); + channel.permissionOverwrites.delete(userObj); } - user[1].roles.add(role); + userObj.roles.add(role); } // set the permissions for the new role on a channel From 2e69bd23853ee33807fd53491ae913b70a1a1c01 Mon Sep 17 00:00:00 2001 From: Wolfdragon24 Date: Tue, 10 Oct 2023 18:13:32 +1100 Subject: [PATCH 4/8] Fix to functionality of iteration and editing roles --- commands/course.js | 2 +- commands/rolesPermOverride.js | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/commands/course.js b/commands/course.js index d30ece6f..54a290f4 100644 --- a/commands/course.js +++ b/commands/course.js @@ -53,7 +53,7 @@ const is_valid_course = (course) => { }; const in_overwrites = (overwrites, id) => - overwrites.find((v, k) => k === id).allow.bitfield === 1024n; + overwrites.find((v, k) => k === id)?.allow?.bitfield === 1024n; module.exports = { data: new SlashCommandBuilder() diff --git a/commands/rolesPermOverride.js b/commands/rolesPermOverride.js index eb8b5240..9ece76b3 100644 --- a/commands/rolesPermOverride.js +++ b/commands/rolesPermOverride.js @@ -19,20 +19,22 @@ const is_valid_course_name = (course) => { }; const in_overwrites = (overwrites, id) => - overwrites.find((v, k) => k === id).allow.bitfield === 1024n; + overwrites.find((v, k) => k === id)?.allow?.bitfield === 1024n; async function editChannels(interaction, channels) { - for (const channel in channels) { + for (const data of channels) { + const channel = data[1]; const is_valid = is_valid_course_name(channel.name); - + if (!is_valid || channel.type !== "GUILD_TEXT") continue; + console.log(channel); - let role = await interaction.guild.roles.cache.find( + let role = interaction.guild.roles.cache.find( (r) => r.name.toLowerCase() === channel.name.toLowerCase(), ); if (!role) { - role = interaction.guild.roles.create({ + role = await interaction.guild.roles.create({ name: channel.name.toLowerCase(), color: "BLUE", }); @@ -47,14 +49,14 @@ async function editChannels(interaction, channels) { // Check if the member has access via individual perms if (in_overwrites(permissions, userId)) { // Remove the member from the channel's permission overwrites - channel.permissionOverwrites.delete(userObj); + await channel.permissionOverwrites.delete(userObj); + await userObj.roles.add(role); } - userObj.roles.add(role); } // set the permissions for the new role on a channel // const channel = interaction.guild.channels.cache.get('CHANNEL_ID'); - channel.permissionOverwrites.create(role, { + await channel.permissionOverwrites.create(role, { VIEW_CHANNEL: true, SEND_MESSAGES: true, }); @@ -75,15 +77,17 @@ module.exports = { ephemeral: true, }); } + await interaction.deferReply(); + // for all roles with name == chat name involving 4 letter prefix comp, seng, engg or binf, // Get all channels and run function - interaction.guild.channels - .fetch() - .then(async (channels) => editChannels(interaction, channels)) - .catch(console.error); + const channels = await interaction.guild.channels.fetch(); + + await editChannels(interaction, channels); + await interaction.editReply("Successfully ported all user permissions to roles."); } catch (error) { - await interaction.reply("Error: " + error); + await interaction.editReply("Error: " + error); } }, }; From 57a33dbcf5f155eb93ddf59ad2b244841405115c Mon Sep 17 00:00:00 2001 From: Wolfdragon24 Date: Tue, 10 Oct 2023 18:26:18 +1100 Subject: [PATCH 5/8] Fix to initial working state --- commands/rolesPermOverride.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/commands/rolesPermOverride.js b/commands/rolesPermOverride.js index 9ece76b3..079b0c43 100644 --- a/commands/rolesPermOverride.js +++ b/commands/rolesPermOverride.js @@ -27,7 +27,6 @@ async function editChannels(interaction, channels) { const is_valid = is_valid_course_name(channel.name); if (!is_valid || channel.type !== "GUILD_TEXT") continue; - console.log(channel); let role = interaction.guild.roles.cache.find( (r) => r.name.toLowerCase() === channel.name.toLowerCase(), @@ -40,11 +39,14 @@ async function editChannels(interaction, channels) { }); } + const permissions = channel.permissionOverwrites.cache; + // clear every individual user permission overwrite for the channel for (const user of channel.members) { const userId = user[0]; const userObj = user[1]; - const permissions = channel.permissionOverwrites.cache; + + if (userObj.user.bot) continue; // Check if the member has access via individual perms if (in_overwrites(permissions, userId)) { From cb60613ca53dd691b9e36334d048e0d75aa85a6f Mon Sep 17 00:00:00 2001 From: Wolfdragon24 Date: Tue, 10 Oct 2023 18:27:05 +1100 Subject: [PATCH 6/8] Fix linting --- commands/rolesPermOverride.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/rolesPermOverride.js b/commands/rolesPermOverride.js index 079b0c43..ac952e4c 100644 --- a/commands/rolesPermOverride.js +++ b/commands/rolesPermOverride.js @@ -25,7 +25,7 @@ async function editChannels(interaction, channels) { for (const data of channels) { const channel = data[1]; const is_valid = is_valid_course_name(channel.name); - + if (!is_valid || channel.type !== "GUILD_TEXT") continue; let role = interaction.guild.roles.cache.find( From 7f56175017cab7699a4f7c5f41a6387b78d7112f Mon Sep 17 00:00:00 2001 From: Wolfdragon24 Date: Tue, 10 Oct 2023 18:54:27 +1100 Subject: [PATCH 7/8] Additional fixes to ordering and component operations to remove role and individual permissions correctly --- commands/course.js | 85 +++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/commands/course.js b/commands/course.js index 54a290f4..832c4d7d 100644 --- a/commands/course.js +++ b/commands/course.js @@ -145,52 +145,47 @@ module.exports = { }); } - // First, let's see if there's a role that matches the name of the course + // Check and fetch a channel corresponding to input + const channel = await interaction.guild.channels.cache.find( + (c) => c.name.toLowerCase() === course.toLowerCase(), + ); + + if (channel === undefined) { + return await interaction.reply({ + content: `❌ | The course chat for \`${course}\` does not exist.`, + ephemeral: true, + }); + } else if (channel.type !== "GUILD_TEXT") { + return await interaction.reply({ + content: `❌ | The course chat for \`${course}\` is not a text channel.`, + ephemeral: true, + }); + } + + const permissions = channel.permissionOverwrites.cache; + + // Then check if there's a role that matches the name of the course const role = await interaction.guild.roles.cache.find( (r) => r.name.toLowerCase() === course.toLowerCase(), ); - // If there is, let's see if the member already has that role + // Check if the role exists if (role !== undefined) { - if (!interaction.member.roles.cache.has(role.id)) { - // Find a channel with the same name as the course - const channel = await interaction.guild.channels.cache.find( - (c) => c.name.toLowerCase() === course.toLowerCase(), - ); - - // Otherwise, make sure that the channel exists, and is a text channel - if (channel === undefined) { - return await interaction.reply({ - content: `❌ | The course chat for \`${course}\` does not exist.`, - ephemeral: true, - }); - } else if (channel.type !== "GUILD_TEXT") { - return await interaction.reply({ - content: `❌ | The course chat for \`${course}\` is not a text channel.`, - ephemeral: true, - }); - } - - const permissions = channel.permissionOverwrites.cache; - - // Check if the member has access via role - if (in_overwrites(permissions, role.id)) { - // If they do remove the role - await interaction.member.roles.remove(role); - return await interaction.reply({ - content: `✅ | Removed you from the role and chat for \`${course}\`.`, - ephemeral: true, - }); - } - - // Check if the member has access via individual perms - if (in_overwrites(permissions, interaction.member.id)) { - // Remove the member from the channel's permission overwrites - await channel.permissionOverwrites.delete(interaction.member); - } + // Check if the member has access via individual perms + if (in_overwrites(permissions, interaction.member.id)) { + // Remove the member from the channel's permission overwrites if so + await channel.permissionOverwrites.delete(interaction.member); + } + // Check if the member has access via role + if ( + interaction.member.roles.cache.has(role.id) && + in_overwrites(permissions, role.id) + ) { + // If they do remove the role + await interaction.member.roles.remove(role); return await interaction.reply({ - content: `✅ | Removed you from the course chat for \`${course}\`.`, + content: `✅ | Removed you from the role and chat for \`${course}\`.`, ephemeral: true, }); } else { @@ -199,6 +194,18 @@ module.exports = { ephemeral: true, }); } + } else if (in_overwrites(permissions, interaction.member.id)) { + // Check if the user has individual perms and removes if so + await channel.permissionOverwrites.delete(interaction.member); + return await interaction.reply({ + content: `✅ | Removed you from the chat for \`${course}\`.`, + ephemeral: true, + }); + } else { + return await interaction.reply({ + content: `❌ | You do not have access to the chat for \`${course}\`.`, + ephemeral: true, + }); } } return await interaction.reply("Error: invalid subcommand."); From 085e19c573812d4e87fdf3fbbda23a8b48f883b0 Mon Sep 17 00:00:00 2001 From: Wolfdragon24 Date: Sat, 14 Oct 2023 09:32:54 +1100 Subject: [PATCH 8/8] Appended filter for both view only perms and view + send messages perms --- commands/course.js | 2 +- commands/rolesPermOverride.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/course.js b/commands/course.js index 832c4d7d..dac19ba6 100644 --- a/commands/course.js +++ b/commands/course.js @@ -53,7 +53,7 @@ const is_valid_course = (course) => { }; const in_overwrites = (overwrites, id) => - overwrites.find((v, k) => k === id)?.allow?.bitfield === 1024n; + [1024n, 3072n].includes(overwrites.find((v, k) => k === id)?.allow?.bitfield); module.exports = { data: new SlashCommandBuilder() diff --git a/commands/rolesPermOverride.js b/commands/rolesPermOverride.js index ac952e4c..293d7994 100644 --- a/commands/rolesPermOverride.js +++ b/commands/rolesPermOverride.js @@ -19,7 +19,7 @@ const is_valid_course_name = (course) => { }; const in_overwrites = (overwrites, id) => - overwrites.find((v, k) => k === id)?.allow?.bitfield === 1024n; + [1024n, 3072n].includes(overwrites.find((v, k) => k === id)?.allow?.bitfield); async function editChannels(interaction, channels) { for (const data of channels) {