mirror of https://github.com/velour/catbase.git
commit
e161e9fece
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/velour/catbase/bot"
|
"github.com/velour/catbase/bot"
|
||||||
|
@ -19,6 +20,8 @@ type AdminPlugin struct {
|
||||||
Bot bot.Bot
|
Bot bot.Bot
|
||||||
db *sqlx.DB
|
db *sqlx.DB
|
||||||
cfg *config.Config
|
cfg *config.Config
|
||||||
|
|
||||||
|
quiet bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAdminPlugin creates a new AdminPlugin with the Plugin interface
|
// NewAdminPlugin creates a new AdminPlugin with the Plugin interface
|
||||||
|
@ -44,6 +47,10 @@ var forbiddenKeys = map[string]bool{
|
||||||
func (p *AdminPlugin) Message(message msg.Message) bool {
|
func (p *AdminPlugin) Message(message msg.Message) bool {
|
||||||
body := message.Body
|
body := message.Body
|
||||||
|
|
||||||
|
if p.quiet {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
if len(body) > 0 && body[0] == '$' {
|
if len(body) > 0 && body[0] == '$' {
|
||||||
return p.handleVariables(message)
|
return p.handleVariables(message)
|
||||||
}
|
}
|
||||||
|
@ -52,6 +59,21 @@ func (p *AdminPlugin) Message(message msg.Message) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.ToLower(body) == "shut up" {
|
||||||
|
dur := time.Duration(p.cfg.GetInt("quietDuration", 5)) * time.Minute
|
||||||
|
log.Printf("Going to sleep for %v, %v", dur, time.Now().Add(dur))
|
||||||
|
p.Bot.SendMessage(message.Channel, "Okay. I'll be back later.")
|
||||||
|
p.quiet = true
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-time.After(dur):
|
||||||
|
p.quiet = false
|
||||||
|
log.Println("Waking up from nap.")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
parts := strings.Split(body, " ")
|
parts := strings.Split(body, " ")
|
||||||
if parts[0] == "set" && len(parts) > 2 && forbiddenKeys[parts[1]] {
|
if parts[0] == "set" && len(parts) > 2 && forbiddenKeys[parts[1]] {
|
||||||
p.Bot.SendMessage(message.Channel, "You cannot access that key")
|
p.Bot.SendMessage(message.Channel, "You cannot access that key")
|
||||||
|
|
Loading…
Reference in New Issue