logmania/bot/main.go

37 lines
626 B
Go
Raw Permalink Normal View History

package bot
import (
2018-09-11 22:57:09 +02:00
"github.com/mattn/go-shellwords"
2019-08-08 15:51:55 +02:00
"dev.sum7.eu/sum7/logmania/database"
)
type Bot struct {
2018-09-11 22:57:09 +02:00
Command
}
func NewBot(db *database.DB) *Bot {
2018-09-11 22:57:09 +02:00
return &Bot{Command{
2019-06-20 10:25:52 +02:00
Description: "logmania bot, to configure live all settings",
2018-09-11 22:57:09 +02:00
Commands: []*Command{
NewFilter(db),
NewHostname(db),
NewPriority(db),
NewReplace(db),
NewSend(db),
},
}}
}
2018-09-11 22:57:09 +02:00
func (b *Bot) Handle(from, msg string) string {
msgParts, err := shellwords.Parse(msg)
if err != nil {
return ""
}
2018-09-11 22:57:09 +02:00
if len(msgParts) <= 0 || msgParts[0][0] != '.' {
return ""
}
2018-09-11 22:57:09 +02:00
msgParts[0] = msgParts[0][1:]
return b.Run(from, msgParts)
}