store

package
v0.0.0-...-cddfdf2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Media

type Media struct {
	ID        string   `json:"id"`
	FileID    string   `json:"file_id"`
	Type      string   `json:"type"` // "photo" or "video"
	Caption   string   `json:"caption"`
	AddedBy   string   `json:"added_by"`
	CreatedAt int64    `json:"created_at"`
	R2Key     string   `json:"r2_key,omitempty"` // Key in R2 bucket if uploaded
	Tags      []string `json:"tags,omitempty"`
}

Media represents a saved telegram photo or video.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store persists user data and settings to BoltDB.

func New

func New(path string) (*Store, error)

New initializes the store with the provided file path.

func (*Store) AddPoints

func (s *Store) AddPoints(id string, delta int) (*User, error)

AddPoints adds points to a user.

func (*Store) CheckIn

func (s *Store) CheckIn(id string, reward int) (int, *User, error)

CheckIn processes a daily check-in and returns gained points or an error.

func (*Store) ClearChatHistory

func (s *Store) ClearChatHistory(userID string) error

ClearChatHistory deletes the chat history for a user.

func (*Store) Close

func (s *Store) Close() error

Close releases database resources.

func (*Store) CountMedia

func (s *Store) CountMedia() (int, error)

CountMedia returns the total number of media items.

func (*Store) DeleteMedia

func (s *Store) DeleteMedia(id string) error

DeleteMedia removes a media by ID.

func (*Store) GetChatHistory

func (s *Store) GetChatHistory(userID string) ([]byte, error)

GetChatHistory retrieves the chat history for a user.

func (*Store) GetMedia

func (s *Store) GetMedia(id string) (*Media, error)

GetMedia returns a single media item by its ID.

func (*Store) GetModel

func (s *Store) GetModel() (string, error)

GetModel returns the stored model or empty string when unset.

func (*Store) GetOrCreateUser

func (s *Store) GetOrCreateUser(id string, username, displayName string) (*User, error)

GetOrCreateUser retrieves or creates a user.

func (*Store) GetRandomMedia

func (s *Store) GetRandomMedia() (*Media, error)

GetRandomMedia returns a random media from the store.

func (*Store) GetRateLimit

func (s *Store) GetRateLimit() (limit int, ok bool, err error)

GetRateLimit returns the stored chat rate limit per minute and whether it was set. A stored value <=0 means the rate limit is disabled.

func (*Store) GetUser

func (s *Store) GetUser(id string) (*User, error)

GetUser retrieves a user by ID without creating a new record.

func (*Store) GetVisionEnabled

func (s *Store) GetVisionEnabled() (bool, error)

GetVisionEnabled returns the global vision enabled status.

func (*Store) ListMedia

func (s *Store) ListMedia(limit, offset int) ([]Media, error)

ListMedia retrieves all media with pagination.

func (*Store) ListSubscribers

func (s *Store) ListSubscribers() ([]string, error)

ListSubscribers returns all subscriber IDs

func (*Store) ListUsers

func (s *Store) ListUsers(limit, offset int) ([]User, error)

ListUsers retrieves all users sorted by ID with pagination.

func (*Store) PromoteAdmin

func (s *Store) PromoteAdmin(id string) (*User, error)

PromoteAdmin promotes a user to admin.

func (*Store) SaveChatHistory

func (s *Store) SaveChatHistory(userID string, data []byte) error

SaveChatHistory persists the chat history for a user.

func (*Store) SaveMedia

func (s *Store) SaveMedia(id, paramsType, caption string, addedBy string) error

SaveMedia saves a media item.

func (*Store) SetMediaR2

func (s *Store) SetMediaR2(id, r2Key string) error

SetMediaR2 updates the R2Key for a media item.

func (*Store) SetMediaTags

func (s *Store) SetMediaTags(id string, tags []string) error

SetMediaTags updates the tags for a media item.

func (*Store) SetModel

func (s *Store) SetModel(model string) error

SetModel updates the stored OpenAI model name.

func (*Store) SetPersona

func (s *Store) SetPersona(id string, persona string) error

SetPersona saves the user's persona (system prompt customization)

func (*Store) SetPoints

func (s *Store) SetPoints(id string, points int) (*User, error)

SetPoints sets a user's points to a specific value.

func (*Store) SetRateLimit

func (s *Store) SetRateLimit(limit int) error

SetRateLimit updates the allowed chat requests per minute. A value <=0 disables the limit.

func (*Store) SetVisionEnabled

func (s *Store) SetVisionEnabled(enabled bool) error

SetVisionEnabled sets the global vision enabled status.

func (*Store) Subscribe

func (s *Store) Subscribe(chatID string) error

Subscribe adds a chat ID to subscriptions

func (*Store) Unsubscribe

func (s *Store) Unsubscribe(chatID string) error

Unsubscribe removes a chat ID

type User

type User struct {
	ID          string `json:"id"`
	Username    string `json:"username"`
	Points      int    `json:"points"`
	LastCheckin string `json:"last_checkin"`
	IsAdmin     bool   `json:"is_admin"`
	DisplayName string `json:"display_name"`
	Persona     string `json:"persona,omitempty"`
}

User represents a Telegram user state.

Jump to

Keyboard shortcuts

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