Compare commits

...

2 Commits

Author SHA1 Message Date
Chris Sexton 802911203f last: fix crash 2021-04-28 12:52:32 -04:00
Chris Sexton 19cbf5efd9 last: add filters for invalid messages 2021-04-28 12:15:09 -04:00
1 changed files with 15 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
@ -24,6 +27,7 @@ func New(b bot.Bot) *LastPlugin {
p := &LastPlugin{
b: b,
db: b.DB(),
c: b.Config(),
channels: map[string]bool{},
}
if err := p.migrate(); err != nil {
@ -98,6 +102,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