cchat-discord/internal/discord/state/labels/container.go

48 lines
1.2 KiB
Go
Raw Normal View History

2021-03-13 08:21:12 +00:00
package labels
import (
"github.com/diamondburned/arikawa/v2/discord"
"github.com/diamondburned/cchat"
)
type labelContainers struct {
2021-03-15 04:30:05 +00:00
guilds map[discord.GuildID]guildContainer
channels map[discord.ChannelID]labelerList
presences map[discord.UserID]labelerList
2021-03-13 08:21:12 +00:00
}
func newLabelContainers() labelContainers {
return labelContainers{
2021-03-15 04:30:05 +00:00
guilds: map[discord.GuildID]guildContainer{},
channels: map[discord.ChannelID]labelerList{},
presences: map[discord.UserID]labelerList{},
2021-03-13 08:21:12 +00:00
}
}
type guildContainer struct {
guild labelerList // optional
members map[discord.UserID]labelerList // optional
}
// IsEmpty returns true if the container no longer holds any labeler.
func (gcont guildContainer) IsEmpty() bool {
return len(gcont.guild) == 0 && len(gcont.members) == 0
}
// labelerList is a list of labelers.
type labelerList map[cchat.LabelContainer]struct{}
// Add adds the given labeler. If the map is nil, then a new one is created.
func (llist *labelerList) Add(l cchat.LabelContainer) {
if *llist == nil {
*llist = make(map[cchat.LabelContainer]struct{}, 1)
}
(*llist)[l] = struct{}{}
}
// Remove removes the given labeler.
func (llist labelerList) Remove(l cchat.LabelContainer) {
delete(llist, l)
}