EDA.Presence (EDA v0.3.0)

Copy Markdown View Source

Presence and activity builder for Discord bots.

Allows setting bot status (online, idle, dnd, invisible) and activities (playing, streaming, listening, watching, custom, competing).

Examples

# Build a presence with status and activity
presence = EDA.Presence.new(
  status: :dnd,
  activities: [EDA.Presence.playing("Elixir")]
)

# Update at runtime
EDA.set_presence(presence)

# Convenience — just set an activity
EDA.set_activity("Elixir", type: :playing)

Summary

Functions

Creates a Competing activity (type 5).

Creates a Custom Status activity (type 4).

Creates a Listening activity (type 2).

Builds a %Presence{} struct from keyword options.

Creates a Playing activity (type 0).

Creates a Streaming activity (type 1) with a Twitch/YouTube URL.

Serializes a %Presence{} to the Discord gateway format.

Creates a Watching activity (type 3).

Types

activity()

@type activity() :: %{
  :name => String.t(),
  :type => activity_type(),
  optional(:url) => String.t()
}

activity_type()

@type activity_type() ::
  :playing | :streaming | :listening | :watching | :custom | :competing

status()

@type status() :: :online | :idle | :dnd | :invisible

t()

@type t() :: %EDA.Presence{
  activities: [activity()],
  afk: boolean(),
  since: integer() | nil,
  status: status()
}

Functions

competing(name)

@spec competing(String.t()) :: activity()

Creates a Competing activity (type 5).

custom(name)

@spec custom(String.t()) :: activity()

Creates a Custom Status activity (type 4).

listening(name)

@spec listening(String.t()) :: activity()

Creates a Listening activity (type 2).

new(opts \\ [])

@spec new(keyword()) :: t()

Builds a %Presence{} struct from keyword options.

Options

  • :status — :online | :idle | :dnd | :invisible (default :online)

  • :activities — list of activity maps from builder functions
  • :afk — boolean (default false)
  • :since — unix timestamp in milliseconds, or nil

playing(name)

@spec playing(String.t()) :: activity()

Creates a Playing activity (type 0).

streaming(name, url)

@spec streaming(String.t(), String.t()) :: activity()

Creates a Streaming activity (type 1) with a Twitch/YouTube URL.

to_map(presence)

@spec to_map(t()) :: map()

Serializes a %Presence{} to the Discord gateway format.

watching(name)

@spec watching(String.t()) :: activity()

Creates a Watching activity (type 3).