Documentation ¶
Overview ¶
Package state provides interfaces for a local or remote state, as well as abstractions around the REST API and Gateway events.
Index ¶
- Variables
- type DefaultStore
- func (s *DefaultStore) Channel(id discord.Snowflake) (*discord.Channel, error)
- func (s *DefaultStore) ChannelRemove(channel *discord.Channel) error
- func (s *DefaultStore) ChannelSet(channel *discord.Channel) error
- func (s *DefaultStore) Channels(guildID discord.Snowflake) ([]discord.Channel, error)
- func (s *DefaultStore) Emoji(guildID, emojiID discord.Snowflake) (*discord.Emoji, error)
- func (s *DefaultStore) EmojiSet(guildID discord.Snowflake, emojis []discord.Emoji) error
- func (s *DefaultStore) Emojis(guildID discord.Snowflake) ([]discord.Emoji, error)
- func (s *DefaultStore) Guild(id discord.Snowflake) (*discord.Guild, error)
- func (s *DefaultStore) GuildRemove(id discord.Snowflake) error
- func (s *DefaultStore) GuildSet(g *discord.Guild) error
- func (s *DefaultStore) Guilds() ([]discord.Guild, error)
- func (s *DefaultStore) Member(guildID, userID discord.Snowflake) (*discord.Member, error)
- func (s *DefaultStore) MemberRemove(guildID, userID discord.Snowflake) error
- func (s *DefaultStore) MemberSet(guildID discord.Snowflake, member *discord.Member) error
- func (s *DefaultStore) Members(guildID discord.Snowflake) ([]discord.Member, error)
- func (s *DefaultStore) Message(channelID, messageID discord.Snowflake) (*discord.Message, error)
- func (s *DefaultStore) MessageRemove(channelID, messageID discord.Snowflake) error
- func (s *DefaultStore) MessageSet(message *discord.Message) error
- func (s *DefaultStore) Messages(channelID discord.Snowflake) ([]discord.Message, error)
- func (s *DefaultStore) Presence(guildID, userID discord.Snowflake) (*discord.Presence, error)
- func (s *DefaultStore) PresenceRemove(guildID, userID discord.Snowflake) error
- func (s *DefaultStore) PresenceSet(guildID discord.Snowflake, presence *discord.Presence) error
- func (s *DefaultStore) Presences(guildID discord.Snowflake) ([]discord.Presence, error)
- func (s *DefaultStore) PrivateChannels() ([]discord.Channel, error)
- func (s *DefaultStore) Reset() error
- func (s *DefaultStore) Role(guildID, roleID discord.Snowflake) (*discord.Role, error)
- func (s *DefaultStore) RoleRemove(guildID, roleID discord.Snowflake) error
- func (s *DefaultStore) RoleSet(guildID discord.Snowflake, role *discord.Role) error
- func (s *DefaultStore) Roles(guildID discord.Snowflake) ([]discord.Role, error)
- func (s *DefaultStore) Self() (*discord.User, error)
- func (s *DefaultStore) SelfSet(me *discord.User) error
- type DefaultStoreOptions
- type State
- func (s *State) Channel(id discord.Snowflake) (*discord.Channel, error)
- func (s *State) Channels(guildID discord.Snowflake) ([]discord.Channel, error)
- func (s *State) Emoji(guildID, emojiID discord.Snowflake) (*discord.Emoji, error)
- func (s *State) Emojis(guildID discord.Snowflake) ([]discord.Emoji, error)
- func (s *State) Guild(id discord.Snowflake) (*discord.Guild, error)
- func (s *State) Guilds() ([]discord.Guild, error)
- func (s *State) Member(guildID, userID discord.Snowflake) (*discord.Member, error)
- func (s *State) Members(guildID discord.Snowflake) ([]discord.Member, error)
- func (s *State) Message(channelID, messageID discord.Snowflake) (*discord.Message, error)
- func (s *State) Messages(channelID discord.Snowflake) ([]discord.Message, error)
- func (s *State) Permissions(channelID, userID discord.Snowflake) (discord.Permissions, error)
- func (s *State) Presence(guildID, userID discord.Snowflake) (*discord.Presence, error)
- func (s *State) Presences(guildID discord.Snowflake) ([]discord.Presence, error)
- func (s *State) Role(guildID, roleID discord.Snowflake) (*discord.Role, error)
- func (s *State) Roles(guildID discord.Snowflake) ([]discord.Role, error)
- func (s *State) Self() (*discord.User, error)
- func (s *State) Unhook()
- type Store
- type StoreGetter
- type StoreModifier
Constants ¶
This section is empty.
Variables ¶
var ( MaxFetchMembers uint = 1000 MaxFetchGuilds uint = 100 )
var ErrStoreNotFound = errors.New("item not found in store")
ErrStoreNotFound is an error that a store can use to return when something isn't in the storage. There is no strict restrictions on what uses this (the default one does, though), so be advised.
Functions ¶
This section is empty.
Types ¶
type DefaultStore ¶
type DefaultStore struct { *DefaultStoreOptions // contains filtered or unexported fields }
func NewDefaultStore ¶
func NewDefaultStore(opts *DefaultStoreOptions) *DefaultStore
func (*DefaultStore) ChannelRemove ¶
func (s *DefaultStore) ChannelRemove(channel *discord.Channel) error
func (*DefaultStore) ChannelSet ¶
func (s *DefaultStore) ChannelSet(channel *discord.Channel) error
func (*DefaultStore) GuildRemove ¶
func (s *DefaultStore) GuildRemove(id discord.Snowflake) error
func (*DefaultStore) MemberRemove ¶
func (s *DefaultStore) MemberRemove(guildID, userID discord.Snowflake) error
func (*DefaultStore) MessageRemove ¶
func (s *DefaultStore) MessageRemove( channelID, messageID discord.Snowflake) error
func (*DefaultStore) MessageSet ¶
func (s *DefaultStore) MessageSet(message *discord.Message) error
func (*DefaultStore) PresenceRemove ¶
func (s *DefaultStore) PresenceRemove(guildID, userID discord.Snowflake) error
func (*DefaultStore) PresenceSet ¶
func (*DefaultStore) PrivateChannels ¶
func (s *DefaultStore) PrivateChannels() ([]discord.Channel, error)
func (*DefaultStore) Reset ¶
func (s *DefaultStore) Reset() error
func (*DefaultStore) RoleRemove ¶
func (s *DefaultStore) RoleRemove(guildID, roleID discord.Snowflake) error
type DefaultStoreOptions ¶
type DefaultStoreOptions struct {
MaxMessages uint // default 50
}
type State ¶
type State struct { *session.Session Store // Ready is not updated by the state. Ready gateway.ReadyEvent // ErrorLog logs all errors that handler might have, including state fails. // This handler will also be used for Session, which would also be used for // Gateway. Defaults to log.Println. ErrorLog func(error) // PreHandler is the manual hook that is executed before the State handler // is. This should only be used for low-level operations. // It's recommended to set Synchronous to true if you mutate the events. PreHandler *handler.Handler // default nil // contains filtered or unexported fields }
func (*State) Messages ¶
Messages fetches maximum 100 messages from the API, if it has to. There is no limit if it's from the State storage.
func (*State) Permissions ¶
type Store ¶
type Store interface { StoreGetter StoreModifier }
Store is the state storage. It should handle mutex itself, and it should only concern itself with the local state.
type StoreGetter ¶
type StoreGetter interface { Self() (*discord.User, error) Channel(id discord.Snowflake) (*discord.Channel, error) Channels(guildID discord.Snowflake) ([]discord.Channel, error) PrivateChannels() ([]discord.Channel, error) Emoji(guildID, emojiID discord.Snowflake) (*discord.Emoji, error) Emojis(guildID discord.Snowflake) ([]discord.Emoji, error) Guild(id discord.Snowflake) (*discord.Guild, error) Guilds() ([]discord.Guild, error) Member(guildID, userID discord.Snowflake) (*discord.Member, error) Members(guildID discord.Snowflake) ([]discord.Member, error) Message(channelID, messageID discord.Snowflake) (*discord.Message, error) Messages(channelID discord.Snowflake) ([]discord.Message, error) // These don't get fetched from the API, it's Gateway only. Presence(guildID, userID discord.Snowflake) (*discord.Presence, error) Presences(guildID discord.Snowflake) ([]discord.Presence, error) Role(guildID, roleID discord.Snowflake) (*discord.Role, error) Roles(guildID discord.Snowflake) ([]discord.Role, error) }
All methods in StoreGetter will be wrapped by the State. If the State can't find anything in the storage, it will call the API itself and automatically add what's missing into the storage.
type StoreModifier ¶
type StoreModifier interface { SelfSet(me *discord.User) error // ChannelSet should switch on Type to know if it's a private channel or // not. ChannelSet(*discord.Channel) error ChannelRemove(*discord.Channel) error EmojiSet(guildID discord.Snowflake, emojis []discord.Emoji) error GuildSet(*discord.Guild) error GuildRemove(id discord.Snowflake) error MemberSet(guildID discord.Snowflake, member *discord.Member) error MemberRemove(guildID, userID discord.Snowflake) error MessageSet(*discord.Message) error MessageRemove(channelID, messageID discord.Snowflake) error PresenceSet(guildID discord.Snowflake, presence *discord.Presence) error PresenceRemove(guildID, userID discord.Snowflake) error RoleSet(guildID discord.Snowflake, role *discord.Role) error RoleRemove(guildID, roleID discord.Snowflake) error // This should reset all the state to zero/null. Reset() error }