admin: be quiet

This will not silence any out of band messages such as Untappd checks,
Twitch notifications, or the startup message.

This will cause catbase not to know anything about the conversation,
which means quoting something during the quiet period is impossible.
Everything during quiet time is off the record.
This commit is contained in:
Chris Sexton 2019-01-25 10:04:38 -05:00
parent 2aaf18518a
commit 17afdda35e
1 changed files with 22 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt"
"log"
"strings"
"time"
"github.com/jmoiron/sqlx"
"github.com/velour/catbase/bot"
@ -19,6 +20,8 @@ type AdminPlugin struct {
Bot bot.Bot
db *sqlx.DB
cfg *config.Config
quiet bool
}
// 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 {
body := message.Body
if p.quiet {
return true
}
if len(body) > 0 && body[0] == '$' {
return p.handleVariables(message)
}
@ -52,6 +59,21 @@ func (p *AdminPlugin) Message(message msg.Message) bool {
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, " ")
if parts[0] == "set" && len(parts) > 2 && forbiddenKeys[parts[1]] {
p.Bot.SendMessage(message.Channel, "You cannot access that key")