csm

package
v0.0.0-...-fa69253 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultExpirationTime int64  = 0           // records won't expire
	RecordPrefix          string = "user_data" // prefix for redis records
	InitialState          string = "~"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatStateMachineInterface

type ChatStateMachineInterface interface {
	UpdateState(update tgbotapi.Update, state string) map[string]interface{}
	GetState(update tgbotapi.Update) string
	UpdateData(update tgbotapi.Update, data map[string]interface{}) map[string]interface{}
	GetData(update tgbotapi.Update) map[string]interface{}
	ClearData(update tgbotapi.Update)
}

type InMenoryCsm

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

func (*InMenoryCsm) ClearData

func (c *InMenoryCsm) ClearData(update tgbotapi.Update)

update data bucket

func (*InMenoryCsm) Get

func (c *InMenoryCsm) Get(key string, create bool) map[string]interface{}

get data from key use `create=true` case you want to create new bucket with `key: {"__state__": INITIAL_VALUE}` if it was not found by `key`

func (*InMenoryCsm) GetData

func (c *InMenoryCsm) GetData(update tgbotapi.Update) map[string]interface{}

get user's saved data if no user found - will create new bucket

func (*InMenoryCsm) GetOrCreate

func (c *InMenoryCsm) GetOrCreate(key string) map[string]interface{}

will create new record if can't get one with particular key

func (*InMenoryCsm) GetState

func (c *InMenoryCsm) GetState(update tgbotapi.Update) string

func (*InMenoryCsm) Key

func (c *InMenoryCsm) Key(update tgbotapi.Update) string

get user identifier by most usable telegram update TODO: make all updates identifier

func (*InMenoryCsm) Set

func (c *InMenoryCsm) Set(key string, value string)

base set reimplementation with err handling

func (*InMenoryCsm) UpdateData

func (c *InMenoryCsm) UpdateData(update tgbotapi.Update, data map[string]interface{}) map[string]interface{}

update data bucket

func (*InMenoryCsm) UpdateState

func (c *InMenoryCsm) UpdateState(update tgbotapi.Update, state string) map[string]interface{}

sets new state TODO: discuss if __state__ key must be array of database and renamed to __states__

type RedisCsm

type RedisCsm struct {
	*redis.Client
}

func (*RedisCsm) ClearData

func (csm *RedisCsm) ClearData(update tgbotapi.Update)

update data bucket

func (*RedisCsm) Flush

func (csm *RedisCsm) Flush()

remove all stored data and database (flush db)

func (*RedisCsm) Get

func (csm *RedisCsm) Get(key string, create bool) map[string]interface{}

get data from key use `create=true` case you want to create new bucket with `key: {"__state__": INITIAL_VALUE}` if it was not found by `key`

func (*RedisCsm) GetData

func (csm *RedisCsm) GetData(update tgbotapi.Update) map[string]interface{}

get user's saved data if no user found - will create new bucket

func (*RedisCsm) GetOrCreate

func (csm *RedisCsm) GetOrCreate(key string) map[string]interface{}

will create new record if can't get one with particular key

func (*RedisCsm) GetState

func (csm *RedisCsm) GetState(update tgbotapi.Update) string

func (*RedisCsm) Key

func (csm *RedisCsm) Key(update tgbotapi.Update) string

get user identifier by most usable telegram update TODO: make all updates identifier

func (*RedisCsm) Set

func (csm *RedisCsm) Set(key string, value string)

base set reimplementation with err handling

func (*RedisCsm) UpdateData

func (csm *RedisCsm) UpdateData(update tgbotapi.Update, data map[string]interface{}) map[string]interface{}

update data bucket

func (*RedisCsm) UpdateState

func (csm *RedisCsm) UpdateState(update tgbotapi.Update, state string) map[string]interface{}

sets new state TODO: discuss if __state__ key must be array of database and renamed to __states__

Jump to

Keyboard shortcuts

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