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
|
|
|
|
2019-08-08 15:51:55 +02:00
|
|
|
"dev.sum7.eu/sum7/logmania/database"
|
2018-09-11 22:57:09 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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-21 00:46:35 +02:00
|
|
|
return fmt.Sprintf("set filter for %s to %s", to, log.LevelString(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-21 00:46:35 +02:00
|
|
|
msg = fmt.Sprintf("%s%s - %s\n", msg, n.Address(), log.LevelString(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-21 00:46:35 +02:00
|
|
|
msg = fmt.Sprintf("%s %s is %s", msg, of, log.LevelString(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-21 00:46:35 +02:00
|
|
|
msg = fmt.Sprintf("%s %s is %s", msg, from, log.LevelString(notify.MaxPrioIn))
|
2018-09-11 22:57:09 +02:00
|
|
|
}
|
|
|
|
return msg
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|