last: add filters for invalid messages

This commit is contained in:
Chris Sexton 2021-04-28 12:07:59 -04:00 committed by Chris Sexton
parent 4c669e520f
commit 19cbf5efd9
1 changed files with 14 additions and 0 deletions

View File

@ -5,6 +5,8 @@ import (
"regexp"
"time"
"github.com/velour/catbase/config"
"github.com/jmoiron/sqlx"
"github.com/rs/zerolog/log"
@ -15,6 +17,7 @@ import (
type LastPlugin struct {
b bot.Bot
db *sqlx.DB
c *config.Config
handlers bot.HandlerTable
channels map[string]bool
@ -98,6 +101,17 @@ func (p *LastPlugin) recordLast(r bot.Request) bool {
}
}
if r.Msg.Body == "" {
return false
}
invalidUsers := p.c.GetArray("last.invalidUsers", []string{"unknown"})
for _, u := range invalidUsers {
if who == u {
return false
}
}
_, err := p.db.Exec(
`insert into last values (?, ?, ?, ?, ?)
on conflict(day) do update set