scripting

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interpreter

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

Interpreter is a script interpreter

func NewInterpreter

func NewInterpreter(script string, logger zerolog.Logger) (*Interpreter, error)

NewInterpreter create new script interpreter

func (*Interpreter) Exec

func (i *Interpreter) Exec(ctx context.Context, input ScriptInput) (OperationStack, error)

Exec a script by the interpreter

type Operation

type Operation struct {
	Name OperationName
	Args []string
}

Operation object

func NewOperation

func NewOperation(name OperationName, args ...string) *Operation

NewOperation create new operation

func (Operation) GetFirstArg

func (op Operation) GetFirstArg() string

GetFirstArg retrn first operation argument

type OperationName

type OperationName uint

OperationName is the operation name

const (
	// OpDrop to drop an article
	OpDrop OperationName = iota
	// OpTriggerWebhook to trigger an outgoing webhook
	OpTriggerWebhook
	// OpSendNotification to send a notification to all user devices
	OpSendNotification
	// OpSetText to set article text
	OpSetText
	// OpSetTitle to set article title
	OpSetTitle
	// OpSetCategory to set article category
	OpSetCategory
	// OpDisableGlobalNotification to disable global notification
	OpDisableGlobalNotification
)

type OperationStack

type OperationStack []Operation

OperationStack is a stack of operation

func (OperationStack) Contains

func (ops OperationStack) Contains(op OperationName) bool

Contains test if an operation is part of the stack

type ScriptEngine

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

ScriptEngine is the scripting engine

func NewScriptEngine

func NewScriptEngine(cacheSize int) *ScriptEngine

NewScriptEngine create new script engine

func (*ScriptEngine) Exec

func (s *ScriptEngine) Exec(ctx context.Context, script string, input ScriptInput) (OperationStack, error)

Exec a script by the script engine

type ScriptInput

type ScriptInput struct {
	URL    string
	HTML   string
	Text   string
	Title  string
	Origin string
	Tags   []string
}

ScriptInput is the paylod passed to the script

Jump to

Keyboard shortcuts

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