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

Add multi-tagging #316

Merged
merged 5 commits into from
Oct 28, 2024
Merged

Add multi-tagging #316

merged 5 commits into from
Oct 28, 2024

Conversation

zuuring
Copy link
Member

@zuuring zuuring commented Oct 8, 2024

Notes

This adds the ability to tag several groups into one channel with the auto-tagging function.

### Notes
This adds the ability to tag several groups into one channel with the auto-tagging function.
@@ -26,7 +26,7 @@ import {
const CUSTOM_CHANNEL_ROLE: Record<string, string> = {
// hiring: "PeopleOps",
"biz-dev-investor": "BD",
"press-relations": "M Group",
"press-relations": "M Group, Marketing",
Copy link
Contributor

Choose a reason for hiding this comment

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

Might as well make this an array here instead of having to split later.

await placeholder.edit(channelMatchingRole.toString())
const roleNames = CUSTOM_CHANNEL_ROLE[containingChannel.name]
?.split(",")
.map((role) => role.trim())
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't a user input so no need to trim. If we allow users to set this manually later, we should trim when they give us a role name, rather than having to do it every time we check for matching channels.

@zuuring
Copy link
Member Author

zuuring commented Oct 28, 2024

@Shadowfiend Thanks for the comments! Just refactored this and added typechecks as well.

// hiring: "PeopleOps",
"biz-dev-investor": "BD",
"press-relations": "M Group",
interface ChannelRoleMapping {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not blocking but let's fix in a follow-up: as a general rule, use type * = { instead of interface * {.

Suggested change
interface ChannelRoleMapping {
type ChannelRoleMapping = {

(mapping) => mapping.channelName === containingChannel.name,
)

if (channelMapping && channelMapping.roles.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can really replace this outer if with:

const channelRoles = channelMapping?.roles ?? []

const rolesToTag = channelRoles.map...

Comment on lines +56 to +62
const rolesToTag = roleNames
.map((roleName) =>
server.roles.cache.find(
(role) => role.name.toLowerCase() === roleName.toLowerCase(),
),
)
.filter((role): role is Role => role !== undefined)
Copy link
Contributor

Choose a reason for hiding this comment

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

Slightly cleaner version we didn't use before:

Suggested change
const rolesToTag = roleNames
.map((roleName) =>
server.roles.cache.find(
(role) => role.name.toLowerCase() === roleName.toLowerCase(),
),
)
.filter((role): role is Role => role !== undefined)
// make sure roleNames is all lowercased beforehand.
const rolesToTag = roleNames
.filter((role): role is Role =>
roleNames.includes(role.name.toLowerCase()))

@@ -76,9 +87,7 @@ async function autoJoinThread(
const matchingRole = server.roles.cache.find(
(role) =>
roleMatchPrefixes?.some(
(channelPrefixRole) =>
role.name.toLowerCase() ===
channelPrefixRole /* already lowercased above */,
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels like this is an important note to keep 😬

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 couple of potential improvements but none blocking, let's :shipit:

@Shadowfiend Shadowfiend merged commit 7e6940f into main Oct 28, 2024
7 checks passed
@Shadowfiend Shadowfiend deleted the add-multi-tagging branch October 28, 2024 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants