EDA.AutoDelete (EDA v0.3.0)

Copy Markdown View Source

Automatic message deletion scheduler.

Manages timed message deletions using the BEAM's timer wheel — efficient for thousands of concurrent timers with zero per-timer process overhead.

How it works

  1. schedule/3 registers a deletion via Process.send_after (O(1) insert)
  2. When the timer fires, a Task is spawned to call Message.delete with low priority so deletions never starve important API calls
  3. The existing EDA.HTTP.RateLimiter handles 429s automatically

Usage

Typically used via the delete_after: option on message creation:

EDA.API.Message.create(channel_id, content: "Temporary!", delete_after: 10_000)

Or directly:

EDA.AutoDelete.schedule(channel_id, message_id, 30_000)

Summary

Functions

Returns a specification to start this module under a supervisor.

Schedules a message for deletion after delay_ms milliseconds.

Schedules an interaction response for deletion after delay_ms milliseconds.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

schedule(channel_id, message_id, delay_ms)

@spec schedule(String.t(), String.t(), non_neg_integer() | nil) :: :ok

Schedules a message for deletion after delay_ms milliseconds.

This is a non-blocking cast. The deletion will be executed asynchronously via Task.Supervisor with low priority through the rate limiter.

Does nothing if delay_ms is nil.

Examples

EDA.AutoDelete.schedule("channel_id", "message_id", 30_000)

schedule_interaction_response(app_id, token, delay_ms)

@spec schedule_interaction_response(String.t(), String.t(), non_neg_integer() | nil) ::
  :ok

Schedules an interaction response for deletion after delay_ms milliseconds.

Uses the interaction token to delete the original response — works for both ephemeral and non-ephemeral responses. Unlike schedule/3, this doesn't need a message ID since interaction responses are deleted via their token.

Does nothing if delay_ms is nil.

Examples

EDA.AutoDelete.schedule_interaction_response(app_id, token, 10_000)

start_link(opts)