EDA.Gateway.MemberChunker (EDA v0.3.0)

Copy Markdown View Source

Orchestrates OP 8 (Request Guild Members) requests with nonce-based tracking.

Supports fire-and-forget caching, synchronous awaiting, prefix search, and fetching by user IDs. Chunks are tracked by nonce and requests are cleaned up on timeout.

Discord rate limits requests for all members of a guild (query: "" and limit: 0) to one per guild every 30 seconds. Those requests are throttled here: a request made during the cooldown is queued and sent when the window opens, so callers never silently lose a request. Prefix searches and user_ids lookups are exempt and always go out immediately.

The cooldown can be tuned with config :eda, member_chunk_cooldown_ms: 30_000.

Summary

Functions

Requests all members and blocks until all chunks arrive.

Returns a specification to start this module under a supervisor.

Fetches specific members by user IDs (max 100).

Called by Events when a GUILD_MEMBERS_CHUNK arrives.

Called by Events when Discord answers an OP 8 with a RATE_LIMITED dispatch.

Fire-and-forget: requests all members for a guild, caches automatically.

Searches members by username prefix (max 100 results).

Functions

await(guild_id, opts \\ [])

@spec await(
  String.t() | integer(),
  keyword()
) :: {:ok, [map()]} | {:error, :timeout}

Requests all members and blocks until all chunks arrive.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

fetch(guild_id, user_ids, opts \\ [])

@spec fetch(String.t() | integer(), [String.t() | integer()], keyword()) ::
  {:ok, [map()]} | {:error, :timeout}

Fetches specific members by user IDs (max 100).

handle_chunk(data)

@spec handle_chunk(map()) :: :ok

Called by Events when a GUILD_MEMBERS_CHUNK arrives.

handle_rate_limited(data)

@spec handle_rate_limited(map()) :: :ok

Called by Events when Discord answers an OP 8 with a RATE_LIMITED dispatch.

request(guild_id, opts \\ [])

@spec request(
  String.t() | integer(),
  keyword()
) :: :ok

Fire-and-forget: requests all members for a guild, caches automatically.

search(guild_id, query, opts \\ [])

@spec search(String.t() | integer(), String.t(), keyword()) ::
  {:ok, [map()]} | {:error, :timeout}

Searches members by username prefix (max 100 results).

start_link(opts \\ [])