admin: add setkey

This commit is contained in:
Chris Sexton 2020-04-29 17:36:34 -04:00 committed by Chris Sexton
parent c7810e9f33
commit 1166fc732e
2 changed files with 18 additions and 0 deletions

View File

@ -160,6 +160,14 @@ func (c *Config) Set(key, value string) error {
return nil return nil
} }
func (c *Config) SetMap(key string, values map[string]string) error {
b, err := json.Marshal(values)
if err != nil {
return err
}
return c.Set(key, string(b))
}
func (c *Config) SetArray(key string, values []string) error { func (c *Config) SetArray(key string, values []string) error {
vals := strings.Join(values, ";;") vals := strings.Join(values, ";;")
return c.Set(key, vals) return c.Set(key, vals)

View File

@ -68,6 +68,7 @@ func (p *AdminPlugin) message(conn bot.Connector, k bot.Kind, message msg.Messag
} }
if strings.ToLower(body) == "reboot" { if strings.ToLower(body) == "reboot" {
p.bot.Send(conn, bot.Message, message.Channel, "brb")
log.Info().Msgf("Got reboot command") log.Info().Msgf("Got reboot command")
os.Exit(0) os.Exit(0)
} }
@ -119,6 +120,15 @@ func (p *AdminPlugin) message(conn bot.Connector, k bot.Kind, message msg.Messag
} }
p.bot.Send(conn, bot.Message, message.Channel, fmt.Sprintf("Set %s", parts[1])) p.bot.Send(conn, bot.Message, message.Channel, fmt.Sprintf("Set %s", parts[1]))
return true return true
} else if parts[0] == "setkey" && len(parts) > 3 {
items := p.cfg.GetMap(parts[1], map[string]string{})
items[parts[2]] = strings.Join(parts[3:], " ")
if err := p.cfg.SetMap(parts[1], items); err != nil {
p.bot.Send(conn, bot.Message, message.Channel, fmt.Sprintf("Set error: %s", err))
return true
}
p.bot.Send(conn, bot.Message, message.Channel, fmt.Sprintf("Set %s", parts[1]))
return true
} }
if parts[0] == "get" && len(parts) == 2 && forbiddenKeys[parts[1]] { if parts[0] == "get" && len(parts) == 2 && forbiddenKeys[parts[1]] {