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

Update auto-join to try channel name prefixes #313

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion discord-scripts/thread-management/auto-join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,28 @@ async function autoJoinThread(
}
}

// All prefixes of the containing channel name, with dashes converted to
// spaces, ordered longest to shortest. For example, #mezo-engineering-musd
// would produce ["mezo engineering musd", "mezo engineering", "mezo"].
const roleMatchPrefixes = containingChannel?.name
.toLowerCase()
.split("-")
.reduce(
(allPrefixes, nameSegment) => [
...allPrefixes,
`${allPrefixes.at(-1) ?? []} ${nameSegment}`.trim(),
Copy link
Member

Choose a reason for hiding this comment

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

Just added .trim() here since on local test, roles were being outputted in some cases role here, role here is, role here there, otherwise let's merge!

],
[] as string[],
)
.reverse()

const matchingRole = server.roles.cache.find(
(role) => role.name.toLowerCase() === containingChannel?.name.toLowerCase(),
(role) =>
roleMatchPrefixes?.some(
(channelPrefixRole) =>
role.name.toLowerCase() ===
channelPrefixRole /* already lowercased above */,
),
)

if (matchingRole !== undefined) {
Expand Down
Loading