From da69df36d4bde3df38a9d66a50c94dfd3757d7a7 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Thu, 26 Aug 2021 10:03:22 -0400 Subject: [PATCH] first/last: filter channels --- plugins/first/first.go | 12 +++++++++++- plugins/last/last.go | 13 +++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/plugins/first/first.go b/plugins/first/first.go index 8839808..d9756d1 100644 --- a/plugins/first/first.go +++ b/plugins/first/first.go @@ -211,7 +211,7 @@ func (p *FirstPlugin) register() { {Kind: bot.Message, IsCmd: false, Regex: regexp.MustCompile(`.*`), Handler: func(r bot.Request) bool { - if r.Msg.IsIM || !p.enabled { + if r.Msg.IsIM || !p.enabled || !p.enabled_channel(r) { return false } @@ -243,6 +243,16 @@ func (p *FirstPlugin) register() { p.bot.RegisterTable(p, p.handlers) } +func (p *FirstPlugin) enabled_channel(r bot.Request) bool { + chs := p.config.GetArray("first.channels", []string{}) + for _, ch := range chs { + if r.Msg.Channel == ch { + return true + } + } + return false +} + func (p *FirstPlugin) allowed(message msg.Message) bool { if message.Body == "" { return false diff --git a/plugins/last/last.go b/plugins/last/last.go index 4bb265b..7c0946a 100644 --- a/plugins/last/last.go +++ b/plugins/last/last.go @@ -81,6 +81,16 @@ func (p *LastPlugin) register() { p.b.RegisterTable(p, p.handlers) } +func (p *LastPlugin) enabled_channel(r bot.Request) bool { + chs := p.c.GetArray("last.channels", []string{}) + for _, ch := range chs { + if r.Msg.Channel == ch { + return true + } + } + return false +} + func nextNoon(t time.Time) time.Duration { day := first.Midnight(t) nextNoon := day.Add(12 * time.Hour) @@ -97,6 +107,9 @@ func nextNoon(t time.Time) time.Duration { } func (p *LastPlugin) recordLast(r bot.Request) bool { + if !p.enabled_channel(r) { + return false + } ch := r.Msg.Channel who := r.Msg.User.Name day := first.Midnight(time.Now())