glyde/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 get(api: api.Api) -> Result(GatewayInfo, api.CallFailure)

GET /gateway, as Get Gateway. The WebSocket URL and nothing else. The one route here that needs no token, and sending the bot’s anyway is harmless, so this goes through the same rest.Config as everything else.

pub fn get_bot(
  api: api.Api,
) -> Result(GatewayBot, api.CallFailure)

GET /gateway/bot, as Get Gateway Bot. The URL plus the recommended shard count and how many shards may identify in the same five-second window. A guessed shard count closes the socket 4010 or 4011, neither of which a reconnect fixes. Identifying past max_concurrency costs an INVALID_SESSION instead, which is why the answer feeds identify_queue.

pub fn get_bot_call() -> rest.Call(GatewayBot)

The Call for [get_bot], for building the request without sending it.

pub fn get_call() -> rest.Call(GatewayInfo)

The Call for [get], for building the request without sending it.

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