store

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package store provides persistent state storage for the bot.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccountStateDir

func AccountStateDir(accountID string) string

AccountStateDir returns ~/.wechatbot/accounts/{accountID}.

func DefaultStateDir

func DefaultStateDir() string

DefaultStateDir returns ~/.wechatbot.

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) Clear

func (s *CursorStore) Clear() error

Clear removes the persisted cursor.

func (*CursorStore) Get

func (s *CursorStore) Get() string

Get returns the current cursor value.

func (*CursorStore) Load

func (s *CursorStore) Load() error

Load reads the cursor from disk.

func (*CursorStore) Path

func (s *CursorStore) Path() string

Path returns the backing file path.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL