glyde/model/gateway_info

The two gateway-discovery responses. GET /gateway/bot carries the URL, the shard count and the session start limit; GET /gateway the URL alone.

Every field is required. A connect is planned from these numbers, and the penalty for guessing one is in SessionStartLimit.

Types

GET /gateway/bot.

pub type GatewayBot {
  GatewayBot(
    url: String,
    dial_host: gateway.Host,
    shards: Int,
    session_start_limit: SessionStartLimit,
  )
}

Constructors

  • GatewayBot(
      url: String,
      dial_host: gateway.Host,
      shards: Int,
      session_start_limit: SessionStartLimit,
    )

    Arguments

    url

    As Discord sent it, wss:// scheme and all.

    dial_host

    The same URL with the scheme taken off, which is what a shard dials. Hand it to gateway.Config.host.

    shards

    Discord’s recommendation. Higher is allowed, lower closes with 4011.

GET /gateway.

pub type GatewayInfo {
  GatewayInfo(url: String, dial_host: gateway.Host)
}

Constructors

  • GatewayInfo(url: String, dial_host: gateway.Host)

    Arguments

    url

    As Discord sent it, wss:// scheme and all.

    dial_host

    The same URL with the scheme taken off, which is what a shard dials. Hand it to gateway.Config.host.

The daily budget of session starts. Exceeding max_concurrency costs an INVALID_SESSION; exhausting remaining resets the bot’s token.

pub type SessionStartLimit {
  SessionStartLimit(
    total: Int,
    remaining: Int,
    reset_after_ms: Int,
    max_concurrency: Int,
  )
}

Constructors

  • SessionStartLimit(
      total: Int,
      remaining: Int,
      reset_after_ms: Int,
      max_concurrency: Int,
    )

    Arguments

    total

    1000 for most bots, more past 150 000 guilds.

    reset_after_ms

    A duration, not an instant: how long until remaining returns to total.

    max_concurrency

    How many shards may IDENTIFY in the same five-second window.

pub type StartWindow {
  Open(remaining: Int)
  Spent(resets_at_ms: Int)
}

Constructors

  • Open(remaining: Int)
  • Spent(resets_at_ms: Int)

    Wait, do not retry: trying past the limit resets the bot’s token. resets_at_ms is an instant on the caller’s clock, like every other deadline glyde hands back.

Values

pub fn identify_queue(
  bot: GatewayBot,
  now_ms now_ms: Int,
) -> identify_queue.Queue

reset_after is a duration and the queue counts instants. Read the clock when the response arrived: any later is time the queue thinks it still has.

pub fn session_start_limit_decoder() -> decode.Decoder(
  SessionStartLimit,
)
pub fn start_window(
  bot: GatewayBot,
  now_ms now_ms: Int,
) -> StartWindow

Same clock rule as identify_queue: reset_after is a duration, so read the clock when the response arrived, not when someone asks.

Search Document