From 5cb6f9ad7e9cc47eff264a848509d0e16c55eaf9 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sat, 28 Sep 2019 13:14:15 -0400 Subject: [PATCH 1/2] untappd: add badge support Note: this may not work on the first try. I'm not going to sit around waiting for a badged checkin in #test. --- plugins/beers/beers.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugins/beers/beers.go b/plugins/beers/beers.go index 8b818fb..cf58fd9 100644 --- a/plugins/beers/beers.go +++ b/plugins/beers/beers.go @@ -287,6 +287,14 @@ type checkin struct { } } } + Badges struct { + Count int + Items []struct { + BadgeName string `json:"badge_name"` + BadgeDescription string `json:"badge_description"` + BadgeImage string `json:"badge_image"` + } + } } type mrUntappd struct { @@ -421,6 +429,16 @@ func (p *BeersPlugin) checkUntappd(c bot.Connector, channel string) { AltTxt: "Here's a photo", }) } + if checkin.Badges.Count > 0 { + msg = msg + "\nThis checkin earned the following badge(s): " + for _, b := range checkin.Badges.Items { + msg = msg + b.BadgeName + args = append(args, bot.ImageAttachment{ + URL: b.BadgeImage, + AltTxt: b.BadgeDescription, + }) + } + } user.lastCheckin = checkin.Checkin_id _, err := p.db.Exec(`update untappd set From 267ec1a8bfbb9fe5a198a7bbc0d2d7ff614455cd Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sat, 28 Sep 2019 13:18:23 -0400 Subject: [PATCH 2/2] untappd: split badge between msg and images --- plugins/beers/beers.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/beers/beers.go b/plugins/beers/beers.go index cf58fd9..951b28b 100644 --- a/plugins/beers/beers.go +++ b/plugins/beers/beers.go @@ -415,6 +415,12 @@ func (p *BeersPlugin) checkUntappd(c bot.Connector, channel string) { msg = fmt.Sprintf("%s -- %s", msg, checkin.Checkin_comment) } + if checkin.Badges.Count > 0 { + msg = msg + "\nThis checkin earned the following badge(s): " + for _, b := range checkin.Badges.Items { + msg = msg + b.BadgeName + } + } args := []interface{}{ channel, @@ -430,9 +436,7 @@ func (p *BeersPlugin) checkUntappd(c bot.Connector, channel string) { }) } if checkin.Badges.Count > 0 { - msg = msg + "\nThis checkin earned the following badge(s): " for _, b := range checkin.Badges.Items { - msg = msg + b.BadgeName args = append(args, bot.ImageAttachment{ URL: b.BadgeImage, AltTxt: b.BadgeDescription,