glyde/gateway/identify
IDENTIFY (op 2): the config it carries and the frame it becomes.
Separate from frame so the wire envelope stays about the envelope, and
so Sharding, LargeThreshold and Properties are found where they are
configured, not in among the opcode tables.
Types
Everything IDENTIFY puts on the wire.
pub type Identity {
Identity(
token: token.Token,
intents: intents.Intents,
properties: Properties,
large_threshold: LargeThreshold,
shard: Sharding,
presence: option.Option(presence.Presence),
)
}
Constructors
-
Identity( token: token.Token, intents: intents.Intents, properties: Properties, large_threshold: LargeThreshold, shard: Sharding, presence: option.Option(presence.Presence), )Arguments
- presence
-
What the bot looks like the moment it connects. Op 3 sends the same object once it is live.
Guild size above which Discord sends an offline member list. Opaque so the clamp happens once, where the value is made, rather than again wherever it is written.
pub opaque type LargeThreshold
IDENTIFY’s properties object. Analytics only; Discord acts on none of
them. The $os spelling is deprecated, so these go out unprefixed.
pub type Properties {
Properties(os: String, browser: String, device: String)
}
Constructors
-
Properties(os: String, browser: String, device: String)
One shard’s place in the fleet, sent as [index, count]. Opaque because
index is 0-based and must be below count: sharding is the only thing
that can make one, so a fleet the gateway would answer with close 4010
cannot be built at all. Labelled and not a pair, because swapping the two
is also 4010 and takes a restart to spot.
pub opaque type Sharding
Why a fleet was refused. Both are configuration mistakes that no reconnect fixes, so they are caught before a shard exists.
pub type ShardingError {
EmptyFleet(count: Int)
IndexOutOfRange(index: Int, count: Int)
}
Constructors
-
EmptyFleet(count: Int)A fleet has at least one shard in it.
-
IndexOutOfRange(index: Int, count: Int)indexis 0-based, so shard 16 of 16 is not a shard.
Values
pub fn identify(identity: Identity) -> frame.Outbound
pub fn large_threshold(value: Int) -> LargeThreshold
Clamped rather than refused: a value outside Discord’s range is a number to correct, not a connection to fail.
pub fn large_threshold_value(threshold: LargeThreshold) -> Int
pub fn shard_index(sharding: Sharding) -> Int
This shard’s 0-based place in the fleet.
pub fn sharding(
index index: Int,
count count: Int,
) -> Result(Sharding, ShardingError)
sharding(index: 0, count: 1) is an unsharded bot, which Discord reads as
sending no shard array at all.