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

Main entry point for Crux.Gateway.

This module fits under a supervision tree, see start_link/1 arguments for configuration.

Link to this section Summary

Types

The gateway reference

Used to start Crux.Gateway.

Used as initial presence for every session.

Functions

Returns a specification to start this module under a supervisor.

Starts a Crux.Gateway process linked to the current process.

Link to this section Types

The gateway reference

Link to this type

options() View Source
options() ::
  %{
    :token => String.t(),
    :url => String.t() | (() -> String.t()),
    :shard_count => pos_integer(),
    optional(:shards) => [non_neg_integer() | Range.t()],
    optional(:presence) => presence(),
    optional(:guild_subscriptions) => boolean(),
    optional(:dispatcher) =>
      GenStage.Dispatcher.t() | {GenStage.Dispatcher.t(), term()}
  }
  | list()

Used to start Crux.Gateway.

See start_link/1

Notes:

  • :token can be retrieved from here.

  • :url you can GET from /gateway/bot (or Crux.Rest.gateway_bot/0).

    This can also be a function with an arity of 0 returning it.

  • :shard_count same as :url.

  • Optionally :shards, which has to be a list of numbers and ranges.
    Examples: [1..3], [1, 2, 3], [1..3, 8, 9]

    Defaults to 0..shard_count-1.

  • Optionally :presence, which is used for the initial presence of every session.
    This should be a map with a "game" and "status" key, or a function with an arity of one (the shard id) and returning such a map, or nil for the default.
    If a function, it will be invoked whenever a shard is about to identify.

    Defaults to %{"game" => nil, "status" => "online"}.

  • Optionally :guild_subscriptions, aids large or generally stateless bots by opting out of several events and less data being sent over the gateway.
    For more information see Discord Docs and the relevant PR on GitHub.

    Defaults to true

  • Optionally :dispatcher, which has to be a valid GenStage.Dispatcher or a tuple of one and initial state.
    See Crux.Gateway.Connection.Producer for more info.

    Defaults to GenStage.BroadcastDispatcher

Link to this type

presence() View Source
presence() :: (non_neg_integer() -> map()) | map()

Used as initial presence for every session.

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

start_link(gateway_opts) View Source
start_link(opts_or_tuple :: options() | {options(), Supervisor.options()}) ::
  Supervisor.on_start()

Starts a Crux.Gateway process linked to the current process.

Options are either just options/0 or a tuple of options/0 and Supervisor.options/0.