logmania/bot/priority.go

83 lines
1.9 KiB
Go
Raw Normal View History

2018-09-11 22:57:09 +02:00
package bot
import (
"fmt"
2019-06-20 09:25:43 +02:00
"github.com/bdlm/log"
logstd "github.com/bdlm/std/logger"
2018-09-11 22:57:09 +02:00
"dev.sum7.eu/genofire/logmania/database"
)
func NewPriority(db *database.DB) *Command {
return &Command{
Name: "priority",
2019-06-20 10:25:52 +02:00
Description: "list and configure priority in channel",
2018-09-11 22:57:09 +02:00
Commands: []*Command{
2018-11-06 00:52:45 +01:00
{
2018-09-11 22:57:09 +02:00
Name: "set",
Description: "set max priority of channel: [channel] Priority",
Action: func(from string, params []string) string {
if len(params) < 1 {
return "invalid: [channel] Priority"
}
to := from
2019-06-20 09:25:43 +02:00
var max logstd.Level
2018-09-11 22:57:09 +02:00
var err error
if len(params) > 1 {
to = params[0]
max, err = log.ParseLevel(params[1])
} else {
max, err = log.ParseLevel(params[0])
}
if err != nil {
return "invalid: [Channel] Priority"
}
n, ok := db.NotifiesByAddress[to]
if !ok {
n = db.NewNotify(to)
}
n.MaxPrioIn = max
2019-06-20 10:37:39 +02:00
return fmt.Sprintf("set filter for %s to %d", to, max)
2018-09-11 22:57:09 +02:00
},
},
2018-11-06 00:52:45 +01:00
{
2018-09-11 22:57:09 +02:00
Name: "all",
Description: "list of all channels",
Action: func(from string, params []string) string {
msg := "priority: \n"
for _, n := range db.Notifies {
2019-06-20 10:37:39 +02:00
msg = fmt.Sprintf("%s%s - %d\n", msg, n.Address(), n.MaxPrioIn)
2018-09-11 22:57:09 +02:00
}
return msg
},
},
2018-11-06 00:52:45 +01:00
{
2018-09-11 22:57:09 +02:00
Name: "channel",
Description: "list of given channel: channel",
Action: func(from string, params []string) string {
if len(params) != 1 {
return "invalid: no channel given"
}
of := params[0]
msg := "priority: \n"
if notify, ok := db.NotifiesByAddress[of]; ok {
2019-06-20 10:37:39 +02:00
msg = fmt.Sprintf("%s %s is %d", msg, of, notify.MaxPrioIn)
2018-09-11 22:57:09 +02:00
}
return msg
},
},
},
Action: func(from string, params []string) string {
msg := "priority: \n"
if notify, ok := db.NotifiesByAddress[from]; ok {
2019-06-20 10:37:39 +02:00
msg = fmt.Sprintf("%s %s is %d", msg, from, notify.MaxPrioIn)
2018-09-11 22:57:09 +02:00
}
return msg
},
}
}