Browse Source

added list command

master
David Haukeness 5 years ago
parent
commit
075dc26ed3
No known key found for this signature in database
GPG Key ID: 54F2372DDB7F9462
  1. 23
      commands.go

23
commands.go

@ -1,9 +1,11 @@
package main package main
import ( import (
"bytes"
"fmt" "fmt"
"net/url" "net/url"
"strings" "strings"
"text/tabwriter"
"samhofi.us/x/keybase/types/chat1" "samhofi.us/x/keybase/types/chat1"
) )
@ -175,7 +177,26 @@ func (b *bot) handleConfigList(m chat1.MsgSummary) {
if args[2] != "list" { if args[2] != "list" {
return return
} }
b.debug("config list called by @%s in %s", m.Sender.Username, m.ConvID) // get the ConvOptions
var opts ConvOptions
err := b.KVStoreGetStruct(m.ConvID, &opts)
if err != nil {
eid := b.logError(err)
b.k.ReactByConvID(m.ConvID, m.Id, "Error ID %s", eid)
return
}
// then reflect the struct to a list
configOpts := structToSlice(opts)
// Then iterate those through a tabWriter
var buf bytes.Buffer
w := tabwriter.NewWriter(&buf, 0, 0, 3, ' ', 0)
fmt.Fprintln(w, "Config Options for this channel:\n```")
for _, opt := range configOpts {
fmt.Fprintf(w, "%s\t%v\t\n", opt.Name, opt.Value)
}
fmt.Fprintln(w, "```")
w.Flush()
b.k.ReplyByConvID(m.ConvID, m.Id, buf.String())
} }
// handleConfigHelp shows config help // handleConfigHelp shows config help

Loading…
Cancel
Save