Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
This commit renames main channel const to `CUSTOM_CHANNEL_ROLE` and makes sure `matchingChannel` check runs before the rest.
  • Loading branch information
zuuring committed Apr 4, 2024
1 parent f5a9c94 commit 03a82f5
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions discord-scripts/thread-management/auto-join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
// it to mention the right role. Discord's behavior in this scenario is not to
// ping the role, but to add all its members to the thread.

const PRIVATE_CHANNELS = [{ channelName: "hiring", roleName: "PeopleOps" }]
const CUSTOM_CHANNEL_ROLE = [{ channelName: "hiring", roleName: "PeopleOps" }]

async function autoJoinThread(
thread: AnyThreadChannel<boolean>,
Expand All @@ -38,6 +38,21 @@ async function autoJoinThread(

const placeholder = await thread.send("<placeholder>")

// Use this to assign a specific role based on the mapping in CUSTOM_CHANNEL_ROLE, in order to map specific roles/channels
const matchingChannel = CUSTOM_CHANNEL_ROLE.find(
(channel) => containingChannel?.name.endsWith(channel.channelName),
)
if (matchingChannel) {
const channelMatchingRole = server.roles.cache.find(
(role) =>
role.name.toLowerCase() === matchingChannel.roleName.toLowerCase(),
)
if (channelMatchingRole) {
await placeholder.edit(channelMatchingRole.toString())
return
}
}

const matchingRole = server.roles.cache.find(
(role) => role.name.toLowerCase() === containingChannel?.name.toLowerCase(),
)
Expand Down Expand Up @@ -74,21 +89,6 @@ async function autoJoinThread(
await placeholder.edit(server.roles.everyone.toString())
}

// Use this to assign a specific role based on the mapping in PRIVATE_CHANNELS, in order to map specific roles/channels
const matchingChannel = PRIVATE_CHANNELS.find(
(channel) => containingChannel?.name.endsWith(channel.channelName),
)
if (matchingChannel) {
const channelMatchingRole = server.roles.cache.find(
(role) =>
role.name.toLowerCase() === matchingChannel.roleName.toLowerCase(),
)
if (channelMatchingRole) {
await placeholder.edit(channelMatchingRole.toString())
return
}
}

// If we hit this spot, be a monster and delete the useless placeholder and
// pray for our soul. Placeholder code as we figure out the best way to
// handle the General category.
Expand Down

0 comments on commit 03a82f5

Please sign in to comment.