You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.6 KiB
52 lines
1.6 KiB
package keybase |
|
|
|
import ( |
|
"log" |
|
"os/exec" |
|
) |
|
|
|
// Options holds... run... options... |
|
type Options struct { |
|
KeybaseLoction string // Optional, but required if keybase is not in your path |
|
HomeDir string // Only use this if you know what you're doing |
|
EnableTyping bool // Show others a typing notification while the bot is working on a command |
|
BotLiteMode bool // Defaults to true - only disable if you need to. |
|
ChannelBufferSize int // The size of the channel buffers, may vary on rate of message ingestion |
|
} |
|
|
|
// NewOptions returns a new instance of *Options with sensible defaults |
|
func NewOptions() *Options { |
|
return &Options{ |
|
BotLiteMode: true, |
|
ChannelBufferSize: 10, |
|
} |
|
} |
|
|
|
// locateKeybase attempts to find the location of the keybase binary in the following order: |
|
// 1. What the user has specified as the location [user specified] |
|
// 2. Looks up the binary location using exec.LookPath [default] |
|
// 3. Returns "keybase" and hopes its pathed on the users system [fallback] |
|
func (opt *Options) locateKeybase() string { |
|
if opt.KeybaseLoction != "" { |
|
return opt.KeybaseLoction |
|
} |
|
path, err := exec.LookPath("keybase") |
|
if err != nil { |
|
log.Println("INFO: Could not detect keybase in path") |
|
return "keybase" |
|
} |
|
return path |
|
} |
|
|
|
// buildBaseCommand adds the homedirectory before the args, when required |
|
func (opt *Options) buildArgs(args ...string) []string { |
|
var cmd []string |
|
if opt.HomeDir != "" { |
|
cmd = append(cmd, "--home", opt.HomeDir) |
|
} |
|
if opt.BotLiteMode { |
|
cmd = append(cmd, "--enable-bot-lite-mode") |
|
} |
|
cmd = append(cmd, args...) |
|
return cmd |
|
}
|
|
|