-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add multi-tagging #316
Conversation
### 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", |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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.
@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 { |
There was a problem hiding this comment.
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 * {
.
interface ChannelRoleMapping { | |
type ChannelRoleMapping = { |
(mapping) => mapping.channelName === containingChannel.name, | ||
) | ||
|
||
if (channelMapping && channelMapping.roles.length > 0) { |
There was a problem hiding this comment.
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...
const rolesToTag = roleNames | ||
.map((roleName) => | ||
server.roles.cache.find( | ||
(role) => role.name.toLowerCase() === roleName.toLowerCase(), | ||
), | ||
) | ||
.filter((role): role is Role => role !== undefined) |
There was a problem hiding this comment.
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:
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 */, |
There was a problem hiding this comment.
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 😬
There was a problem hiding this 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
Notes
This adds the ability to tag several groups into one channel with the auto-tagging function.