Documentation
¶
Overview ¶
Package state keeps the guilds, channels, roles, members, messages and voice states a bot sees, built from gateway events.
Feed a Cache from the session handler before the router, so handlers read the state after the event:
cache := state.New(state.WithMemberPolicy(state.MembersInVoice()))
session.Handler = func(event string, data json.RawMessage) {
cache.Handle(event, data)
router.Handle(event, data)
}
Flags and policies decide what is kept. OnChange passes the value from before an update or delete. A Chunker loads guild members, a Resolver falls back to REST for anything missing, and a Store decides where the data lives. The default store is in memory; the state/redis module shares one cache between processes.
Index ¶
- Constants
- Variables
- func ChunkAll(string) bool
- func ChunkGuilds(ids ...string) func(string) bool
- func OnChange[E any, P interface{ ... }, O any](c *Cache, fn func(old O, e P)) func()
- type Cache
- func (c *Cache) Apply(e fluxer.Event)
- func (c *Cache) CanManageMember(guildID, actorID, targetID string) bool
- func (c *Cache) CanManageRole(guildID, actorID, roleID string) bool
- func (c *Cache) Channel(id string) (fluxer.Channel, bool)
- func (c *Cache) ChannelByName(guildID, name string) (fluxer.Channel, bool)
- func (c *Cache) EachGuild() iter.Seq[fluxer.Guild]
- func (c *Cache) EachMember(guildID string) iter.Seq[fluxer.Member]
- func (c *Cache) EachMessage(channelID string) iter.Seq[fluxer.Message]
- func (c *Cache) Emoji(guildID, emojiID string) (fluxer.Emoji, bool)
- func (c *Cache) EmojiByName(guildID, name string) (fluxer.Emoji, bool)
- func (c *Cache) FindMember(guildID, name string) (fluxer.Member, bool)
- func (c *Cache) Flags() Flags
- func (c *Cache) Guild(id string) (fluxer.Guild, bool)
- func (c *Cache) GuildChannels(guildID string) []fluxer.Channel
- func (c *Cache) Guilds() []fluxer.Guild
- func (c *Cache) Handle(event string, data json.RawMessage)
- func (c *Cache) HighestRole(guildID, userID string) (fluxer.Role, bool)
- func (c *Cache) Member(guildID, userID string) (fluxer.Member, bool)
- func (c *Cache) MemberPartial(guildID, userID string) bool
- func (c *Cache) Members(guildID string) []fluxer.Member
- func (c *Cache) Message(channelID, messageID string) (fluxer.Message, bool)
- func (c *Cache) MessageByID(messageID string) (fluxer.Message, bool)
- func (c *Cache) Messages(channelID string, q fluxer.MessageQuery) []fluxer.Message
- func (c *Cache) OnChange(fn func(Change)) func()
- func (c *Cache) PendingGuilds() int
- func (c *Cache) Permissions(guildID, channelID, userID string) (fluxer.Permissions, bool)
- func (c *Cache) Presence(guildID, userID string) (fluxer.Presence, bool)
- func (c *Cache) Presences(guildID string) []fluxer.Presence
- func (c *Cache) Role(guildID, roleID string) (fluxer.Role, bool)
- func (c *Cache) RoleByName(guildID, name string) (fluxer.Role, bool)
- func (c *Cache) Self() fluxer.User
- func (c *Cache) SelfMember(guildID string) (fluxer.Member, bool)
- func (c *Cache) Stats() Stats
- func (c *Cache) Store() Store
- func (c *Cache) SweepMembers() int
- func (c *Cache) SweepMessages() int
- func (c *Cache) Threads(parentID string) []fluxer.Channel
- func (c *Cache) Unavailable(id string) bool
- func (c *Cache) User(id string) (fluxer.User, bool)
- func (c *Cache) VoiceChannel(guildID, userID string) string
- func (c *Cache) VoiceMembers(guildID, channelID string) []fluxer.Member
- func (c *Cache) VoiceStates(guildID string) []fluxer.VoiceState
- func (c *Cache) WaitGuilds(ctx context.Context) error
- type Change
- type Chunker
- type Flags
- type GuildRecord
- type Instances
- type MemberRequester
- type MemoryStore
- func (s *MemoryStore) Channels() Table[fluxer.Channel]
- func (s *MemoryStore) Emojis() Table[fluxer.Emoji]
- func (s *MemoryStore) Guilds() Table[GuildRecord]
- func (s *MemoryStore) Members() Table[fluxer.Member]
- func (s *MemoryStore) Messages() Table[fluxer.Message]
- func (s *MemoryStore) Presences() Table[fluxer.Presence]
- func (s *MemoryStore) Roles() Table[fluxer.Role]
- func (s *MemoryStore) Stickers() Table[fluxer.Sticker]
- func (s *MemoryStore) Users() Table[fluxer.User]
- func (s *MemoryStore) VoiceStates() Table[fluxer.VoiceState]
- type MemoryTable
- func (t *MemoryTable[V]) Delete(group, key string)
- func (t *MemoryTable[V]) DeleteGroup(group string)
- func (t *MemoryTable[V]) Get(group, key string) (V, bool)
- func (t *MemoryTable[V]) Group(group string) iter.Seq2[string, V]
- func (t *MemoryTable[V]) Groups() iter.Seq[string]
- func (t *MemoryTable[V]) Len(group string) int
- func (t *MemoryTable[V]) Locate(key string) (string, bool)
- func (t *MemoryTable[V]) Put(group, key string, v V)
- type Option
- func WithChannelPolicy(p Policy[fluxer.Channel]) Option
- func WithFlags(f Flags) Option
- func WithMemberPolicy(p Policy[fluxer.Member]) Option
- func WithMessageEvict(fn func(fluxer.Message)) Option
- func WithMessagePolicy(p Policy[fluxer.Message]) Option
- func WithMessages(perChannel int, ttl time.Duration) Option
- func WithStore(s Store) Option
- func WithoutFlags(f Flags) Option
- type Policy
- func All[T any]() Policy[T]
- func ChannelTypes(types ...int) Policy[fluxer.Channel]
- func MemberOwner() Policy[fluxer.Member]
- func MembersInGuilds(guildIDs ...string) Policy[fluxer.Member]
- func MembersInVoice() Policy[fluxer.Member]
- func MembersOnline() Policy[fluxer.Member]
- func MembersTimedOut() Policy[fluxer.Member]
- func MembersWithRole(roleIDs ...string) Policy[fluxer.Member]
- func MessagesFromHumans() Policy[fluxer.Message]
- func MessagesInGuilds(guildIDs ...string) Policy[fluxer.Message]
- func None[T any]() Policy[T]
- type RateLimitedError
- type Resolver
- func (r *Resolver) Channel(ctx context.Context, id string) (fluxer.Channel, error)
- func (r *Resolver) Guild(ctx context.Context, id string) (fluxer.Guild, error)
- func (r *Resolver) Member(ctx context.Context, guildID, userID string) (fluxer.Member, error)
- func (r *Resolver) Message(ctx context.Context, channelID, messageID string) (fluxer.Message, error)
- func (r *Resolver) Permissions(ctx context.Context, guildID, channelID, userID string) (fluxer.Permissions, error)
- func (r *Resolver) Roles(ctx context.Context, guildID string) ([]fluxer.Role, error)
- func (r *Resolver) User(ctx context.Context, id string) (fluxer.User, error)
- type Stats
- type Store
- type Table
Constants ¶
const DefaultMessagesPerChannel = 100
DefaultMessagesPerChannel is the number of messages kept per channel when WithMessages is not used.
Variables ¶
var ErrChunkTimeout = errors.New("state: member chunks did not arrive in time")
ErrChunkTimeout is returned by Chunker.Request when not all chunks arrived within Chunker.Timeout.
Functions ¶
func ChunkGuilds ¶
ChunkGuilds returns a Chunker.Filter that matches the listed guilds.
Types ¶
type Cache ¶
type Cache struct {
// SkipMembers stops the cache from storing members other than the bot's own member.
SkipMembers bool
// OnError receives events that Handle could not decode.
OnError func(event string, err error)
// contains filtered or unexported fields
}
Cache keeps gateway state in a Store. Pass every dispatch to Handle or Apply; the read methods are safe to call from any goroutine.
func (*Cache) Apply ¶
Apply updates the cache from a decoded event and then runs the OnChange handlers. Events for the same guild are applied one at a time.
func (*Cache) CanManageMember ¶
CanManageMember reports whether actorID outranks targetID in the role hierarchy. Nobody can manage the owner or themselves, the owner can manage everyone else, and a target without cached roles can be managed by any actor that has one. Permissions are not checked.
func (*Cache) CanManageRole ¶
CanManageRole reports whether actorID ranks above roleID in the role hierarchy. The guild owner can manage every role. Permissions are not checked.
func (*Cache) ChannelByName ¶
ChannelByName returns the first non-thread channel by position whose name matches, ignoring case and a leading #.
func (*Cache) EachGuild ¶
EachGuild yields the available guilds in no particular order, assembled like Guild, without building a slice first.
func (*Cache) EachMember ¶
EachMember yields the guild's cached members in no particular order.
func (*Cache) EachMessage ¶
EachMessage yields a channel's cached messages in no particular order.
func (*Cache) EmojiByName ¶
EmojiByName returns a guild emoji with exactly that name. If several share the name, any one of them is returned.
func (*Cache) FindMember ¶
FindMember looks up a member by username, tag or display name, ignoring case, surrounding spaces and a leading @. An exact match wins; otherwise it returns the member with the lowest user ID whose name starts with name.
func (*Cache) Guild ¶
Guild returns a cached guild with its roles, emojis, stickers and non-thread channels filled in. Unavailable guilds are reported as missing.
func (*Cache) GuildChannels ¶
GuildChannels returns the guild's channels without threads, sorted by position and then ID.
func (*Cache) Handle ¶
func (c *Cache) Handle(event string, data json.RawMessage)
Handle decodes a raw gateway dispatch and applies it. Decode errors go to OnError and event names the library does not know are ignored.
func (*Cache) HighestRole ¶
HighestRole returns the member's highest cached role by position, preferring the lower ID on a tie. It returns false when none of the member's roles is cached.
func (*Cache) Member ¶
Member returns a cached member. When the stored member carries only a user ID, the user is filled in from the user table.
func (*Cache) MemberPartial ¶
MemberPartial reports whether a member is cached without user details such as the username.
func (*Cache) MessageByID ¶
MessageByID returns a cached message without knowing its channel. It needs a store whose message table supports Locate.
func (*Cache) Messages ¶
Messages returns cached messages of a channel between q.After and q.Before, newest first. When only q.After is set, it returns the messages right after it, oldest first. q.Limit caps the number of results.
func (*Cache) OnChange ¶
OnChange registers fn to run after each event, once the cache has applied it and released its lock. Handlers run on the goroutine that called Apply. The returned function removes the handler.
func (*Cache) PendingGuilds ¶
PendingGuilds returns how many guilds from the last READY have not arrived yet.
func (*Cache) Permissions ¶
func (c *Cache) Permissions(guildID, channelID, userID string) (fluxer.Permissions, bool)
Permissions computes a member's permissions from cached data. An empty channelID gives guild-level permissions, and a thread uses its parent's overwrites. It returns false when the guild, member or channel is not cached.
func (*Cache) Presence ¶
Presence returns a user's presence in a guild. Offline users have no cached presence.
func (*Cache) RoleByName ¶
RoleByName returns the lowest role by position whose name matches, ignoring case.
func (*Cache) SelfMember ¶
SelfMember returns the bot's own member in a guild.
func (*Cache) Stats ¶
Stats counts the entries in every table of the store. It walks all groups, which can be slow with a remote store.
func (*Cache) SweepMembers ¶
SweepMembers checks every cached member against the flags, SkipMembers and the member policy again and removes the ones that no longer pass. It returns the number of members removed.
func (*Cache) SweepMessages ¶
SweepMessages removes expired messages and messages that fail the message policy, calling the evict function for each one. It returns the number removed.
func (*Cache) Threads ¶
Threads returns the cached threads of parentID sorted by ID. It returns nil when the parent channel is not cached.
func (*Cache) Unavailable ¶
Unavailable reports whether the guild is known but currently unavailable.
func (*Cache) User ¶
User returns a cached user. Users are collected from READY, members, presences and messages while FlagUsers is set.
func (*Cache) VoiceChannel ¶
VoiceChannel returns the voice channel a user is in, or an empty string. For a user with several connections in the guild it returns any one of them.
func (*Cache) VoiceMembers ¶
VoiceMembers returns the cached members in a voice channel, sorted by user ID. Users in the channel without a cached member are left out.
func (*Cache) VoiceStates ¶
func (c *Cache) VoiceStates(guildID string) []fluxer.VoiceState
VoiceStates returns the guild's voice states sorted by user ID. A user connected from several sessions appears once per connection.
type Change ¶
type Change struct {
// Event is the applied event.
Event fluxer.Event
// Old is the cached value from before the event. It is a pointer such as
// *fluxer.Channel or *fluxer.Message for update, delete and reaction events, and
// that pointer is nil when nothing was cached. MessageDeleteBulk gives the cached
// []fluxer.Message, and emoji and sticker updates give the previous slice. Old is
// nil for events that have no previous value.
Old any
}
Change describes an event that a cache has applied.
type Chunker ¶
type Chunker struct {
// Requester sends the member requests.
Requester MemberRequester
// Filter, when set, makes Handle request all members of each guild in a
// GUILD_CREATE for which it returns true. ChunkAll and ChunkGuilds are ready-made
// filters.
Filter func(guildID string) bool
// Timeout is how long Request waits for all chunks after sending the request. The
// default is 30 seconds.
Timeout time.Duration
// OnError receives errors from the requests started by Filter.
OnError func(guildID string, err error)
// contains filtered or unexported fields
}
Chunker requests guild members over the gateway and collects the matching GUILD_MEMBERS_CHUNK events. Pass raw dispatches to Handle.
func NewChunker ¶
func NewChunker(r MemberRequester) *Chunker
NewChunker returns a chunker that sends requests through r.
func (*Chunker) Handle ¶
func (k *Chunker) Handle(event string, data json.RawMessage)
Handle processes a raw gateway dispatch. It reads GUILD_MEMBERS_CHUNK, RATE_LIMITED and GUILD_CREATE and ignores other events. Chunks without a nonce or with a nonce the chunker did not send are ignored.
func (*Chunker) Request ¶
Request sends r with a new nonce, waits until every chunk for that nonce has arrived and returns the collected members. Presences in the chunks are not returned. It fails with a *RateLimitedError if the gateway rate limits the request, with ErrChunkTimeout after Timeout, or with the context's error.
type Flags ¶
type Flags uint32
Flags selects which kinds of data a Cache stores.
const ( FlagGuilds Flags = 1 << iota FlagChannels FlagThreads FlagRoles FlagMembers FlagVoiceStates FlagEmojis FlagStickers FlagUsers FlagPresences FlagMessages FlagsAll = FlagGuilds | FlagChannels | FlagThreads | FlagRoles | FlagMembers | FlagVoiceStates | FlagEmojis | FlagStickers | FlagUsers | FlagPresences | FlagMessages )
Flags for the individual tables. FlagThreads covers thread channels and FlagChannels all other channels. FlagsAll is the default for New.
type GuildRecord ¶
type GuildRecord struct {
Guild fluxer.Guild `json:"guild"`
Unavailable bool `json:"unavailable,omitempty"`
// JoinedAt is when the bot joined the guild, if the gateway sent it.
JoinedAt *time.Time `json:"joined_at,omitempty"`
}
GuildRecord is the stored form of a guild. Guild has no roles, channels, emojis or stickers; the cache keeps those in their own tables and adds them back on read.
type Instances ¶
type Instances struct {
// SkipMembers is copied to each cache when it is created. Changing it later does not
// affect existing caches.
SkipMembers bool
// OnError receives decode errors from all caches together with the origin that
// produced them. It is read when a cache is created.
OnError func(origin, event string, err error)
// Options returns extra options for one origin. They are applied after the options
// passed to NewInstances.
Options func(origin string) []Option
// contains filtered or unexported fields
}
Instances keeps one Cache per origin, for bots connected to several Fluxer instances. A cache is created the first time its origin is used.
func NewInstances ¶
NewInstances returns an empty set of caches. opts apply to every cache it creates.
func (*Instances) Drop ¶
Drop forgets the cache for origin. The next call to For creates a new, empty one.
type MemberRequester ¶
type MemberRequester interface {
RequestGuildMembers(ctx context.Context, r fluxer.RequestMembers) error
}
MemberRequester sends a request guild members command. *fluxer.Session implements it.
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is the default in-memory Store. Its channel and message tables are indexed.
func (*MemoryStore) Channels ¶
func (s *MemoryStore) Channels() Table[fluxer.Channel]
Channels returns the channel table.
func (*MemoryStore) Emojis ¶
func (s *MemoryStore) Emojis() Table[fluxer.Emoji]
Emojis returns the emoji table.
func (*MemoryStore) Guilds ¶
func (s *MemoryStore) Guilds() Table[GuildRecord]
Guilds returns the guild table.
func (*MemoryStore) Members ¶
func (s *MemoryStore) Members() Table[fluxer.Member]
Members returns the member table.
func (*MemoryStore) Messages ¶
func (s *MemoryStore) Messages() Table[fluxer.Message]
Messages returns the message table.
func (*MemoryStore) Presences ¶
func (s *MemoryStore) Presences() Table[fluxer.Presence]
Presences returns the presence table.
func (*MemoryStore) Roles ¶
func (s *MemoryStore) Roles() Table[fluxer.Role]
Roles returns the role table.
func (*MemoryStore) Stickers ¶
func (s *MemoryStore) Stickers() Table[fluxer.Sticker]
Stickers returns the sticker table.
func (*MemoryStore) Users ¶
func (s *MemoryStore) Users() Table[fluxer.User]
Users returns the user table.
func (*MemoryStore) VoiceStates ¶
func (s *MemoryStore) VoiceStates() Table[fluxer.VoiceState]
VoiceStates returns the voice state table.
type MemoryTable ¶
type MemoryTable[V any] struct { // contains filtered or unexported fields }
MemoryTable is an in-memory Table, sharded by group. An indexed table also records which group holds each key, for Locate.
func NewMemoryTable ¶
func NewMemoryTable[V any](indexed bool) *MemoryTable[V]
NewMemoryTable returns an empty table. With indexed set, Locate works, which assumes that each key is used in only one group.
func (*MemoryTable[V]) Delete ¶
func (t *MemoryTable[V]) Delete(group, key string)
Delete removes one value and drops the group once it is empty.
func (*MemoryTable[V]) DeleteGroup ¶
func (t *MemoryTable[V]) DeleteGroup(group string)
DeleteGroup removes every value in group.
func (*MemoryTable[V]) Get ¶
func (t *MemoryTable[V]) Get(group, key string) (V, bool)
Get returns the value stored under group and key.
func (*MemoryTable[V]) Group ¶
func (t *MemoryTable[V]) Group(group string) iter.Seq2[string, V]
Group returns a snapshot of group taken when Group is called.
func (*MemoryTable[V]) Groups ¶
func (t *MemoryTable[V]) Groups() iter.Seq[string]
Groups returns a snapshot of the names of all non-empty groups.
func (*MemoryTable[V]) Len ¶
func (t *MemoryTable[V]) Len(group string) int
Len returns the number of values in group.
func (*MemoryTable[V]) Locate ¶
func (t *MemoryTable[V]) Locate(key string) (string, bool)
Locate returns the group that holds key. It always returns false for a table created without an index.
func (*MemoryTable[V]) Put ¶
func (t *MemoryTable[V]) Put(group, key string, v V)
Put stores v under group and key.
type Option ¶
type Option func(*Cache)
Option configures a Cache created by New.
func WithChannelPolicy ¶
WithChannelPolicy limits which channels and threads are cached. A cached channel that stops matching on a later update is removed.
func WithMemberPolicy ¶
WithMemberPolicy limits which members are cached. The bot's own member is always kept, regardless of the policy, FlagMembers and SkipMembers. A cached member that stops matching on a later update is removed.
func WithMessageEvict ¶
WithMessageEvict sets a function that is called for every message removed by the limit, the TTL or SweepMessages. Messages deleted by events are not reported.
func WithMessagePolicy ¶
WithMessagePolicy limits which messages are cached. SweepMessages removes cached messages that no longer match.
func WithMessages ¶
WithMessages sets how many messages are kept per channel and for how long. When a channel goes over perChannel, its oldest messages are evicted. A ttl of zero keeps messages until the limit evicts them; otherwise expired messages are removed when the channel gets a new message or by SweepMessages. A perChannel of zero or less disables the message cache.
func WithoutFlags ¶
WithoutFlags clears f from the flags set so far.
type Policy ¶
Policy decides whether a value is kept in the cache. It runs on every write of that kind of value, so it should be cheap, and it must not apply events to the same cache.
func ChannelTypes ¶
ChannelTypes keeps channels whose type is one of types.
func MemberOwner ¶
MemberOwner keeps the owner of each cached guild.
func MembersInGuilds ¶
MembersInGuilds keeps members of the listed guilds.
func MembersInVoice ¶
MembersInVoice keeps members that are in a voice channel according to the cached voice states, so it needs FlagVoiceStates. A member is dropped when its voice state shows that it left.
func MembersOnline ¶
MembersOnline keeps members with a cached presence that is not offline. Members who go offline stay cached until their next member update or SweepMembers.
func MembersTimedOut ¶
MembersTimedOut keeps members whose timeout has not ended yet. Members whose timeout runs out stay cached until their next member update or SweepMembers.
func MembersWithRole ¶
MembersWithRole keeps members that have at least one of the listed roles.
func MessagesFromHumans ¶
MessagesFromHumans keeps messages that were not sent by a bot or a webhook.
func MessagesInGuilds ¶
MessagesInGuilds keeps messages sent in the listed guilds.
type RateLimitedError ¶
type RateLimitedError struct {
GuildID string
// RetryAfter is how long to wait before requesting members of the guild again.
RetryAfter time.Duration
}
RateLimitedError is returned by Chunker.Request when the gateway answers the request with RATE_LIMITED.
func (*RateLimitedError) Error ¶
func (e *RateLimitedError) Error() string
Error implements the error interface.
type Resolver ¶
type Resolver struct {
Cache *Cache
Client *fluxer.Client
// contains filtered or unexported fields
}
Resolver reads from a Cache and falls back to the REST API on a miss. Fetched values are written back to the cache, subject to its flags and policies, and concurrent fetches of the same value share one request.
func NewResolver ¶
NewResolver returns a resolver for c that fetches missing data with client.
func (*Resolver) Member ¶
Member returns a member from the cache, or fetches it when it is missing or partial.
func (*Resolver) Message ¶
func (r *Resolver) Message(ctx context.Context, channelID, messageID string) (fluxer.Message, error)
Message returns a message from the cache or fetches it.
func (*Resolver) Permissions ¶
func (r *Resolver) Permissions(ctx context.Context, guildID, channelID, userID string) (fluxer.Permissions, error)
Permissions fetches whatever is missing of the guild, its roles, the member, the channel and a thread's parent, and then computes the permissions like Cache.Permissions. An empty channelID gives guild-level permissions.
type Stats ¶
type Stats struct {
Guilds int
Channels int
Roles int
Members int
Users int
Presences int
VoiceStates int
Messages int
Emojis int
Stickers int
// Hits counts Resolver lookups that were answered from the cache.
Hits uint64
// Misses counts Resolver lookups that went to the API.
Misses uint64
}
Stats is a snapshot of how many entries each table of a cache holds.
type Store ¶
type Store interface {
// Guilds holds guild records under the empty group, keyed by guild ID.
Guilds() Table[GuildRecord]
// Channels holds channels grouped by guild ID, with DM channels under the empty
// group. The cache uses Locate to find a channel by ID alone.
Channels() Table[fluxer.Channel]
// Roles holds roles grouped by guild ID.
Roles() Table[fluxer.Role]
// Members holds members grouped by guild ID and keyed by user ID.
Members() Table[fluxer.Member]
// VoiceStates holds voice states grouped by guild ID and keyed by connection ID, or
// by user ID when a state has no connection ID.
VoiceStates() Table[fluxer.VoiceState]
// Emojis holds custom emojis grouped by guild ID.
Emojis() Table[fluxer.Emoji]
// Stickers holds stickers grouped by guild ID.
Stickers() Table[fluxer.Sticker]
// Users holds users under the empty group, keyed by user ID.
Users() Table[fluxer.User]
// Presences holds presences grouped by guild ID and keyed by user ID.
Presences() Table[fluxer.Presence]
// Messages holds messages grouped by channel ID. Cache.MessageByID needs Locate to
// work on this table.
Messages() Table[fluxer.Message]
}
Store holds the tables a Cache reads and writes. NewMemoryStore is the default; the state/redis module provides a Store that several processes can share.
type Table ¶
type Table[V any] interface { // Get returns the value stored under group and key. Get(group, key string) (V, bool) // Put stores v under group and key, replacing any previous value. Put(group, key string, v V) // Delete removes one value. Delete(group, key string) // DeleteGroup removes every value in group. DeleteGroup(group string) // Group returns the entries of group. The entries are read when Group is called, so // the table can be changed while iterating. Group(group string) iter.Seq2[string, V] // Len returns the number of values in group. Len(group string) int // Groups returns the names of all groups that hold at least one value. Groups() iter.Seq[string] // Locate returns the group that holds key. Tables that keep no key index always // return false. Locate(key string) (string, bool) }
Table is a two-level key-value table used by a Store. Values live under a group, usually a guild or channel ID, and a key inside that group.