Documentation
¶
Index ¶
- func PolicyAll[T any](_ T) bool
- func PolicyNone[T any](_ T) bool
- type Cache
- type Caches
- type ChannelCache
- type ConfigOpt
- func WithCaches(flags ...Flags) ConfigOpt
- func WithChannelCache(channelCache ChannelCache) ConfigOpt
- func WithChannelCachePolicy(policy Policy[fluxer.GuildChannel]) ConfigOpt
- func WithEmojiCache(emojiCache EmojiCache) ConfigOpt
- func WithEmojiCachePolicy(policy Policy[fluxer.Emoji]) ConfigOpt
- func WithGuildCache(guildCache GuildCache) ConfigOpt
- func WithGuildCachePolicy(policy Policy[fluxer.Guild]) ConfigOpt
- func WithGuildScheduledEventCache(guildScheduledEventCache GuildScheduledEventCache) ConfigOpt
- func WithGuildScheduledEventCachePolicy(policy Policy[fluxer.GuildScheduledEvent]) ConfigOpt
- func WithMemberCache(memberCache MemberCache) ConfigOpt
- func WithMemberCachePolicy(policy Policy[fluxer.Member]) ConfigOpt
- func WithMessageCache(messageCache MessageCache) ConfigOpt
- func WithMessageCachePolicy(policy Policy[fluxer.Message]) ConfigOpt
- func WithPresenceCache(presenceCache PresenceCache) ConfigOpt
- func WithPresenceCachePolicy(policy Policy[fluxer.Presence]) ConfigOpt
- func WithRoleCache(roleCache RoleCache) ConfigOpt
- func WithRoleCachePolicy(policy Policy[fluxer.Role]) ConfigOpt
- func WithSelfUserCache(cache SelfUserCache) ConfigOpt
- func WithStickerCache(stickerCache StickerCache) ConfigOpt
- func WithStickerCachePolicy(policy Policy[fluxer.Sticker]) ConfigOpt
- func WithVoiceStateCache(voiceStateCache VoiceStateCache) ConfigOpt
- func WithVoiceStateCachePolicy(policy Policy[fluxer.VoiceState]) ConfigOpt
- type DefaultCache
- func (c *DefaultCache[T]) All() iter.Seq[T]
- func (c *DefaultCache[T]) Get(id snowflake.ID) (T, bool)
- func (c *DefaultCache[T]) Len() int
- func (c *DefaultCache[T]) Put(id snowflake.ID, entity T)
- func (c *DefaultCache[T]) Remove(id snowflake.ID) (T, bool)
- func (c *DefaultCache[T]) RemoveIf(filterFunc FilterFunc[T])
- type EmojiCache
- type FilterFunc
- type Flags
- type GroupedCache
- type GroupedFilterFunc
- type GuildCache
- type GuildScheduledEventCache
- type MemberCache
- type MessageCache
- type Policy
- func AllPolicies[T any](policies ...Policy[T]) Policy[T]
- func AnyPolicy[T any](policies ...Policy[T]) Policy[T]
- func PolicyChannelExclude(channelTypes ...fluxer.ChannelType) Policy[fluxer.Channel]
- func PolicyChannelInclude(channelTypes ...fluxer.ChannelType) Policy[fluxer.Channel]
- func PolicyMembersInVoice(caches Caches) Policy[fluxer.Member]
- func PolicyMembersInclude(guildIDs ...snowflake.ID) Policy[fluxer.Member]
- type PresenceCache
- type RoleCache
- type SelfUserCache
- type Set
- type StickerCache
- type VoiceStateCache
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PolicyNone ¶
PolicyNone returns a policy that will never cache anything.
Types ¶
type Cache ¶
type Cache[T any] interface { // Get returns a copy of the entity with the given snowflake and a bool whether it was found or not. Get(id snowflake.ID) (T, bool) // Put stores the given entity with the given snowflake as key. If the entity is already present, it will be overwritten. Put(id snowflake.ID, entity T) // Remove removes the entity with the given snowflake as key and returns a copy of the entity and a bool whether it was removed or not. Remove(id snowflake.ID) (T, bool) // RemoveIf removes all entities that pass the given FilterFunc RemoveIf(filterFunc FilterFunc[T]) // Len returns the number of entities in the cache. Len() int // All returns an [iter.Seq] of all entities in the cache. All() iter.Seq[T] }
Cache is a simple key value store. They key is always a snowflake.ID. The cache provides a simple way to store and retrieve entities. But is not guaranteed to be thread safe as this depends on the underlying implementation.
func NewCache ¶
NewCache returns a new DefaultCache implementation which filter the entities after the gives Flags and Policy. This cache implementation is thread safe and can be used in multiple goroutines without any issues. It also only hands out copies to the entities. Regardless these entities should be handles as immutable.
type Caches ¶
type Caches interface {
SelfUserCache
GuildCache
ChannelCache
GuildScheduledEventCache
RoleCache
MemberCache
PresenceCache
VoiceStateCache
MessageCache
EmojiCache
StickerCache
// CacheFlags returns the current configured FLags of the caches.
CacheFlags() Flags
// MemberPermissions returns the calculated permissions of the given member.
// This requires the FlagRoles to be set.
MemberPermissions(member fluxer.Member) fluxer.Permissions
// MemberPermissionsInChannel returns the calculated permissions of the given member in the given channel.
// This requires the FlagRoles and FlagChannels to be set.
MemberPermissionsInChannel(channel fluxer.GuildChannel, member fluxer.Member) fluxer.Permissions
// MemberRoles returns all roles of the given member.
// This requires the FlagRoles to be set.
MemberRoles(member fluxer.Member) []fluxer.Role
// AudioChannelMembers returns all members which are in the given audio channel.
// This requires the FlagVoiceStates to be set.
AudioChannelMembers(channel fluxer.GuildAudioChannel) []fluxer.Member
// SelfMember returns the current bot member from the given guildID.
// This is only available after we received the gateway.EventTypeGuildCreate event for the given guildID.
SelfMember(guildID snowflake.ID) (fluxer.Member, bool)
// GuildMessageChannel returns a fluxer.GuildMessageChannel from the ChannelCache and a bool indicating if it exists.
GuildMessageChannel(channelID snowflake.ID) (fluxer.GuildMessageChannel, bool)
// GuildAudioChannel returns a fluxer.GetGuildAudioChannel from the ChannelCache and a bool indicating if it exists.
GuildAudioChannel(channelID snowflake.ID) (fluxer.GuildAudioChannel, bool)
// GuildTextChannel returns a fluxer.GuildTextChannel from the ChannelCache and a bool indicating if it exists.
GuildTextChannel(channelID snowflake.ID) (fluxer.GuildTextChannel, bool)
// GuildVoiceChannel returns a fluxer.GuildVoiceChannel from the ChannelCache and a bool indicating if it exists.
GuildVoiceChannel(channelID snowflake.ID) (fluxer.GuildVoiceChannel, bool)
// GuildCategoryChannel returns a fluxer.GuildCategoryChannel from the ChannelCache and a bool indicating if it exists.
GuildCategoryChannel(channelID snowflake.ID) (fluxer.GuildCategoryChannel, bool)
}
Caches combines all different entity caches into one with some utility methods.
type ChannelCache ¶
type ChannelCache interface {
ChannelCache() Cache[fluxer.GuildChannel]
Channel(channelID snowflake.ID) (fluxer.GuildChannel, bool)
Channels() iter.Seq[fluxer.GuildChannel]
ChannelsForGuild(guildID snowflake.ID) iter.Seq[fluxer.GuildChannel]
ChannelsLen() int
AddChannel(channel fluxer.GuildChannel)
RemoveChannel(channelID snowflake.ID) (fluxer.GuildChannel, bool)
RemoveChannelsByGuildID(guildID snowflake.ID)
}
func NewChannelCache ¶
func NewChannelCache(cache Cache[fluxer.GuildChannel]) ChannelCache
type ConfigOpt ¶
type ConfigOpt func(config *config)
ConfigOpt is a type alias for a function that takes a config and is used to configure your Caches.
func WithCaches ¶
WithCaches sets the Flags of the config.
func WithChannelCache ¶
func WithChannelCache(channelCache ChannelCache) ConfigOpt
WithChannelCache sets the ChannelCache of the config.
func WithChannelCachePolicy ¶
func WithChannelCachePolicy(policy Policy[fluxer.GuildChannel]) ConfigOpt
WithChannelCachePolicy sets the Policy[fluxer.Channel] of the config.
func WithEmojiCache ¶
func WithEmojiCache(emojiCache EmojiCache) ConfigOpt
WithEmojiCache sets the EmojiCache of the config.
func WithEmojiCachePolicy ¶
WithEmojiCachePolicy sets the Policy[fluxer.Emoji] of the config.
func WithGuildCache ¶
func WithGuildCache(guildCache GuildCache) ConfigOpt
WithGuildCache sets the GuildCache of the config.
func WithGuildCachePolicy ¶
WithGuildCachePolicy sets the Policy[fluxer.Guild] of the config.
func WithGuildScheduledEventCache ¶
func WithGuildScheduledEventCache(guildScheduledEventCache GuildScheduledEventCache) ConfigOpt
WithGuildScheduledEventCache sets the GuildScheduledEventCache of the config.
func WithGuildScheduledEventCachePolicy ¶
func WithGuildScheduledEventCachePolicy(policy Policy[fluxer.GuildScheduledEvent]) ConfigOpt
WithGuildScheduledEventCachePolicy sets the Policy[fluxer.GuildScheduledEvent] of the config.
func WithMemberCache ¶
func WithMemberCache(memberCache MemberCache) ConfigOpt
WithMemberCache sets the MemberCache of the config.
func WithMemberCachePolicy ¶
WithMemberCachePolicy sets the Policy[fluxer.Member] of the config.
func WithMessageCache ¶
func WithMessageCache(messageCache MessageCache) ConfigOpt
WithMessageCache sets the MessageCache of the config.
func WithMessageCachePolicy ¶
WithMessageCachePolicy sets the Policy[fluxer.Message] of the config.
func WithPresenceCache ¶
func WithPresenceCache(presenceCache PresenceCache) ConfigOpt
WithPresenceCache sets the PresenceCache of the config.
func WithPresenceCachePolicy ¶
WithPresenceCachePolicy sets the Policy[fluxer.Presence] of the config.
func WithRoleCache ¶
WithRoleCache sets the RoleCache of the config.
func WithRoleCachePolicy ¶
WithRoleCachePolicy sets the Policy[fluxer.Role] of the config.
func WithSelfUserCache ¶
func WithSelfUserCache(cache SelfUserCache) ConfigOpt
WithSelfUserCache sets the SelfUserCache of the config.
func WithStickerCache ¶
func WithStickerCache(stickerCache StickerCache) ConfigOpt
WithStickerCache sets the StickerCache of the config.
func WithStickerCachePolicy ¶
WithStickerCachePolicy sets the Policy[fluxer.Sticker] of the config.
func WithVoiceStateCache ¶
func WithVoiceStateCache(voiceStateCache VoiceStateCache) ConfigOpt
WithVoiceStateCache sets the VoiceStateCache of the config.
func WithVoiceStateCachePolicy ¶
func WithVoiceStateCachePolicy(policy Policy[fluxer.VoiceState]) ConfigOpt
WithVoiceStateCachePolicy sets the Policy[fluxer.VoiceState] of the config.
type DefaultCache ¶
type DefaultCache[T any] struct { // contains filtered or unexported fields }
DefaultCache is a simple thread safe cache key value store.
func (*DefaultCache[T]) All ¶
func (c *DefaultCache[T]) All() iter.Seq[T]
func (*DefaultCache[T]) Len ¶
func (c *DefaultCache[T]) Len() int
func (*DefaultCache[T]) Put ¶
func (c *DefaultCache[T]) Put(id snowflake.ID, entity T)
func (*DefaultCache[T]) RemoveIf ¶
func (c *DefaultCache[T]) RemoveIf(filterFunc FilterFunc[T])
type EmojiCache ¶
type EmojiCache interface {
EmojiCache() GroupedCache[fluxer.Emoji]
Emoji(guildID snowflake.ID, emojiID snowflake.ID) (fluxer.Emoji, bool)
Emojis(guildID snowflake.ID) iter.Seq[fluxer.Emoji]
EmojisAllLen() int
EmojisLen(guildID snowflake.ID) int
AddEmoji(emoji fluxer.Emoji)
RemoveEmoji(guildID snowflake.ID, emojiID snowflake.ID) (fluxer.Emoji, bool)
RemoveEmojisByGuildID(guildID snowflake.ID)
}
func NewEmojiCache ¶
func NewEmojiCache(cache GroupedCache[fluxer.Emoji]) EmojiCache
type Flags ¶
type Flags int
Flags are used to enable/disable certain internal caches
const ( FlagGuilds Flags = 1 << iota FlagGuildScheduledEvents FlagMembers FlagThreadMembers FlagMessages FlagPresences FlagChannels FlagRoles FlagEmojis FlagStickers FlagVoiceStates FlagStageInstances FlagGuildSoundboardSounds FlagsNone Flags = 0 FlagsAll = FlagGuilds | FlagGuildScheduledEvents | FlagMembers | FlagThreadMembers | FlagMessages | FlagPresences | FlagChannels | FlagRoles | FlagEmojis | FlagStickers | FlagVoiceStates | FlagStageInstances | FlagGuildSoundboardSounds )
values for CacheFlags
type GroupedCache ¶
type GroupedCache[T any] interface { // Get returns a copy of the entity with the given groupID and ID and a bool wheaten it was found or not. Get(groupID snowflake.ID, id snowflake.ID) (T, bool) // Put stores the given entity with the given groupID and ID as key. If the entity is already present, it will be overwritten. Put(groupID snowflake.ID, id snowflake.ID, entity T) // Remove removes the entity with the given groupID and ID as key and returns a copy of the entity and a bool whether it was removed or not. Remove(groupID snowflake.ID, id snowflake.ID) (T, bool) // GroupRemove removes all entities in the given groupID. GroupRemove(groupID snowflake.ID) // RemoveIf removes all entities that pass the given GroupedFilterFunc. RemoveIf(filterFunc GroupedFilterFunc[T]) // GroupRemoveIf removes all entities that pass the given GroupedFilterFunc within the groupID. GroupRemoveIf(groupID snowflake.ID, filterFunc GroupedFilterFunc[T]) // Len returns the total number of entities in the cache. Len() int // GroupLen returns the number of entities in the cache within the groupID. GroupLen(groupID snowflake.ID) int // All returns an [iter.Seq2] of all entities in the cache. All() iter.Seq2[snowflake.ID, T] // GroupAll returns an [iter.Seq] of all entities in the cache within the groupID. GroupAll(groupID snowflake.ID) iter.Seq[T] }
GroupedCache is a simple key value store grouped by a snowflake.ID. They key is always a snowflake.ID. The cache provides a simple way to store and retrieve entities. But is not guaranteed to be thread safe as this depends on the underlying implementation.
func NewGroupedCache ¶
func NewGroupedCache[T any](flags Flags, neededFlags Flags, policy Policy[T]) GroupedCache[T]
NewGroupedCache returns a new default GroupedCache with the provided flags, neededFlags and policy.
type GroupedFilterFunc ¶
GroupedFilterFunc is used to filter grouped cached entities.
type GuildCache ¶
type GuildCache interface {
GuildCache() Cache[fluxer.Guild]
IsGuildUnready(guildID snowflake.ID) bool
SetGuildUnready(guildID snowflake.ID, unready bool)
UnreadyGuildIDs() []snowflake.ID
Guild(guildID snowflake.ID) (fluxer.Guild, bool)
Guilds() iter.Seq[fluxer.Guild]
GuildsLen() int
AddGuild(guild fluxer.Guild)
RemoveGuild(guildID snowflake.ID) (fluxer.Guild, bool)
}
type GuildScheduledEventCache ¶
type GuildScheduledEventCache interface {
GuildScheduledEventCache() GroupedCache[fluxer.GuildScheduledEvent]
GuildScheduledEvent(guildID snowflake.ID, guildScheduledEventID snowflake.ID) (fluxer.GuildScheduledEvent, bool)
GuildScheduledEvents(guildID snowflake.ID) iter.Seq[fluxer.GuildScheduledEvent]
GuildScheduledEventsAllLen() int
GuildScheduledEventsLen(guildID snowflake.ID) int
AddGuildScheduledEvent(guildScheduledEvent fluxer.GuildScheduledEvent)
RemoveGuildScheduledEvent(guildID snowflake.ID, guildScheduledEventID snowflake.ID) (fluxer.GuildScheduledEvent, bool)
RemoveGuildScheduledEventsByGuildID(guildID snowflake.ID)
}
func NewGuildScheduledEventCache ¶
func NewGuildScheduledEventCache(cache GroupedCache[fluxer.GuildScheduledEvent]) GuildScheduledEventCache
type MemberCache ¶
type MemberCache interface {
MemberCache() GroupedCache[fluxer.Member]
Member(guildID snowflake.ID, userID snowflake.ID) (fluxer.Member, bool)
Members(guildID snowflake.ID) iter.Seq[fluxer.Member]
MembersAllLen() int
MembersLen(guildID snowflake.ID) int
AddMember(member fluxer.Member)
RemoveMember(guildID snowflake.ID, userID snowflake.ID) (fluxer.Member, bool)
RemoveMembersByGuildID(guildID snowflake.ID)
}
func NewMemberCache ¶
func NewMemberCache(cache GroupedCache[fluxer.Member]) MemberCache
type MessageCache ¶
type MessageCache interface {
MessageCache() GroupedCache[fluxer.Message]
Message(channelID snowflake.ID, messageID snowflake.ID) (fluxer.Message, bool)
Messages(channelID snowflake.ID) iter.Seq[fluxer.Message]
MessagesAllLen() int
MessagesLen(guildID snowflake.ID) int
AddMessage(message fluxer.Message)
RemoveMessage(channelID snowflake.ID, messageID snowflake.ID) (fluxer.Message, bool)
RemoveMessagesByChannelID(channelID snowflake.ID)
RemoveMessagesByGuildID(guildID snowflake.ID)
}
func NewMessageCache ¶
func NewMessageCache(cache GroupedCache[fluxer.Message]) MessageCache
type Policy ¶
Policy can be used to define your own policy for when entities should be cached.
func AllPolicies ¶
AllPolicies is a shorthand for CachePolicy.And(CachePolicy).And(CachePolicy) etc.
func PolicyChannelExclude ¶
func PolicyChannelExclude(channelTypes ...fluxer.ChannelType) Policy[fluxer.Channel]
PolicyChannelExclude returns a policy that will not cache channels of the given types.
func PolicyChannelInclude ¶
func PolicyChannelInclude(channelTypes ...fluxer.ChannelType) Policy[fluxer.Channel]
PolicyChannelInclude returns a policy that will only cache channels of the given types.
func PolicyMembersInVoice ¶
PolicyMembersInVoice returns a policy that will only cache members that are connected to an audio channel.
func PolicyMembersInclude ¶
PolicyMembersInclude returns a policy that will only cache members of the given guilds.
type PresenceCache ¶
type PresenceCache interface {
PresenceCache() GroupedCache[fluxer.Presence]
Presence(guildID snowflake.ID, userID snowflake.ID) (fluxer.Presence, bool)
Presences(guildID snowflake.ID) iter.Seq[fluxer.Presence]
PresencesAllLen() int
PresencesLen(guildID snowflake.ID) int
AddPresence(presence fluxer.Presence)
RemovePresence(guildID snowflake.ID, userID snowflake.ID) (fluxer.Presence, bool)
RemovePresencesByGuildID(guildID snowflake.ID)
}
func NewPresenceCache ¶
func NewPresenceCache(cache GroupedCache[fluxer.Presence]) PresenceCache
type RoleCache ¶
type RoleCache interface {
RoleCache() GroupedCache[fluxer.Role]
Role(guildID snowflake.ID, roleID snowflake.ID) (fluxer.Role, bool)
Roles(guildID snowflake.ID) iter.Seq[fluxer.Role]
RolesAllLen() int
RolesLen(guildID snowflake.ID) int
AddRole(role fluxer.Role)
RemoveRole(guildID snowflake.ID, roleID snowflake.ID) (fluxer.Role, bool)
RemoveRolesByGuildID(guildID snowflake.ID)
}
func NewRoleCache ¶
func NewRoleCache(cache GroupedCache[fluxer.Role]) RoleCache
type SelfUserCache ¶
type SelfUserCache interface {
SelfUser() (fluxer.OAuth2User, bool)
SetSelfUser(selfUser fluxer.OAuth2User)
}
func NewSelfUserCache ¶
func NewSelfUserCache() SelfUserCache
type Set ¶
type Set[T comparable] interface { // Add adds an item to the set. Add(item T) // Remove removes an item from the set. Remove(item T) // Has returns true if the item is in the set, false otherwise. Has(item T) bool // Len returns the number of items in the set. Len() int // Clear removes all items from the set. Clear() // All returns an iterator over all items in the set. All() iter.Seq[T] }
Set is a collection of unique items. It should be thread-safe.
func NewSet ¶
func NewSet[T comparable]() Set[T]
NewSet returns a thread-safe in memory implementation of a set.
type StickerCache ¶
type StickerCache interface {
StickerCache() GroupedCache[fluxer.Sticker]
Sticker(guildID snowflake.ID, stickerID snowflake.ID) (fluxer.Sticker, bool)
Stickers(guildID snowflake.ID) iter.Seq[fluxer.Sticker]
StickersAllLen() int
StickersLen(guildID snowflake.ID) int
AddSticker(sticker fluxer.Sticker)
RemoveSticker(guildID snowflake.ID, stickerID snowflake.ID) (fluxer.Sticker, bool)
RemoveStickersByGuildID(guildID snowflake.ID)
}
func NewStickerCache ¶
func NewStickerCache(cache GroupedCache[fluxer.Sticker]) StickerCache
type VoiceStateCache ¶
type VoiceStateCache interface {
VoiceStateCache() GroupedCache[fluxer.VoiceState]
VoiceState(guildID snowflake.ID, userID snowflake.ID) (fluxer.VoiceState, bool)
VoiceStates(guildID snowflake.ID) iter.Seq[fluxer.VoiceState]
VoiceStatesAllLen() int
VoiceStatesLen(guildID snowflake.ID) int
AddVoiceState(voiceState fluxer.VoiceState)
RemoveVoiceState(guildID snowflake.ID, userID snowflake.ID) (fluxer.VoiceState, bool)
RemoveVoiceStatesByGuildID(guildID snowflake.ID)
}
func NewVoiceStateCache ¶
func NewVoiceStateCache(cache GroupedCache[fluxer.VoiceState]) VoiceStateCache