glyde/model/channel

Channels, threads and permission overwrites.

One flat record with a type_, not a sum type: twelve of the thirteen types carry name, so a sum type would force a twelve-arm case to read it.

Only id and type_ are required, so an interaction’s partial channel decodes through the same decoder as a full one.

Types

The body of GET /guilds/{id}/threads/active, which is every active thread at once. Discord sends no has_more here, so there is no page to ask for.

pub type ActiveThreads {
  ActiveThreads(
    threads: List(Channel),
    members: List(ThreadMember),
  )
}

Constructors

A channel of any kind, threads included.

pub type Channel {
  Channel(
    id: id.Id(id.Channel),
    type_: ChannelType,
    guild_id: option.Option(id.Id(id.Guild)),
    position: option.Option(Int),
    permission_overwrites: option.Option(
      List(PermissionOverwrite),
    ),
    name: option.Option(String),
    topic: option.Option(String),
    nsfw: option.Option(Bool),
    last_message_id: option.Option(id.Id(id.Message)),
    bitrate: option.Option(Int),
    user_limit: option.Option(Int),
    rate_limit_per_user: option.Option(Int),
    recipients: option.Option(List(user.User)),
    icon: option.Option(String),
    owner_id: option.Option(id.Id(id.User)),
    application_id: option.Option(id.Id(id.Application)),
    managed: option.Option(Bool),
    parent_id: option.Option(id.Id(id.Channel)),
    last_pin_timestamp: option.Option(String),
    rtc_region: option.Option(String),
    video_quality_mode: option.Option(VideoQualityMode),
    message_count: option.Option(Int),
    member_count: option.Option(Int),
    thread_metadata: option.Option(ThreadMetadata),
    member: option.Option(ThreadMember),
    default_auto_archive_duration: option.Option(
      ThreadAutoArchiveDuration,
    ),
    permissions: option.Option(permissions.Permissions),
    flags: option.Option(flags.Flags(ChannelFlag)),
    total_message_sent: option.Option(Int),
    default_thread_rate_limit_per_user: option.Option(Int),
    newly_created: option.Option(Bool),
  )
}

Constructors

pub type ChannelFlag {
  Pinned
  RequireTag
  HideMediaDownloadOptions
  IsSpoilerChannel
}

Constructors

  • Pinned

    A forum or media post pinned to the top of its parent.

  • RequireTag

    The parent forum requires a tag on every post.

  • HideMediaDownloadOptions
  • IsSpoilerChannel

    Every attachment in the channel is treated as a spoiler.

Live values are 0 to 5, 10 to 13, 15 and 16. 14 is hub-only, and 6 to 9 were withdrawn but can still turn up in cached data.

pub type ChannelType {
  GuildText
  Dm
  GuildVoice
  GroupDm
  GuildCategory
  GuildAnnouncement
  AnnouncementThread
  PublicThread
  PrivateThread
  GuildStageVoice
  GuildDirectory
  GuildForum
  GuildMedia
  UnknownChannelType(Int)
}

Constructors

  • GuildText
  • Dm
  • GuildVoice
  • GroupDm
  • GuildCategory
  • GuildAnnouncement
  • AnnouncementThread
  • PublicThread
  • PrivateThread
  • GuildStageVoice
  • GuildDirectory
  • GuildForum
  • GuildMedia
  • UnknownChannelType(Int)

Who an overwrite applies to. Three cases, not two Options: a type Discord adds after this build is neither a role nor a member, and treating it as either grants or denies the wrong people.

pub type OverwriteTarget {
  RoleTarget(id.Id(id.Role))
  MemberTarget(id.Id(id.User))
  UnknownTarget(id.Id(id.Overwrite), Int)
}

Constructors

pub type OverwriteType {
  RoleOverwrite
  MemberOverwrite
  UnknownOverwriteType(Int)
}

Constructors

  • RoleOverwrite
  • MemberOverwrite
  • UnknownOverwriteType(Int)

id is a role id or a user id, and only type_ says which. Read it through overwrite_target.

pub type PermissionOverwrite {
  PermissionOverwrite(
    id: id.Id(id.Overwrite),
    type_: OverwriteType,
    allow: permissions.Permissions,
    deny: permissions.Permissions,
  )
}

Constructors

Minute values, not an ordinal: 60, 1440, 4320, 10080.

pub type ThreadAutoArchiveDuration {
  OneHour
  OneDay
  ThreeDays
  OneWeek
  UnknownAutoArchiveDuration(Int)
}

