zork: make path to exec and dat configurable

zork: squash pkgPath err

zork: add flag support
This commit is contained in:
Chris Sexton 2019-10-01 14:01:02 -04:00
parent 6ebc476456
commit 4fd0683a8d
1 changed files with 9 additions and 4 deletions

View File

@ -39,12 +39,17 @@ func New(b bot.Bot) bot.Plugin {
func (p *ZorkPlugin) runZork(c bot.Connector, ch string) error { func (p *ZorkPlugin) runZork(c bot.Connector, ch string) error {
const importString = "github.com/velour/catbase/plugins/zork" const importString = "github.com/velour/catbase/plugins/zork"
pkgPath := ""
pkg, err := build.Import(importString, "", build.FindOnly) pkg, err := build.Import(importString, "", build.FindOnly)
if err != nil { if err == nil {
return err pkgPath = pkg.Dir
} }
zorkdat := filepath.Join(pkg.Dir, "ZORK1.DAT") zorkPath := p.bot.Config().GetString("zork.path", pkgPath)
cmd := exec.Command("dfrotz", zorkdat) zorkdat := filepath.Join(zorkPath, "ZORK1.DAT")
zorkFlags := p.bot.Config().GetArray("zork.args", []string{"-p"})
zorkExec := p.bot.Config().GetString("zork.binary", "frotz")
zorkFlags = append(zorkFlags, zorkdat)
cmd := exec.Command(zorkExec, zorkFlags...)
var r io.ReadCloser var r io.ReadCloser
r, cmd.Stdout = io.Pipe() r, cmd.Stdout = io.Pipe()