added list command

This commit is contained in:
2020-04-02 22:44:19 +00:00
parent 95dc451ab3
commit 075dc26ed3

View File

@ -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