EDA.Cache (EDA v0.3.0)

Copy Markdown View Source

Unified cache interface for EDA.

This module provides a simple API for accessing cached Discord data. Data is automatically cached as events are received from the Gateway.

Examples

# Get a guild
guild = EDA.Cache.get_guild("123456789")

# Get a user
user = EDA.Cache.get_user("987654321")

# Get a channel
channel = EDA.Cache.get_channel("111222333")

# Get the bot user
me = EDA.Cache.me()

Summary

Functions

Returns the number of cached channels.

Gets all cached channels.

Gets all channels for a guild.

Fetches a channel from cache, falling back to REST on miss.

Fetches a guild from cache, falling back to REST on miss.

Fetches a member from cache, falling back to REST on miss.

Fetches a role from cache, falling back to REST on miss.

Fetches a user from cache, falling back to REST on miss.

Gets a channel by ID.

Gets a guild by ID.

Gets a member in a guild.

Gets a user's presence in a guild.

Gets a role by ID.

Gets a user by ID.

Gets a user's voice state in a guild.

Returns the number of cached guilds.

Gets all cached guilds.

Gets the current bot user as an %EDA.User{} struct.

Returns the raw map of the current bot user (string keys).

Returns the total number of cached members.

Gets all members for a guild.

Gets all presences for a guild.

Stores the current bot user. Saves both the parsed %EDA.User{} struct and the raw map for backward compatibility.

Returns the total number of cached roles.

Gets all roles for a guild.

Returns the number of cached users.

Gets all cached users.

Gets all voice states for a specific channel in a guild.

Gets all voice states for a guild.

Functions

channel_count()

@spec channel_count() :: non_neg_integer()

Returns the number of cached channels.

channels()

@spec channels() :: [map()]

Gets all cached channels.

channels_for_guild(guild_id)

@spec channels_for_guild(String.t() | integer()) :: [map()]

Gets all channels for a guild.

fetch_channel(channel_id)

@spec fetch_channel(String.t() | integer()) :: {:ok, map()} | {:error, term()}

Fetches a channel from cache, falling back to REST on miss.

fetch_guild(guild_id)

@spec fetch_guild(String.t() | integer()) :: {:ok, map()} | {:error, term()}

Fetches a guild from cache, falling back to REST on miss.

fetch_member(guild_id, user_id)

@spec fetch_member(String.t() | integer(), String.t() | integer()) ::
  {:ok, map()} | {:error, term()}

Fetches a member from cache, falling back to REST on miss.

fetch_role(guild_id, role_id)

@spec fetch_role(String.t() | integer(), String.t() | integer()) ::
  {:ok, map()} | {:error, term()}

Fetches a role from cache, falling back to REST on miss.

Note: the REST API returns all roles for the guild, so guild_id is required.

fetch_user(user_id)

@spec fetch_user(String.t() | integer()) :: {:ok, map()} | {:error, term()}

Fetches a user from cache, falling back to REST on miss.

get_channel(channel_id)

@spec get_channel(String.t() | integer()) :: map() | nil

Gets a channel by ID.

get_guild(guild_id)

@spec get_guild(String.t() | integer()) :: map() | nil

Gets a guild by ID.

get_member(guild_id, user_id)

@spec get_member(String.t() | integer(), String.t() | integer()) :: map() | nil

Gets a member in a guild.

get_presence(guild_id, user_id)

@spec get_presence(String.t() | integer(), String.t() | integer()) :: map() | nil

Gets a user's presence in a guild.

get_role(role_id)

@spec get_role(String.t() | integer()) :: map() | nil

Gets a role by ID.

get_user(user_id)

@spec get_user(String.t() | integer()) :: map() | nil

Gets a user by ID.

get_voice_state(guild_id, user_id)

@spec get_voice_state(String.t() | integer(), String.t() | integer()) :: map() | nil

Gets a user's voice state in a guild.

guild_count()

@spec guild_count() :: non_neg_integer()

Returns the number of cached guilds.

guilds()

@spec guilds() :: [map()]

Gets all cached guilds.

me()

@spec me() :: EDA.User.t() | map() | nil

Gets the current bot user as an %EDA.User{} struct.

Returns nil if the bot hasn't connected yet. The raw map is also stored for internal callers that need string-key access.

me_raw()

@spec me_raw() :: map() | nil

Returns the raw map of the current bot user (string keys).

Used internally by code that expects me["id"] string-key access (e.g., app_id/0, voice event routing).

member_count()

@spec member_count() :: non_neg_integer()

Returns the total number of cached members.

members(guild_id)

@spec members(String.t() | integer()) :: [map()]

Gets all members for a guild.

presences(guild_id)

@spec presences(String.t() | integer()) :: [map()]

Gets all presences for a guild.

put_me(user)

@spec put_me(map()) :: :ok

Stores the current bot user. Saves both the parsed %EDA.User{} struct and the raw map for backward compatibility.

role_count()

@spec role_count() :: non_neg_integer()

Returns the total number of cached roles.

roles(guild_id)

@spec roles(String.t() | integer()) :: [map()]

Gets all roles for a guild.

user_count()

@spec user_count() :: non_neg_integer()

Returns the number of cached users.

users()

@spec users() :: [map()]

Gets all cached users.

voice_channel_members(guild_id, channel_id)

@spec voice_channel_members(String.t() | integer(), String.t() | integer()) :: [map()]

Gets all voice states for a specific channel in a guild.

voice_states(guild_id)

@spec voice_states(String.t() | integer()) :: [map()]

Gets all voice states for a guild.