Documentation ¶
Index ¶
- Constants
- Variables
- func LNewFDataMap(g *lualib.G, mod *FactoidModule, mapName string) lua.LValue
- func LNewFactoid(g *lualib.G, mod *FactoidModule, name string) lua.LValue
- func NewBangFactoidModule(t marvin.Team) marvin.Module
- func NewFactoidModule(t marvin.Team) marvin.Module
- func RegisterFunctionMultiArg(name string, f func(args ...string) string)
- func RegisterFunctionSingleArg(name string, f func(args ...string) string)
- func RegisterFunctionSingleArg2(name string, f func(arg string) string)
- func RunFactoidLua(ctx context.Context, mod *FactoidModule, factoidName, factoidSource string, ...) (string, error)
- type API
- type BangFactoidModule
- func (mod *BangFactoidModule) Disable(team marvin.Team)
- func (mod *BangFactoidModule) Enable(team marvin.Team)
- func (mod *BangFactoidModule) Identifier() marvin.ModuleID
- func (mod *BangFactoidModule) Load(t marvin.Team)
- func (mod *BangFactoidModule) OnEdit(_rtm slack.RTMRawMessage)
- func (mod *BangFactoidModule) OnMessage(_rtm slack.RTMRawMessage)
- func (mod *BangFactoidModule) Process(rtm slack.SlackTextMessage, isEditing bool) (string, OutputFlags)
- type DirectiveToken
- type ElevatedActionSource
- type ErrSource
- type ErrUser
- type Factoid
- type FactoidModule
- func (mod *FactoidModule) CmdForget(t marvin.Team, args *marvin.CommandArguments) marvin.CommandResult
- func (mod *FactoidModule) CmdGet(t marvin.Team, args *marvin.CommandArguments) marvin.CommandResult
- func (mod *FactoidModule) CmdInfo(t marvin.Team, args *marvin.CommandArguments) marvin.CommandResult
- func (mod *FactoidModule) CmdList(t marvin.Team, args *marvin.CommandArguments) marvin.CommandResult
- func (mod *FactoidModule) CmdRemember(t marvin.Team, args *marvin.CommandArguments) marvin.CommandResult
- func (mod *FactoidModule) CmdSource(t marvin.Team, args *marvin.CommandArguments) marvin.CommandResult
- func (mod *FactoidModule) Disable(t marvin.Team)
- func (mod *FactoidModule) Enable(team marvin.Team)
- func (mod *FactoidModule) ForgetFactoid(dbID int64, isForgotten bool) error
- func (mod *FactoidModule) GetFDataAll(mapName string) (map[string][]byte, error)
- func (mod *FactoidModule) GetFDataValue(mapName, keyName string) ([]byte, error)
- func (mod *FactoidModule) GetFactoidBare(name string, channel slack.ChannelID) (*Factoid, error)
- func (mod *FactoidModule) GetFactoidHistory(name string, channel slack.ChannelID) ([]Factoid, error)
- func (mod *FactoidModule) GetFactoidInfo(name string, channel slack.ChannelID, withForgotten bool) (*Factoid, error)
- func (mod *FactoidModule) HTTPEditFactoid(w http.ResponseWriter, r *http.Request)
- func (mod *FactoidModule) HTTPListFactoids(w http.ResponseWriter, r *http.Request)
- func (mod *FactoidModule) HTTPShowFactoid(w http.ResponseWriter, r *http.Request)
- func (mod *FactoidModule) Identifier() marvin.ModuleID
- func (mod *FactoidModule) ListFactoids(match string, channel slack.ChannelID) (channelOnly, global []string, err error)
- func (mod *FactoidModule) ListFactoidsWithInfo(match string, channel slack.ChannelID) ([]*Factoid, error)
- func (mod *FactoidModule) Load(t marvin.Team)
- func (mod *FactoidModule) LockFactoid(dbID int64, isLocked bool) error
- func (mod *FactoidModule) RunFactoid(ctx context.Context, line []string, of *OutputFlags, ...) (result string, err error)
- func (mod *FactoidModule) SaveFactoid(name string, channel slack.ChannelID, rawSource string, ...) error
- func (mod *FactoidModule) SetFDataValue(mapName, keyName string, val []byte)
- func (mod *FactoidModule) Team() marvin.Team
- func (mod *FactoidModule) Tokenize(source string) []Token
- type Function
- type FunctionToken
- type LFDataMap
- type LFactoid
- type OutputFlags
- type ParameterToken
- type TextToken
- type Token
Constants ¶
const BangIdentifier = "factoid-bang"
const (
FactoidNameMaxLen = 75
)
const Identifier = "factoid"
Variables ¶
var DirectiveTokenRgx = regexp.MustCompile(`^{([a-z]+)}`)
var ErrNoSuchFactoid = errors.Errorf("Factoid does not exist")
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
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 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 ¶
func (eas *ElevatedActionSource) Drop() marvin.ActionSource
Drop returns the un-elevated ActionSource.
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) 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 (mod *FactoidModule) CmdForget(t marvin.Team, args *marvin.CommandArguments) marvin.CommandResult
func (*FactoidModule) CmdGet ¶
func (mod *FactoidModule) CmdGet(t marvin.Team, args *marvin.CommandArguments) marvin.CommandResult
func (*FactoidModule) CmdInfo ¶
func (mod *FactoidModule) CmdInfo(t marvin.Team, args *marvin.CommandArguments) marvin.CommandResult
func (*FactoidModule) CmdList ¶
func (mod *FactoidModule) CmdList(t marvin.Team, args *marvin.CommandArguments) marvin.CommandResult
func (*FactoidModule) CmdRemember ¶
func (mod *FactoidModule) CmdRemember(t marvin.Team, args *marvin.CommandArguments) marvin.CommandResult
func (*FactoidModule) CmdSource ¶
func (mod *FactoidModule) CmdSource(t marvin.Team, args *marvin.CommandArguments) marvin.CommandResult
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 (*FactoidModule) GetFactoidHistory ¶
func (*FactoidModule) GetFactoidInfo ¶
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 (*FactoidModule) ListFactoidsWithInfo ¶
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 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 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)
type Token ¶
type Token interface { Run(mod *FactoidModule, args []string, actionSource marvin.ActionSource) (string, error) Source() string }
func NewParameterToken ¶
Pass match[0], match[1], ... match[4]