bot

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CMD_START       = "start"
	CMD_HELP        = "help"
	CMD_CANCEL      = "cancel"
	CMD_SIMPLE      = "simple"
	CMD_LIST        = "list"
	CMD_ARCHIVE_ALL = "archiveAll"
	CMD_DELETE_ALL  = "deleteAll"
	CMD_SUGGEST     = "suggestions"
	CMD_CONFIG      = "config"

	CMD_ADM_NOTIFY = "admin_notify"
	CMD_ADM_CRON   = "admin_cron"
)
View Source
const (
	TRACE = helpers.TRACE
	DEBUG = helpers.DEBUG
	INFO  = helpers.INFO
	WARN  = helpers.WARN
	ERROR = helpers.ERROR
	FATAL = helpers.FATAL
)
View Source
const FORMATTER_PLACEHOLDER = "${SPACE_FORMAT}"
View Source
const MSG_UNFINISHED_STATE = "You have an unfinished operation running. Please finish it or /cancel it before starting a new one."
View Source
const TEMPLATE_SIMPLE_DEFAULT = `${date} * "${description}"${tag}
  ${account:from:the money came *from*} ${-amount}
  ${account:to:the money went *to*}`

Variables

View Source
var (
	CMD_COMMENT  = []string{"comment", "c"}
	CMD_TEMPLATE = []string{"template", "t"}
)
View Source
var TEMPLATE_TYPE_HINTS = map[Type]HintTemplate{
	Type(c.FIELD_AMOUNT): {
		Text:    "Please enter the *amount* of money {{.FieldHint}} (e.g. '12.34' or '12.34 {{.FieldDefault}}')",
		Handler: HandleFloat,
	},
	Type(c.FIELD_ACCOUNT): {
		Text:    "Please enter the *account* {{.FieldHint}} (or select one from the list)",
		Handler: HandleRaw,
	},
	Type(c.FIELD_DESCRIPTION): {
		Text:    "Please enter a *description* {{.FieldHint}} (or select one from the list)",
		Handler: HandleRaw,
	},
}

Functions

func HandleFloat

func HandleFloat(m *tb.Message) (string, error)

func HandleRaw

func HandleRaw(m *tb.Message) (string, error)

func ParseAmount

func ParseAmount(f float64) string

func ParseDate

func ParseDate(m string) (string, error)

func Recipient added in v0.19.0

func Recipient(m *tb.Message) tb.Recipient

func ReplyKeyboard

func ReplyKeyboard(buttons []string) *tb.ReplyMarkup

Types

type Bot

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

func (*Bot) Handle

func (b *Bot) Handle(endpoint interface{}, handler tb.HandlerFunc, m ...tb.MiddlewareFunc)

func (*Bot) Me

func (b *Bot) Me() *tb.User

func (*Bot) Respond

func (b *Bot) Respond(c *tb.Callback, resp ...*tb.CallbackResponse) error

func (*Bot) Send

func (b *Bot) Send(to tb.Recipient, what interface{}, options ...interface{}) (*tb.Message, error)

func (*Bot) SendSilent added in v0.24.0

func (b *Bot) SendSilent(logFn func(level helpers.Level, m *tb.Message, format string, v ...interface{}), to tb.Recipient, what interface{}, options ...interface{}) (*tb.Message, error)

func (*Bot) Start

func (b *Bot) Start()

type BotController

type BotController struct {
	Repo  *crud.Repo
	State *StateHandler
	Bot   IBot

	CronScheduler *gocron.Scheduler
}

func NewBotController

func NewBotController(db dbWrapper.DB) *BotController

func (*BotController) AddBotAndStart

func (bc *BotController) AddBotAndStart(b IBot)

func (*BotController) ConfigureCronScheduler

func (bc *BotController) ConfigureCronScheduler() *BotController

func (*BotController) DeleteUserData added in v1.0.0

func (bc *BotController) DeleteUserData(m *tb.Message)

func (*BotController) Logf

func (bc *BotController) Logf(level helpers.Level, m *tb.Message, format string, v ...interface{})

func (*BotController) MergeMessagesHonorSendLimit added in v0.17.1

func (bc *BotController) MergeMessagesHonorSendLimit(m []string, sep string) []string

type CMD

type CMD struct {
	CommandAlias []string
	Optional     []string
	Handler      tb.HandlerFunc
	Help         string
}

type Hint

type Hint struct {
	Prompt          string
	KeyboardOptions []string
}

type HintTemplate added in v0.21.0

type HintTemplate struct {
	Text    string
	Handler func(m *tb.Message) (string, error)
}

type IBot

