Documentation
¶
Overview ¶
Package store provides persistent state storage for the bot.
Index ¶
- func AccountStateDir(accountID string) string
- func DefaultStateDir() string
- type ContextStore
- func (s *ContextStore) All() map[string]string
- func (s *ContextStore) Clear() error
- func (s *ContextStore) Delete(userID string) error
- func (s *ContextStore) Get(userID string) string
- func (s *ContextStore) Load() error
- func (s *ContextStore) Path() string
- func (s *ContextStore) Save() error
- func (s *ContextStore) Set(userID, token string) error
- type CursorData
- type CursorStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccountStateDir ¶
AccountStateDir returns ~/.wechatbot/accounts/{accountID}.
Types ¶
type ContextStore ¶
type ContextStore struct {
// contains filtered or unexported fields
}
ContextStore persists context tokens per user. Tokens are needed to reply in the correct conversation and must survive restarts.
func NewContextStore ¶
func NewContextStore(accountID, path string) *ContextStore
NewContextStore creates a store backed by the given file path. If path is empty, it defaults to ~/.wechatbot/accounts/{accountID}/context_tokens.json when accountID is non-empty, otherwise ~/.wechatbot/context_tokens.json.
func (*ContextStore) All ¶
func (s *ContextStore) All() map[string]string
All returns a copy of all stored tokens.
func (*ContextStore) Clear ¶
func (s *ContextStore) Clear() error
Clear removes all tokens from memory and disk.
func (*ContextStore) Delete ¶
func (s *ContextStore) Delete(userID string) error
Delete removes a user's context token.
func (*ContextStore) Get ¶
func (s *ContextStore) Get(userID string) string
Get returns the context token for a user, or empty string if none.
func (*ContextStore) Load ¶
func (s *ContextStore) Load() error
Load reads tokens from disk into memory. Missing files are treated as empty; malformed files return an error.
func (*ContextStore) Path ¶
func (s *ContextStore) Path() string
Path returns the backing file path.
func (*ContextStore) Save ¶
func (s *ContextStore) Save() error
Save writes the current in-memory tokens to disk.
func (*ContextStore) Set ¶
func (s *ContextStore) Set(userID, token string) error
Set stores a context token and persists it to disk.
type CursorData ¶
type CursorData struct {
GetUpdatesBuf string `json:"get_updates_buf"`
}
CursorData is the on-disk format for future extensibility.
type CursorStore ¶
type CursorStore struct {
// contains filtered or unexported fields
}
CursorStore persists the get_updates_buf cursor so the bot can resume polling after a restart.
func NewCursorStore ¶
func NewCursorStore(accountID, path string) *CursorStore
NewCursorStore creates a store backed by the given file path. If path is empty, it defaults to ~/.wechatbot/accounts/{accountID}/cursor.json when accountID is non-empty, otherwise ~/.wechatbot/cursor.json.
func (*CursorStore) Save ¶
func (s *CursorStore) Save() error
Save persists the current cursor to disk.
func (*CursorStore) Set ¶
func (s *CursorStore) Set(buf string) error
Set updates the cursor and persists it.