store

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

This section is empty.

Types

type Expectation

type Expectation string
const (
	ExpectNothing   Expectation = ""
	ExpectLanguage  Expectation = "lang"
	ExpectAuthToken Expectation = "token"
	ExpectComment   Expectation = "comment"
)

type FsOption

type FsOption func(s *fsStore)

func FsMaxSentRecords

func FsMaxSentRecords(n int) FsOption

type SentMsgRec

type SentMsgRec struct {
	MessageID int
	Event     *frf.Event
	// .ReplyToMessage.MessageID
	ReplyToID int
}

type State

type State struct {
	ID          types.TgChatID
	Language    language.Tag
	UserID      uuid.UUID
	AccessToken string
	LastEventID uuid.UUID
	Expectation Expectation

	ReactToMessageID int
	CommentToPostID  uuid.UUID
	CommentPrefix    string
}

State is the saved state of a chat.

func NewChatState

func NewChatState(chatID types.TgChatID) *State

func (*State) ClearExpectations

func (s *State) ClearExpectations()

func (*State) IsAuthorized

func (s *State) IsAuthorized() bool

IsAuthorized returns true if the user is authorized.

func (*State) IsPausedExpectation

func (s *State) IsPausedExpectation() bool

type Store

type Store interface {
	// LoadState returnd state by chatID or nil if there is no state
	LoadState(chatID types.TgChatID) (*State, error)
	SaveState(state *State) error
	DeleteState(chatID types.TgChatID) error
	ListIDs() ([]types.TgChatID, error)

	// EventsQueue
	AddToQueue(chatID types.TgChatID, entry json.RawMessage) error
	LoadAndDeleteQueue(chatID types.TgChatID) ([]json.RawMessage, error)

	// EventsStore
	GetMsgRec(chatID types.TgChatID, messageID int) (SentMsgRec, error)
	PutMsgRec(chatID types.TgChatID, rec SentMsgRec) error

	// Tracked posts
	TrackPost(chatID types.TgChatID, postID uuid.UUID) error
	UntrackPost(chatID types.TgChatID, postID uuid.UUID) error
	IsPostTracked(chatID types.TgChatID, postID uuid.UUID) (bool, error)
	TrackedEntities(chatID types.TgChatID) (TrackedEntities, error)
}

Store abstracts database interface.

func NewFsStore

func NewFsStore(dirName string, options ...FsOption) Store

NewFsStore creates a new file-based Store.

type TrackedEntities

type TrackedEntities struct {
	PostIDs []uuid.UUID
}

Jump to

Keyboard shortcuts

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