first/last: filter channels

This commit is contained in:
Chris Sexton 2021-08-26 10:03:22 -04:00 committed by Chris Sexton
parent 9585ac6c23
commit da69df36d4
2 changed files with 24 additions and 1 deletions

View File

@ -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

View File

@ -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())