All files / discord-guild-workspace/lib options.ts

100% Statements 48/48
100% Branches 11/11
100% Functions 4/4
100% Lines 48/48

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 491x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 5x 5x 5x 5x 1x 1x 5x 5x 4x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
export type DiscordChannelOption = {
  id: string
  name: string
  type: "text" | "announcement" | "thread" | "forum"
}
 
export type DiscordRoleOption = {
  id: string
  name: string
}
 
export type DiscordConfigOptions = {
  channels: DiscordChannelOption[]
  roles: DiscordRoleOption[]
}
 
export function getChannelOptionLabel(channel: DiscordChannelOption): string {
  const typeLabel = {
    announcement: "Announcement",
    forum: "Forum",
    text: "Text",
    thread: "Thread",
  }[channel.type]
 
  return `#${channel.name} ยท ${typeLabel}`
}
 
export function getSelectedOptionState<TOption extends { id: string }>(
  options: TOption[],
  selectedId: string
): { option?: TOption; missing: boolean } {
  if (!selectedId) {
    return { missing: false }
  }
 
  const option = options.find((candidate) => candidate.id === selectedId)
 
  return option ? { option, missing: false } : { missing: true }
}
 
export function getMissingRoleIds(
  roles: DiscordRoleOption[],
  selectedIds: string[]
): string[] {
  const availableIds = new Set(roles.map((role) => role.id))
 
  return selectedIds.filter((id) => !availableIds.has(id))
}