factoid

package
v0.0.0-...-d726a1a Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2019 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const BangIdentifier = "factoid-bang"
View Source
const (
	FactoidNameMaxLen = 75
)
View Source
const Identifier = "factoid"

Variables

View Source
var DirectiveTokenRgx = regexp.MustCompile(`^{([a-z]+)}`)
View Source
var ErrNoSuchFactoid = errors.Errorf("Factoid does not exist")
View Source
var FunctionTokenRgx = regexp.MustCompile(`(^|[^\\])\$([a-zA-Z_][a-zA-Z0-9_]*)\(.*?\)`)

parenthesis matching performed separately 1 = backslash check 2 = name do parencheck starting at end of 2, ignore end of 0

View Source
var ParameterTokenRgx = regexp.MustCompile("%([A-Za-z]+)([0-9]+)?(-)?([0-9]+)?%")

Functions

func LNewFDataMap

func LNewFDataMap(g *lualib.G, mod *FactoidModule, mapName string) lua.LValue

func LNewFactoid

func LNewFactoid(g *lualib.G, mod *FactoidModule, name string) lua.LValue

func NewBangFactoidModule

func NewBangFactoidModule(t marvin.Team) marvin.Module

func NewFactoidModule

func NewFactoidModule(t marvin.Team) marvin.Module

func RegisterFunctionMultiArg

func RegisterFunctionMultiArg(name string, f func(args ...string) string)

func RegisterFunctionSingleArg

func RegisterFunctionSingleArg(name string, f func(args ...string) string)

func RegisterFunctionSingleArg2

func RegisterFunctionSingleArg2(name string, f func(arg string) string)

func RunFactoidLua

func RunFactoidLua(ctx context.Context, mod *FactoidModule, factoidName, factoidSource string, factoidArgs []string, of *OutputFlags, actSource marvin.ActionSource) (string, error)

Types

type API

type API interface {
	marvin.Module

	RunFactoid(ctx context.Context, line []string, of *OutputFlags, source marvin.ActionSource) (result string, err error)
}

type BangFactoidModule

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

func (*BangFactoidModule) Disable

func (mod *BangFactoidModule) Disable(team marvin.Team)

func (*BangFactoidModule) Enable

func (mod *BangFactoidModule) Enable(team marvin.Team)

func (*BangFactoidModule) Identifier

func (mod *BangFactoidModule) Identifier() marvin.ModuleID

func (*BangFactoidModule) Load

func (mod *BangFactoidModule) Load(t marvin.Team)

func (*BangFactoidModule) OnEdit

func (mod *BangFactoidModule) OnEdit(_rtm slack.RTMRawMessage)

func (*BangFactoidModule) OnMessage

func (mod *BangFactoidModule) OnMessage(_rtm slack.RTMRawMessage)

func (*BangFactoidModule) Process

func (mod *BangFactoidModule) Process(rtm slack.SlackTextMessage, isEditing bool) (string, OutputFlags)

type DirectiveToken

type DirectiveToken struct {
	Directive string
}

func Directives

func Directives(source string) ([]DirectiveToken, string)

func (DirectiveToken) Source

func (d DirectiveToken) Source() string

type ElevatedActionSource

type ElevatedActionSource struct {
	marvin.ActionSource
	Rights marvin.AccessLevel
}

ElevatedActionSource allows for a temporary elevation of user permissions. It modifies the returned AccessLevel, and the Drop method allows the original rights to be restored.

func (*ElevatedActionSource) AccessLevel

func (eas *ElevatedActionSource) AccessLevel() marvin.AccessLevel

AccessLevel returns the elevated level of access rights.

func (*ElevatedActionSource) Drop

Drop returns the un-elevated ActionSource.

type ErrSource

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

type ErrUser

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

type Factoid

type Factoid struct {
	Mod *FactoidModule

	IsBareInfo   bool
	DbID         int64
	FactoidName  string
	RawSource    string
	ScopeChannel slack.ChannelID

	LastUser      slack.UserID
	LastChannel   slack.ChannelID
	LastMessage   slack.MessageTS
	LastTimestamp time.Time

	IsLocked    bool
	IsForgotten bool
	// contains filtered or unexported fields
}

func (*Factoid) FillInfo

func (fi *Factoid) FillInfo(channel slack.ChannelID) error

FillInfo transforms a bare FactoidInfo into a full FactoidInfo.

func (*Factoid) Tokens

func (fi *Factoid) Tokens() ([]DirectiveToken, []Token)

Tokens can panic, make sure it gets called with PCall() before saving a factoid to the database.

type FactoidModule

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

func (*FactoidModule) CmdForget

func (*FactoidModule) CmdGet

func (*FactoidModule) CmdInfo

func (*FactoidModule) CmdList

func (*FactoidModule) CmdRemember

func (*FactoidModule) CmdSource

func (*FactoidModule) Disable

func (mod *FactoidModule) Disable(t marvin.Team)

func (*FactoidModule) Enable

func (mod *FactoidModule) Enable(team marvin.Team)

func (*FactoidModule) ForgetFactoid

func (mod *FactoidModule) ForgetFactoid(dbID int64, isForgotten bool) error

