Skip to content

Commit

Permalink
Fix arrays + typechecks
Browse files Browse the repository at this point in the history
  • Loading branch information
zuuring committed Oct 28, 2024
1 parent 032c5eb commit b898a3f
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions discord-scripts/thread-management/auto-join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ 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 CUSTOM_CHANNEL_ROLE: Record<string, string> = {
// hiring: "PeopleOps",
"biz-dev-investor": "BD",
"press-relations": "M Group, Marketing",
interface ChannelRoleMapping {
channelName: string
roles: string[]
}

const hasCustomChannels = Object.keys(CUSTOM_CHANNEL_ROLE).length > 0
const CUSTOM_CHANNEL_ROLE: ChannelRoleMapping[] = [
{ channelName: "biz-dev-investor", roles: ["BD"] },
{ channelName: "press-relations", roles: ["M Group", "Marketing"] },
]

async function autoJoinThread(
thread: AnyThreadChannel<boolean>,
Expand All @@ -41,16 +43,16 @@ async function autoJoinThread(
}

const { guild: server, parent: containingChannel } = thread

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
if (hasCustomChannels && containingChannel) {
const roleNames = CUSTOM_CHANNEL_ROLE[containingChannel.name]
?.split(",")
.map((role) => role.trim())
if (containingChannel) {
const channelMapping = CUSTOM_CHANNEL_ROLE.find(
(mapping) => mapping.channelName === containingChannel.name,
)

if (channelMapping && channelMapping.roles.length > 0) {
const roleNames = channelMapping.roles

if (roleNames && roleNames.length > 0) {
const rolesToTag = roleNames
.map((roleName) =>
server.roles.cache.find(
Expand Down Expand Up @@ -82,13 +84,12 @@ async function autoJoinThread(
)
.reverse()

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

Check failure on line 87 in discord-scripts/thread-management/auto-join.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎····`
roleMatchPrefixes?.some(

Check failure on line 88 in discord-scripts/thread-management/auto-join.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
(channelPrefixRole) =>

Check failure on line 89 in discord-scripts/thread-management/auto-join.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `(channelPrefixRole)·=>⏎········role.name.toLowerCase()·===⏎········channelPrefixRole` with `··(channelPrefixRole)·=>·role.name.toLowerCase()·===·channelPrefixRole,`
role.name.toLowerCase() ===
channelPrefixRole
),

Check failure on line 92 in discord-scripts/thread-management/auto-join.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
)

if (matchingRole !== undefined) {
Expand Down

0 comments on commit b898a3f

Please sign in to comment.