EDA.Cache.VoiceState (EDA v0.3.0)

Copy Markdown View Source

ETS-based cache for Discord voice states.

Tracks which users are in which voice channels, along with their mute/deaf state. Keyed by {guild_id, user_id} for O(1) lookups.

Automatically populated from GUILD_CREATE and VOICE_STATE_UPDATE events. When a user leaves voice (channel_id is nil), their entry is removed.

Summary

Functions

Returns a specification to start this module under a supervisor.

Returns the total number of cached voice states.

Removes all voice states for a guild.

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

Gets all voice states for a guild.

Gets a user's voice state in a guild.

Creates or updates a voice state. If channel_id is nil, removes the entry.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

count()

@spec count() :: non_neg_integer()

Returns the total number of cached voice states.

delete_guild(guild_id)

@spec delete_guild(String.t() | integer()) :: :ok

Removes all voice states for a guild.

for_channel(guild_id, channel_id)

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

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

for_guild(guild_id)

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

Gets all voice states for a guild.

get(guild_id, user_id)

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

Gets a user's voice state in a guild.

start_link(opts)

upsert(guild_id, data)

@spec upsert(String.t(), map()) :: :ok

Creates or updates a voice state. If channel_id is nil, removes the entry.