|
|
|
package keybase
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os/exec"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Options holds... run... options...
|
|
|
|
type Options struct {
|
|
|
|
// Optional, but required if keybase is not in your path
|
|
|
|
KeybaseLocation string
|
|
|
|
|
|
|
|
// Only use this if you know what you're doing
|
|
|
|
HomeDir string
|
|
|
|
|
|
|
|
// Show others a typing notification while the bot is working on a command
|
|
|
|
EnableTyping bool
|
|
|
|
|
|
|
|
// Turn off Keybase's 'bot lite' mode. Only disable if you need to.
|
|
|
|
DisableLiteMode bool
|
|
|
|
|
|
|
|
// The size of the channel buffers, may vary on rate of message ingestion
|
|
|
|
ChannelBufferSize int
|
|
|
|
}
|
|
|
|
|
|
|
|
// locateKeybase attempts to find the location of the keybase binary using the system PATH
|
|
|
|
func locateKeybase() (string, error) {
|
|
|
|
path, err := exec.LookPath("keybase")
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("could not determine path for keybase binary: %v", err)
|
|
|
|
}
|
|
|
|
return path, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// buildArgs adds the homedirectory before the args, when required
|
|
|
|
func buildArgs(opts Options, args ...string) ([]string, error) {
|
|
|
|
if len(args) == 0 {
|
|
|
|
return nil, fmt.Errorf("no arguments")
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialize slice so we never return a nil object
|
|
|
|
cmd := make([]string, 0)
|
|
|
|
if opts.HomeDir != "" {
|
|
|
|
cmd = append(cmd, "--home", opts.HomeDir)
|
|
|
|
}
|
|
|
|
if !opts.DisableLiteMode {
|
|
|
|
cmd = append(cmd, "--enable-bot-lite-mode")
|
|
|
|
}
|
|
|
|
cmd = append(cmd, args...)
|
|
|
|
|
|
|
|
return cmd, nil
|
|
|
|
}
|