2017-08-11 17:45:42 +02:00
|
|
|
package bot
|
|
|
|
|
|
|
|
import (
|
2018-09-11 22:57:09 +02:00
|
|
|
"github.com/mattn/go-shellwords"
|
2017-08-11 17:45:42 +02:00
|
|
|
|
2018-04-13 16:44:23 +02:00
|
|
|
"dev.sum7.eu/genofire/logmania/database"
|
2017-08-11 17:45:42 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Bot struct {
|
2018-09-11 22:57:09 +02:00
|
|
|
Command
|
2017-08-11 17:45:42 +02:00
|
|
|
}
|
|
|
|
|
2017-11-10 18:57:36 +01:00
|
|
|
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),
|
|
|
|
},
|
|
|
|
}}
|
2017-08-11 17:45:42 +02:00
|
|
|
}
|
|
|
|
|
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 ""
|
2017-08-11 17:45:42 +02:00
|
|
|
}
|
2018-09-11 22:57:09 +02:00
|
|
|
if len(msgParts) <= 0 || msgParts[0][0] != '.' {
|
|
|
|
return ""
|
2017-08-11 17:45:42 +02:00
|
|
|
}
|
2018-09-11 22:57:09 +02:00
|
|
|
msgParts[0] = msgParts[0][1:]
|
|
|
|
return b.Run(from, msgParts)
|
2017-08-11 17:45:42 +02:00
|
|
|
}
|