nosedrum v0.2.0 Nosedrum.MessageCache behaviour View Source

A cache for recent messages sent on guilds.

Usage of implementations of this module is useful when your bot needs to access recently sent messages without hogging the API. One use case would be bots with an integrated mod log that want to show a before & after comparison of edited messages.

Link to this section Summary

Types

A slimmed down message with the most relevant data

Callbacks

Consume the given message in the cache process identified by cache

Retrieve a single message for the given guild_id with the specified message_id from the cache process identified by cache

Retrieve up to limit messages for the given guild_id from the cache process identified by cache. If limit is nil, return all messages for that guild from the cache

Update the given message in the cache, if present

Link to this section Types

A slimmed down message with the most relevant data.

You can fetch information about the author and the channel using Nostrum's built in cache, specificaly Nostrum.Cache.ChannelCache.get/1 and Nostrum.Cache.UserCache.get/1.

Link to this section Callbacks

Link to this callback

consume(message, cache) View Source
consume(message :: Nostrum.Struct.Message.t(), cache :: reference()) :: :ok

Consume the given message in the cache process identified by cache.

Whether this is done asynchronously or synchronously depends on the implementation.

Link to this callback

get(guild_id, message_id, cache) View Source
get(
  guild_id :: Nostrum.Struct.Guild.id(),
  message_id :: Nostrum.Struct.Message.id(),
  cache :: reference()
) :: cache_message() | nil | {:error, String.t()}

Retrieve a single message for the given guild_id with the specified message_id from the cache process identified by cache.

If no message with the given ID is cached, nil is returned.

Link to this callback

recent_in_guild(guild_id, limit, cache) View Source
recent_in_guild(
  guild_id :: Nostrum.Struct.Guild.id(),
  limit :: pos_integer() | nil,
  cache :: reference()
) :: {:ok, [cache_message()]} | {:error, String.t()}

Retrieve up to limit messages for the given guild_id from the cache process identified by cache. If limit is nil, return all messages for that guild from the cache.

If the guild is not cached, an empty message list is returned.

Link to this callback

update(message, cache) View Source
update(message :: Nostrum.Struct.Message.t(), cache :: reference()) :: :ok

Update the given message in the cache, if present.

Whether this is done asynchronously or synchronously depends on the implementation.