From 17afdda35ee0ffe2a46a3b9814e5b56fbedb9133 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Fri, 25 Jan 2019 10:04:38 -0500 Subject: [PATCH] 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. --- plugins/admin/admin.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/plugins/admin/admin.go b/plugins/admin/admin.go index 50049b3..a7e45c8 100644 --- a/plugins/admin/admin.go +++ b/plugins/admin/admin.go @@ -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")