type IBot interface {
	// Using from base package:
	Start()
	Handle(endpoint interface{}, h tb.HandlerFunc, m ...tb.MiddlewareFunc)
	Send(to tb.Recipient, what interface{}, options ...interface{}) (*tb.Message, error)
	Respond(c *tb.Callback, resp ...*tb.CallbackResponse) error
	// custom by me:
	Me() *tb.User
	SendSilent(logFn func(level helpers.Level, m *tb.Message, format string, v ...interface{}), to tb.Recipient, what interface{}, options ...interface{}) (*tb.Message, error)
}

func CreateBot

func CreateBot(bc *BotController) IBot

type Input

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

type NumberConfig added in v0.21.0

type NumberConfig struct {
	Fraction   int
	IsNegative bool
}

type ReceiverImpl

type ReceiverImpl struct {
	ChatId string
}

func (ReceiverImpl) Recipient

func (r ReceiverImpl) Recipient() string

type Sender added in v0.19.0

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

func (Sender) Recipient added in v0.19.0

func (s Sender) Recipient() string

type SimpleTx

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

func (*SimpleTx) CacheData added in v0.21.0

func (tx *SimpleTx) CacheData() (data map[string]string)

func (*SimpleTx) Debug

func (tx *SimpleTx) Debug() string

func (*SimpleTx) EnrichHint

func (tx *SimpleTx) EnrichHint(r *crud.Repo, m *tb.Message, i *Input) *Hint

func (*SimpleTx) FillTemplate

func (tx *SimpleTx) FillTemplate(currency, tag string, tzOffset int) (string, error)

func (*SimpleTx) Input

func (tx *SimpleTx) Input(m *tb.Message) (isDone bool, err error)

func (*SimpleTx) IsDone

func (tx *SimpleTx) IsDone() bool

func (*SimpleTx) NextHint

func (tx *SimpleTx) NextHint(r *crud.Repo, m *tb.Message) *Hint

func (*SimpleTx) Prepare added in v0.21.0

func (tx *SimpleTx) Prepare() Tx

func (*SimpleTx) SetDate

func (tx *SimpleTx) SetDate(d string) (Tx, error)

type StateHandler

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

func NewStateHandler

func NewStateHandler() *StateHandler

func (*StateHandler) Clear

func (s *StateHandler) Clear(m *tb.Message)

func (*StateHandler) CountOpen added in v0.18.3

func (s *StateHandler) CountOpen() int

func (*StateHandler) GetTx

func (s *StateHandler) GetTx(m *tb.Message) Tx

func (*StateHandler) GetType

func (s *StateHandler) GetType(m *tb.Message) StateType

func (*StateHandler) SimpleTx

func (s *StateHandler) SimpleTx(m *tb.Message, suggestedCur string) (Tx, error)

func (*StateHandler) StartTpl

func (s *StateHandler) StartTpl(m *tb.Message, name string)

func (*StateHandler) TemplateTx

func (s *StateHandler) TemplateTx(m *tb.Message, template, suggestedCur, date string) (Tx, error)

type StateType

type StateType string
const (
	ST_NONE StateType = ""
	ST_TX   StateType = "tx"
	ST_TPL  StateType = "tpl"
)

type TemplateField

type TemplateField struct {
	TemplateHintData
	NumberConfig
}

func ParseTemplateField

func ParseTemplateField(rawField, currencySuggestion string) *TemplateField

func ParseTemplateFields

func ParseTemplateFields(template, currencySuggestion string) []*TemplateField

func SortTemplateFields added in v0.21.0

func SortTemplateFields(unsortedFields []*TemplateField) []*TemplateField

func (*TemplateField) FieldIdentifierForValue added in v0.21.0

func (tf *TemplateField) FieldIdentifierForValue() string

type TemplateHintData added in v0.21.0

type TemplateHintData struct {
	Raw string

	FieldName      string
	FieldSpecifier string
	FieldHint      string
	FieldDefault   string // This is not filled by field parsing logic yet. Instead values can be passed in.
}

type TemplateName

type TemplateName string

type TemplateTx

type TemplateTx struct {
}

type Tx

type Tx interface {
	Prepare() Tx
	Input(*tb.Message) (bool, error)
	IsDone() bool
	Debug() string
	NextHint(*crud.Repo, *tb.Message) *Hint
	EnrichHint(r *crud.Repo, m *tb.Message, i *Input) *Hint
	FillTemplate(currency, tag string, tzOffset int) (string, error)
	CacheData() map[string]string

	SetDate(string) (Tx, error)
	// contains filtered or unexported methods
}

func CreateSimpleTx

func CreateSimpleTx(suggestedCur, template string) (Tx, error)

type Type added in v0.21.0

type Type string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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