Skip to content

Commit

Permalink
dev/course fix 5 merge (#161)
Browse files Browse the repository at this point in the history
* migrate from insou api to circles for the handbook commands (#128)

* migrate from insou api to circles for the handbook commands

* remove trailing forward slash in handbook.json

* handbook: the handbook is fixed

* Update handbook.js

commented out a console.log

---------

Co-authored-by: tunein <z5371683@ad.unsw.edu.au>
Co-authored-by: zcDay1 <113964162+zcDay1@users.noreply.github.com>

* prettier formatted

* chore(deps): update `renovate` config

* chore(deps): update docker/build-push-action action to v4 (#134)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Projects description command feature (#145)

* projects-descriptions v1 commit

* project-descriptions command v2 commit

* linting fixes for project-descriptions.js, and for handbook.js

---------

Co-authored-by: AcdSoftCo <106219586+AcdSoftCo@users.noreply.github.com>

* disable annoying carrotboard pins

* 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 merging

* Revert "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 merging"

This reverts commit 2f59c71.

* rolesPermOverride command  (#152)

* 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

---------

Co-authored-by: AcdSoftCo <106219586+AcdSoftCo@users.noreply.github.com>

* 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>

* Project descriptions (#154)

* project-descriptions.js: updated course descriptions written by the directors for 2023 levelling up with Projects Fair Day, and the discord bot CTF flag easter egg entry under this command included too for this event.

* made messages ephemeral to prevent chat from being spammed by users. And got rid of link embeds in the messages.

* lint update

---------

Co-authored-by: AcdSoftCo <106219586+AcdSoftCo@users.noreply.github.com>

* Dev/course channel fix 3 (#158)

* 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.

* Modified functions for course channel fixes

* Check for if user only has read perms for overwrite replacing and fix looping over members

* Fix to functionality of iteration and editing roles

* Fix to initial working state

* Fix linting

* Additional fixes to ordering and component operations to remove role and individual permissions correctly

* Appended filter for both view only perms and view + send messages perms

---------

Co-authored-by: AcdSoftCo <106219586+AcdSoftCo@users.noreply.github.com>
Co-authored-by: Wolfdragon24 <dragonbomber24@gmail.com>

* dev/course-channel-fix-5 (#160)

* 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.

* Modified functions for course channel fixes

* Check for if user only has read perms for overwrite replacing and fix looping over members

* Fix to functionality of iteration and editing roles

* Fix to initial working state

* Fix linting

* Additional fixes to ordering and component operations to remove role and individual permissions correctly

* Appended filter for both view only perms and view + send messages perms

* Appended single channel mode for permissions override

* Appended check command for role permissions

* Resolved merge conflicts in dev/course-channel-fix-4

---------

Co-authored-by: AcdSoftCo <106219586+AcdSoftCo@users.noreply.github.com>
Co-authored-by: Wolfdragon24 <dragonbomber24@gmail.com>

* Update rolesPermOverride.js

double equals updated to triple equals on line 156

---------

Co-authored-by: imagine-hussain <93496985+imagine-hussain@users.noreply.github.com>
Co-authored-by: tunein <z5371683@ad.unsw.edu.au>
Co-authored-by: AcdSoftCo <106219586+AcdSoftCo@users.noreply.github.com>
Co-authored-by: Jared L <48422312+lhjt@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: abiramen <7523422+abiramen@users.noreply.github.com>
Co-authored-by: Bigbugman <101852152+Bigbugman@users.noreply.github.com>
Co-authored-by: Wolfdragon24 <dragonbomber24@gmail.com>
Co-authored-by: Abraham Assariparambil Earnest <44077482+abe123442@users.noreply.github.com>
  • Loading branch information
10 people authored Oct 28, 2023
1 parent 17aec19 commit 9d12d77
Showing 1 changed file with 95 additions and 5 deletions.
100 changes: 95 additions & 5 deletions commands/rolesPermOverride.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,68 @@ async function editChannels(interaction, channels) {
}
}

async function isFixed(interaction, channel) {
const is_valid = is_valid_course_name(channel.name);

if (!is_valid || channel.type !== "GUILD_TEXT") return true;

const role = interaction.guild.roles.cache.find(
(r) => r.name.toLowerCase() === channel.name.toLowerCase(),
);

if (!role) return false;

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];

if (userObj.user.bot) continue;

// Check if the member has access via individual perms
if (in_overwrites(permissions, userId)) return false;
}

if (!in_overwrites(permissions, role.id)) return false;

return true;
}

async function allFixed(interaction, channels) {
const unfixed = [];
for (const data of channels) {
const channel = data[1];
const fixed = await isFixed(interaction, channel);

if (!fixed) unfixed.push(channel.name);
}

return unfixed;
}

module.exports = {
data: new SlashCommandBuilder()
.setName("rolespermoverride")
.setDescription(
"Looks for matches between roles and course chats and attaches permissions.",
)
.addBooleanOption((option) =>
option
.setName("singlechannel")
.setDescription(
"Should this command only be run on the current channel? (Default: False)",
)
.setRequired(false),
)
.addBooleanOption((option) =>
option
.setName("check")
.setDescription(
"Should a check be run on if the channel is fixed? (Default: False)",
)
.setRequired(false),
),
async execute(interaction) {
try {
Expand All @@ -84,11 +141,44 @@ module.exports = {

// for all roles with name == chat name involving 4 letter prefix comp, seng, engg or binf,

// Get all channels and run function
const channels = await interaction.guild.channels.fetch();

await editChannels(interaction, channels);
await interaction.editReply("Successfully ported all user permissions to roles.");
if (!interaction.options.getBoolean("singlechannel")) {
// Get all channels and run specified function
const channels = await interaction.guild.channels.fetch();

if (!interaction.options.getBoolean("check")) {
await editChannels(interaction, channels);
await interaction.editReply(
"Successfully ported all user permissions to roles.",
);
} else {
const unfixed = await allFixed(interaction, channels);

if (unfixed.length === 0) {
await interaction.editReply("All channels in this server appear fixed.");
} else {
await interaction.editReply(
`The following channels appear unfixed: ${unfixed.join(", ")}`,
);
}
}
} else {
const channel = interaction.channel;

if (!interaction.options.getBoolean("check")) {
await editChannels(interaction, [[undefined, channel]]);
await interaction.editReply(
"Successfully ported user permissions to roles in this channel",
);
} else {
const fixed = await isFixed(interaction, channel);

if (fixed) {
await interaction.editReply("This channel appears fixed.");
} else {
await interaction.editReply("This channel appears unfixed.");
}
}
}
} catch (error) {
await interaction.editReply("Error: " + error);
}
Expand Down

0 comments on commit 9d12d77

Please sign in to comment.