logmania/bot/main.go

37 lines
632 B
Go
Raw Normal View History

package bot
import (
2018-09-11 22:57:09 +02:00
"github.com/mattn/go-shellwords"
"dev.sum7.eu/genofire/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{
Description: "logmania bot, to configurate live all settings",
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)
}