diff options
Diffstat (limited to 'telegram/commands.go')
-rw-r--r-- | telegram/commands.go | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/telegram/commands.go b/telegram/commands.go index c0fe05f..d3a8ea7 100644 --- a/telegram/commands.go +++ b/telegram/commands.go @@ -1,6 +1,7 @@ package telegram import ( + "fmt" "github.com/pkg/errors" "strconv" "strings" @@ -22,7 +23,7 @@ var transportCommands = map[string]command{ "setname": command{"first last", "update name"}, "setbio": command{"", "update about"}, "setpassword": command{"[old] [new]", "set or remove password"}, - //"config": command{"[param] [value]", "view or update configuration options"}, + "config": command{"[param] [value]", "view or update configuration options"}, } var chatCommands = map[string]command{ @@ -209,6 +210,29 @@ func (c *Client) ProcessTransportCommand(cmdline string) string { if err != nil { return errors.Wrap(err, "Couldn't set password").Error() } + case "config": + if len(args) > 1 { + value, err := c.Session.Set(args[0], args[1]) + if err != nil { + return err.Error() + } + + return fmt.Sprintf("%s set to %s", args[0], value) + } else if len(args) > 0 { + value, err := c.Session.Get(args[0]) + if err != nil { + return err.Error() + } + + return fmt.Sprintf("%s is set to %s", args[0], value) + } + + var entries []string + for key, value := range c.Session.ToMap() { + entries = append(entries, fmt.Sprintf("%s is set to %s", key, value)) + } + + return strings.Join(entries, "\n") case "help": return helpString(helpTypeTransport) } |