func (*FactoidModule) GetFDataAll

func (mod *FactoidModule) GetFDataAll(mapName string) (map[string][]byte, error)

func (*FactoidModule) GetFDataValue

func (mod *FactoidModule) GetFDataValue(mapName, keyName string) ([]byte, error)

func (*FactoidModule) GetFactoidBare

func (mod *FactoidModule) GetFactoidBare(name string, channel slack.ChannelID) (*Factoid, error)

func (*FactoidModule) GetFactoidHistory

func (mod *FactoidModule) GetFactoidHistory(name string, channel slack.ChannelID) ([]Factoid, error)

func (*FactoidModule) GetFactoidInfo

func (mod *FactoidModule) GetFactoidInfo(name string, channel slack.ChannelID, withForgotten bool) (*Factoid, error)

func (*FactoidModule) HTTPEditFactoid

func (mod *FactoidModule) HTTPEditFactoid(w http.ResponseWriter, r *http.Request)

func (*FactoidModule) HTTPListFactoids

func (mod *FactoidModule) HTTPListFactoids(w http.ResponseWriter, r *http.Request)

func (*FactoidModule) HTTPShowFactoid

func (mod *FactoidModule) HTTPShowFactoid(w http.ResponseWriter, r *http.Request)

func (*FactoidModule) Identifier

func (mod *FactoidModule) Identifier() marvin.ModuleID

func (*FactoidModule) ListFactoids

func (mod *FactoidModule) ListFactoids(match string, channel slack.ChannelID) (channelOnly, global []string, err error)

func (*FactoidModule) ListFactoidsWithInfo

func (mod *FactoidModule) ListFactoidsWithInfo(match string, channel slack.ChannelID) ([]*Factoid, error)

func (*FactoidModule) Load

func (mod *FactoidModule) Load(t marvin.Team)

func (*FactoidModule) LockFactoid

func (mod *FactoidModule) LockFactoid(dbID int64, isLocked bool) error

func (*FactoidModule) RunFactoid

func (mod *FactoidModule) RunFactoid(ctx context.Context, line []string, of *OutputFlags, source marvin.ActionSource) (result string, err error)

RunFactoid

Returns the following errors (make sure to use errors.Cause()):

factoidName, ErrNoSuchFactoid - Factoid not found
ErrUser - Something was wrong with the input. Not enough args, recursion limit reached.

func (*FactoidModule) SaveFactoid

func (mod *FactoidModule) SaveFactoid(name string, channel slack.ChannelID, rawSource string, source marvin.ActionSource) error

func (*FactoidModule) SetFDataValue

func (mod *FactoidModule) SetFDataValue(mapName, keyName string, val []byte)

func (*FactoidModule) Team

func (mod *FactoidModule) Team() marvin.Team

func (*FactoidModule) Tokenize

func (mod *FactoidModule) Tokenize(source string) []Token

type Function

type Function struct {
	F func(args ...string) string

	MultiArg bool
}

type FunctionToken

type FunctionToken struct {
	Function
	// contains filtered or unexported fields
}

func (FunctionToken) Run

func (p FunctionToken) Run(mod *FactoidModule, args []string, actionSource marvin.ActionSource) (string, error)

func (FunctionToken) Source

func (p FunctionToken) Source() string

type LFDataMap

type LFDataMap struct {
	MapName string
	// contains filtered or unexported fields
}

func (*LFDataMap) SetupMetatable

func (*LFDataMap) SetupMetatable(L *lua.LState)

type LFactoid

type LFactoid struct {
	Name string
	// contains filtered or unexported fields
}

LFactoid has the following API, where `factoid` is the global of the same name:

f = factoid.name
factoid.test(...args...) -> String, result of running !test ...args...
factoid.test.src -> String
factoid.test.exists -> Bool
factoid.test.author -> LUser
factoid.test.islocal -> Bool
factoid.test.time -> UnixSecs
factoid.test.created -> Slack archive link
factoid.test.history -> List<
factoid.test.data -> String
factoid.test.data = v

If f.exists is false, most other methods will error.

func (*LFactoid) SetupMetatable

func (*LFactoid) SetupMetatable(L *lua.LState)

type OutputFlags

type OutputFlags struct {
	NoReply     bool
	Say         bool
	Pre         bool
	SideEffects bool

	DisallowLua bool
}

type ParameterToken

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

func (ParameterToken) Run

func (p ParameterToken) Run(mod *FactoidModule, args []string, actionSource marvin.ActionSource) (string, error)

func (ParameterToken) Source

func (p ParameterToken) Source() string

type TextToken

type TextToken struct {
	Text string
}

func (TextToken) Run

func (t TextToken) Run(mod *FactoidModule, args []string, actionSource marvin.ActionSource) (string, error)

func (TextToken) Source

func (t TextToken) Source() string

type Token

type Token interface {
	Run(mod *FactoidModule, args []string, actionSource marvin.ActionSource) (string, error)
	Source() string
}

func NewParameterToken

func NewParameterToken(rawStr, opStr, startStr, rangeStr, endStr string) Token

Pass match[0], match[1], ... match[4]

Jump to

Keyboard shortcuts

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