Crux v2020-03-17 17:55:51Z Crux.Gateway.Command View Source

Builds Gateway Commands.
Note: Only the sent ones can be found here.

A list of available op codes:

OP CodeName
0dispatchreceived only
1heartbeattwo way
2identifysent only
3status_updatesent only
4voice_state_updatesent only
5voice_guild_pingsent only
6resumesent only
7reconnectreceived only
8request_guild_memberssent only
9invalid_sessionreceived only
10helloreceived only
11heartbeat_ackreceived only

Gateway Lifecycle Flowchart

Link to this section Summary

Types

Used to set an activity via status_update/2.

Encoded command ready to be sent to the gateway via Crux.Gateway.Connection.send_command/3.

Link to this section Types

Link to this type

activity() View Source
activity() :: %{
  :name => String.t(),
  :type => non_neg_integer(),
  optional(:url) => String.t()
}

Used to set an activity via status_update/2.

:type must be a valid Activity Type

Note that streaming requires a twitch url pointing to a possible channel!

Encoded command ready to be sent to the gateway via Crux.Gateway.Connection.send_command/3.

If you want to build custom commands,
pass :erlang.term_to_binary/1 a map with the keys op and d,
and wrap it in a tuple with :binary as first element.

Link to this section Functions

Link to this function

heartbeat(sequence) View Source
heartbeat(sequence :: non_neg_integer() | nil) :: command()

Builds a Heartbeat command.

Used to signalize the server that the client is still alive and able to receive messages.

Link to this function

identify(args) View Source
identify(
  data :: %{
    :shard_id => non_neg_integer(),
    :shard_count => pos_integer(),
    :token => String.t(),
    optional(:presence) => Crux.Gateway.presence(),
    optional(:guild_subscriptions) => boolean()
  }
) :: command()

Builds an Identify command.

Used to identify the gateway connection and "log in".

Link to this function

request_guild_members(guild_id, opts \\ []) View Source
request_guild_members(
  guild_id :: Crux.Structs.Snowflake.t(),
  opts ::
    [
      query: String.t(),
      limit: non_neg_integer(),
      presences: boolean(),
      user_ids: Crux.Structs.Snowflake.t() | [Crux.Structs.Snowflake.t()]
    ]
    | map()
) :: command()

Builds a Request Guild Members command.

Used to request guild member for a specific guild.

Note: This must be sent to the connection handling the guild, not just any connection.

The gateway will respond with :GUILD_MEMBER_CHUNK packets until all appropriate members are received.

Link to this function

resume(map) View Source
resume(
  data :: %{seq: non_neg_integer(), token: String.t(), session: String.t()}
) :: command()

Builds a Resume command.

Used to resume into a session which was unexpectly disconnected and may be resumable.

Link to this function

status_update(status, game \\ nil) View Source
status_update(status :: String.t(), game :: activity() | nil) :: command()

Builds a Status Update command.

Used to update the status of the client, including activity.

Link to this function

voice_state_update(guild_id, channel_id \\ nil, states \\ []) View Source
voice_state_update(
  guild_id :: Crux.Structs.Snowflake.t(),
  channel_id :: Crux.Structs.Snowflake.t() | nil,
  states :: [self_mute: boolean(), self_deaf: boolean()]
) :: command()

Builds a Voice State Update command.

Used to join, switch between, and leave voice channels and/or change self_mute or self_deaf states.