mirror of https://github.com/velour/catbase.git
admin: add setkey
This commit is contained in:
parent
c7810e9f33
commit
1166fc732e
|
@ -160,6 +160,14 @@ func (c *Config) Set(key, value string) error {
|
|||
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 {
|
||||
vals := strings.Join(values, ";;")
|
||||
return c.Set(key, vals)
|
||||
|
|
|
@ -68,6 +68,7 @@ func (p *AdminPlugin) message(conn bot.Connector, k bot.Kind, message msg.Messag
|
|||
}
|
||||
|
||||
if strings.ToLower(body) == "reboot" {
|
||||
p.bot.Send(conn, bot.Message, message.Channel, "brb")
|
||||
log.Info().Msgf("Got reboot command")
|
||||
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]))
|
||||
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]] {
|
||||
|
|
Loading…
Reference in New Issue