Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defense channels and rolemapping #301

Merged
merged 17 commits into from
Jul 2, 2024
Merged

Defense channels and rolemapping #301

merged 17 commits into from
Jul 2, 2024

Conversation

zuuring
Copy link
Member

@zuuring zuuring commented Mar 18, 2024

Notes

This adds a new discord command defense-audit which has one parameter client-name which will then perform the following steps:

  • Create two channels, int-clientname-audit and ext-clientname-audit
  • Create two new roles Defense Internal: clientname and Defense Extenal: clientname
  • Grant ViewChannel access to both channels for Defense Internal: * and only ext-*-audit channel access to Defense Extenal
  • Generate an invite link for both channels

Screenshot

Screenshot 2024-03-20 at 13 51 15

Automatic role assignment

Also included in this PR is automatic role assignment based of the invite code used. Due to lack of IDs associated to GuildMemberAdd events when a new user joins discord, the only way to tie a discord user to an invite link is to count invite code uses within the guild and compare it once a new member has joined the discord. For this to work, we check the invites and match role assignment to channel.name the invite link was generated from.

To-do

  • Setup defense-audit command
  • Add rolemapping based on invite joins
  • Fix issue on int-client-name-audit channels not finding correct role for ext-client-name-audit channels

### Notes
This adds an additional feature to the new audit channel flow. Once an `ext-name-audit` channel is setup, now you can make an `int-name-audit` channel, which will perform these steps:

1. Setup a new role `Defense Internal: Name`
2. Generate an invite for the `int-name-audit` channel
3. Check if a matching `ext-name-audit` channel exists, if so assign `ViewChannel` permission to `Defense Internal: name` role.
@zuuring zuuring changed the title Setup Defense Internal Defense channel and rolemapping Mar 18, 2024
@zuuring zuuring changed the title Defense channel and rolemapping Defense channels and rolemapping Mar 18, 2024
This is still a work in progress just testing out the ability of assigning a role to an invite based of the uses it has.
Rewrite some of the checks and counts in-order to correctly match the role. The previous method was breaking on different format channels such as `ext-thesis-test-audit`
Moves `listInvites` into it's own function for easier calls
Refactor the `guildMemberAdd` event to resolve lint expression errors and make sure channel name is found correctly based on ext, int patterns
Resolves the issue that would fail to assign internal roles to external channel if the channel name had the format `ext-client-name-audit` vs `ext-clientname-audit`
This fixes the bug happening on invites not counting correctly if they were being used more than 2 times on certain edge cases.
This is still WIP but adds the `defense-audit` command with the parameter `client-name` to automatically build `int-clientname-audit` and `ext-clientname-audit` channels with two roles `Defense Internal: ClientName` and `Defense External: ClientName`.

Can only be run from the `defense` category
This commit makes it so the `defense-audit` command can only be run within the `defense` parent category of channels and will send a reply if it isn't working as it should.

Also adds an `interaction.editReply` inorder to avoid any timeout issues happening
Removes the debug loggers from the scripts, not needed anymore!
@zuuring zuuring marked this pull request as ready for review March 20, 2024 14:17
@zuuring zuuring added the enhancement New feature or request label Mar 21, 2024
@Shadowfiend
Copy link
Contributor

Question here: can we kill the embeds in the intro message?

Copy link
Contributor

@Shadowfiend Shadowfiend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a handful of questions & comments.

discord-scripts/invite-management.ts Outdated Show resolved Hide resolved
discord-scripts/invite-management.ts Outdated Show resolved Hide resolved
discord-scripts/invite-management.ts Outdated Show resolved Hide resolved
discord-scripts/invite-management.ts Outdated Show resolved Hide resolved
discord-scripts/invite-management.ts Show resolved Hide resolved
discord-scripts/invite-management.ts Outdated Show resolved Hide resolved
discord-scripts/invite-management.ts Outdated Show resolved Hide resolved
discord-scripts/invite-management.ts Show resolved Hide resolved
discord-scripts/invite-management.ts Outdated Show resolved Hide resolved
discord-scripts/invite-management.ts Outdated Show resolved Hide resolved
This commit adds a number of changes to the audit channel flow. mainly:

- Update permissions if channel already exists
- Check if role already exists, if so skip
- Changed logic so that if audit channels already exist, we output a different message to interaction
- Remove embeds by wrapping invite URL in quotes.
- Change verbiage around messages
- Separates InternalChannel and externalChannel
- Changed invite code permission match
@zuuring
Copy link
Member Author

zuuring commented Apr 12, 2024

@Shadowfiend Just pushed an update to this with fixes to the review comments as following:

  • Update permissions if channel already exists
  • Check if role already exists, if so skip
  • Changed logic so that if audit channels already exist, we output a different message to interaction
  • Remove embeds by wrapping invite URL in quotes.
  • Change verbiage around messages
  • Separates InternalChannel and externalChannel
  • Changed invite code permission match

Now one thing that came up, turns out Discord channel categories have a limit of max (50) channels per category. Should we maybe setup an "Audit" category or even (not ideal) a channel category on a per client basis?

@Shadowfiend
Copy link
Contributor

Now one thing that came up, turns out Discord channel categories have a limit of max (50) channels per category. Should we maybe setup an "Audit" category or even (not ideal) a channel category on a per client basis?

Lawd. I think we can hold for now, as I don't think we're going to have 20 audits going in parallel, and older audits will get archived. Making them their own category is a good idea though and we can discuss with Defense once we've got the basics working here.

This commit switches over from discordjs `Collection` in favour of storing invites as an object.
Copy link
Contributor

@Shadowfiend Shadowfiend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think I'm going to hold this up on the remaining remarks—it's close though!

discord-scripts/invite-management.ts Outdated Show resolved Hide resolved
discord-scripts/invite-management.ts Show resolved Hide resolved
discord-scripts/invite-management.ts Outdated Show resolved Hide resolved
discord-scripts/invite-management.ts Outdated Show resolved Hide resolved
This commit does some refactoring based off review feedback (thank you!) as well as making sure the invite uses / expiry date is listed properly.
@zuuring
Copy link
Member Author

zuuring commented Apr 22, 2024

@Shadowfiend Just pushed an update on this with the fixes based on your review! I also added a way to show expiry date using Discord's built in time rendering. That way we get a nice hover event when going over the expiry time.
Screenshot 2024-04-22 at 16 06 29

Copy link
Contributor

@Shadowfiend Shadowfiend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good, let's :shipit:

@Shadowfiend Shadowfiend merged commit fef77fa into main Jul 2, 2024
7 checks passed
@Shadowfiend Shadowfiend deleted the internal-channel-role branch July 2, 2024 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants