Skip to content

Commit d55e093

Browse files
zcDay1AcdSoftCo
andauthored
Roles perm override (#153)
* rolesPermOverride command is a script or one-time use command to attach every course role with permissions to view and send messages in any text channel with identical name. Please review and test before mergin * BUGGY CODE but still progress over the previous commit, I will come back this evening to fix * rolesPermOverride command: now admin-only command, and I've tested it for various cases regarding if a channel exists, if a role exists for a channel that doesnt exist, if there are two channels with the same name as a role and vice versa, and it works without error * course.js: removed code to create individual user permission overwrites in each channel --------- Co-authored-by: AcdSoftCo <106219586+AcdSoftCo@users.noreply.github.com>
1 parent da9b795 commit d55e093

File tree

1 file changed

+4
-92
lines changed

1 file changed

+4
-92
lines changed

commands/course.js

Lines changed: 4 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -128,52 +128,8 @@ module.exports = {
128128
});
129129
}
130130

131-
// Otherwise, find a channel with the same name as the course
132-
const channel = await interaction.guild.channels.cache.find(
133-
(c) => c.name.toLowerCase() === course.toLowerCase(),
134-
);
135-
136-
// Make sure that the channel exists, and is a text channel
137-
if (channel === undefined) {
138-
return await interaction.reply({
139-
content: `❌ | The course chat for \`${course}\` does not exist. If you'd like for it to be created, please raise a ticket in <#${MODERATION_REQUEST_CHANNEL}>.`,
140-
ephemeral: true,
141-
});
142-
} else if (channel.type !== "GUILD_TEXT") {
143-
return await interaction.reply({
144-
content: `❌ | The course chat for \`${course}\` is not a text channel.`,
145-
ephemeral: true,
146-
});
147-
}
148-
149-
const permissions = new Permissions(
150-
channel.permissionsFor(interaction.user.id).bitfield,
151-
);
152-
153-
// Check if the member already has an entry in the channel's permission overwrites, and update
154-
// the entry if they do just to make sure that they have the correct permissions
155-
if (
156-
permissions.has([
157-
Permissions.FLAGS.VIEW_CHANNEL,
158-
Permissions.FLAGS.SEND_MESSAGES,
159-
])
160-
) {
161-
await channel.permissionOverwrites.edit(interaction.member, {
162-
VIEW_CHANNEL: true,
163-
});
164-
return await interaction.reply({
165-
content: `❌ | You are already in the course chat for \`${course_with_alias}\`.`,
166-
ephemeral: true,
167-
});
168-
}
169-
170-
// Add the member to the channel's permission overwrites
171-
await channel.permissionOverwrites.create(interaction.member, {
172-
VIEW_CHANNEL: true,
173-
});
174-
175131
return await interaction.reply({
176-
content: `✅ | Added you to the chat for ${course_with_alias}.`,
132+
content: `✅ | End of command - ${course_with_alias}.`,
177133
ephemeral: true,
178134
});
179135
} else if (interaction.options.getSubcommand() === COMMAND_LEAVE) {
@@ -182,7 +138,7 @@ module.exports = {
182138

183139
if (!is_valid_course(course)) {
184140
return await interaction.reply({
185-
content: `❌ | You are not allowed to leave this channel using this command.`,
141+
content: `❌ | Not a valid course.`,
186142
ephemeral: true,
187143
});
188144
}
@@ -196,63 +152,19 @@ module.exports = {
196152
if (role !== undefined) {
197153
if (!interaction.member.roles.cache.has(role.id)) {
198154
return await interaction.reply({
199-
content: `❌ | You are not in the course chat for \`${course}\`.`,
155+
content: `❌ | You do not have the role for \`${course}\`.`,
200156
ephemeral: true,
201157
});
202158
}
203159

204160
// If they do, let's remove the role from them
205161
await interaction.member.roles.remove(role);
206162
return await interaction.reply({
207-
content: `✅ | Removed you from the chat for \`${course}\`.`,
163+
content: `✅ | Removed you from the role and chat for \`${course}\`.`,
208164
ephemeral: true,
209165
});
210166
}
211-
212-
// Find a channel with the same name as the course
213-
const channel = await interaction.guild.channels.cache.find(
214-
(c) => c.name.toLowerCase() === course.toLowerCase(),
215-
);
216-
217-
// Otherwise, make sure that the channel exists, and is a text channel
218-
if (channel === undefined) {
219-
return await interaction.reply({
220-
content: `❌ | The course chat for \`${course}\` does not exist.`,
221-
ephemeral: true,
222-
});
223-
} else if (channel.type !== "GUILD_TEXT") {
224-
return await interaction.reply({
225-
content: `❌ | The course chat for \`${course}\` is not a text channel.`,
226-
ephemeral: true,
227-
});
228-
}
229-
230-
const permissions = new Permissions(
231-
channel.permissionsFor(interaction.user.id).bitfield,
232-
);
233-
234-
// Check if the member already has an entry in the channel's permission overwrites
235-
if (
236-
!permissions.has([
237-
Permissions.FLAGS.VIEW_CHANNEL,
238-
Permissions.FLAGS.SEND_MESSAGES,
239-
])
240-
) {
241-
return await interaction.reply({
242-
content: `❌ | You are not in the course chat for \`${course}\`.`,
243-
ephemeral: true,
244-
});
245-
}
246-
247-
// Remove the member from the channel's permission overwrites
248-
await channel.permissionOverwrites.delete(interaction.member);
249-
250-
return await interaction.reply({
251-
content: `✅ | Removed you from the course chat for \`${course}\`.`,
252-
ephemeral: true,
253-
});
254167
}
255-
256168
return await interaction.reply("Error: invalid subcommand.");
257169
} catch (error) {
258170
await interaction.reply("Error: " + error);

0 commit comments

Comments
 (0)