Constructors

  • OneHour
  • OneDay
  • ThreeDays
  • OneWeek
  • UnknownAutoArchiveDuration(Int)

The body of the two archived thread listings, which page. members holds only the bot’s own membership, and only of the threads it has joined.

pub type ThreadList {
  ThreadList(
    threads: List(Channel),
    members: List(ThreadMember),
    has_more: Bool,
  )
}

Constructors

  • ThreadList(
      threads: List(Channel),
      members: List(ThreadMember),
      has_more: Bool,
    )

    Arguments

    has_more

    Another page exists before the oldest thread returned.

One user’s membership of one thread. Mind the collision: Channel.member is a ThreadMember, and ThreadMember.member is a GuildMember.

pub type ThreadMember {
  ThreadMember(
    id: option.Option(id.Id(id.Channel)),
    user_id: option.Option(id.Id(id.User)),
    join_timestamp: String,
    flags: Int,
    member: option.Option(member.GuildMember),
  )
}

Constructors

pub type ThreadMetadata {
  ThreadMetadata(
    archived: Bool,
    auto_archive_duration: ThreadAutoArchiveDuration,
    archive_timestamp: String,
    locked: Bool,
    invitable: option.Option(Bool),
    create_timestamp: option.Option(String),
  )
}

Constructors

  • ThreadMetadata(
      archived: Bool,
      auto_archive_duration: ThreadAutoArchiveDuration,
      archive_timestamp: String,
      locked: Bool,
      invitable: option.Option(Bool),
      create_timestamp: option.Option(String),
    )

    Arguments

    auto_archive_duration

    MINUTES.

    archive_timestamp

    ISO-8601, when the archive flag last changed.

    invitable

    Private threads only.

    create_timestamp

    Only threads created after 2022-01-09.

pub type VideoQualityMode {
  AutoQuality
  FullQuality
  UnknownVideoQualityMode(Int)
}

Constructors

  • AutoQuality
  • FullQuality
  • UnknownVideoQualityMode(Int)

Values

pub fn auto_archive_duration_from_int(
  value: Int,
) -> ThreadAutoArchiveDuration
pub fn auto_archive_duration_to_int(
  value: ThreadAutoArchiveDuration,
) -> Int
pub fn auto_archive_duration_to_json(
  value: ThreadAutoArchiveDuration,
) -> json.Json
pub fn channel_flags(
  of chosen: List(ChannelFlag),
) -> flags.Flags(ChannelFlag)

Build the flags an edit sends. Anything decoded off the wire should be edited with with_flag instead, so bits this build cannot name survive.

pub fn channel_type_decoder() -> decode.Decoder(ChannelType)
pub fn channel_type_from_int(value: Int) -> ChannelType
pub fn channel_type_to_int(value: ChannelType) -> Int
pub fn channel_type_to_json(value: ChannelType) -> json.Json
pub fn has_flag(
  bits: flags.Flags(ChannelFlag),
  flag: ChannelFlag,
) -> Bool
pub fn is_dm(type_: ChannelType) -> Bool
pub fn is_textable(type_: ChannelType) -> Bool

Voice and stage channels have a text chat too.

pub fn is_thread(type_: ChannelType) -> Bool
pub fn is_thread_only(type_: ChannelType) -> Bool

Forums and media channels hold threads only, so they are not textable.

pub fn is_voice(type_: ChannelType) -> Bool
pub const no_channel_flags: flags.Flags(ChannelFlag)
pub fn overwrite_target(
  overwrite: PermissionOverwrite,
) -> OverwriteTarget
pub fn overwrite_type_from_int(value: Int) -> OverwriteType
pub fn overwrite_type_to_int(value: OverwriteType) -> Int
pub fn overwrite_type_to_json(value: OverwriteType) -> json.Json
pub fn permission_overwrite_decoder() -> decode.Decoder(
  PermissionOverwrite,
)
pub fn permission_overwrite_to_json(
  overwrite: PermissionOverwrite,
) -> json.Json
pub fn thread_list_decoder() -> decode.Decoder(ThreadList)
pub fn thread_member_decoder() -> decode.Decoder(ThreadMember)
pub fn video_quality_mode_decoder() -> decode.Decoder(
  VideoQualityMode,
)
pub fn video_quality_mode_from_int(
  value: Int,
) -> VideoQualityMode
pub fn video_quality_mode_to_int(value: VideoQualityMode) -> Int
pub fn video_quality_mode_to_json(
  value: VideoQualityMode,
) -> json.Json
Search Document