untappd: defer checkins without media

This commit is contained in:
Chris Sexton 2020-05-04 13:35:31 -04:00 committed by Chris Sexton
parent 07c4950b2d
commit d7b0bed0db
1 changed files with 13 additions and 0 deletions

View File

@ -15,6 +15,7 @@ import (
"github.com/jmoiron/sqlx"
"github.com/rs/zerolog/log"
"github.com/velour/catbase/bot"
"github.com/velour/catbase/bot/msg"
"github.com/velour/catbase/plugins/counter"
@ -27,6 +28,8 @@ const itemName = ":beer:"
type BeersPlugin struct {
Bot bot.Bot
db *sqlx.DB
untapdCache map[int]bool
}
type untappdUser struct {
@ -51,6 +54,8 @@ func New(b bot.Bot) *BeersPlugin {
p := &BeersPlugin{
Bot: b,
db: b.DB(),
untapdCache: make(map[int]bool),
}
for _, channel := range b.Config().GetArray("Untappd.Channels", []string{}) {
go p.untappdLoop(b.DefaultConnector(), channel)
@ -440,6 +445,14 @@ func (p *BeersPlugin) checkUntappd(c bot.Connector, channel string) {
URL: checkin.Media.Items[0].Photo.Photo_img_lg,
AltTxt: "Here's a photo",
})
} else if !p.untapdCache[checkin.Checkin_id] {
// Mark checkin as "seen" but not complete, continue to next checkin
log.Debug().Msgf("Deferring checkin: %#v", checkin)
p.untapdCache[checkin.Checkin_id] = true
continue
} else {
// We've seen this checkin, so unmark and accept that there's no media
delete(p.untapdCache, checkin.Checkin_id)
}
user.lastCheckin = checkin.Checkin_id