Nostrum.Cache.ChannelGuildMapping behaviour (nostrum v0.11.0-dev)

View Source

Cache behaviour & dispatcher for mapping channel IDs to their respective guilds.

Purpose

While retrieving the channels on a specific guild is trivial as they are stored on the guild, retrieving the guild a given channel belongs to is not possible with the regular data mode of channels. This module allows to retrieve guilds associated with a channel via get/1.

Configuration

By default, nostrum will use Elixir.Nostrum.Cache.ChannelGuildMapping.ETS to store the mapping. To override this, set the [:caches, :channel_guild_mapping] setting on nostrum's application configuration:

config :nostrum,
  caches: %{
    channel_guild_mapping: MyBot.Nostrum.Cache.ChannelGuildMapping
  }

This setting must be set at compile time.

Summary

Callbacks

Retrieve the child specification for starting this mapping under a supervisor.

Create a mapping of the given channel to the given guild.

Remove any mapping associated with the given channel.

Retrieve the guild ID for the given channel ID, if present.

Callbacks

child_spec(term)

(since 0.8.0)
@callback child_spec(term()) :: Supervisor.child_spec()

Retrieve the child specification for starting this mapping under a supervisor.

create(id, id)

(since 0.8.0)
@callback create(Nostrum.Struct.Channel.id(), Nostrum.Struct.Guild.id()) :: true

Create a mapping of the given channel to the given guild.

delete(id)

(since 0.8.0)
@callback delete(Nostrum.Struct.Channel.id()) :: true

Remove any mapping associated with the given channel.

get(id)

(since 0.8.0)

Retrieve the guild ID for the given channel ID, if present.

Functions

create(guild_id, shard_num)

(since 0.8.0)

See Nostrum.Cache.ChannelGuildMapping.ETS.create/2.

delete(guild_id)

(since 0.8.0)

See Nostrum.Cache.ChannelGuildMapping.ETS.delete/1.

get(guild_id)

(since 0.8.0)

See Nostrum.Cache.ChannelGuildMapping.ETS.get/1.