Merge pull request #203 from velour/badges

untappd: add badge support
This commit is contained in:
Chris Sexton 2019-09-28 13:22:58 -04:00 committed by GitHub
commit 38c83ba5e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 0 deletions

View File

@ -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 { type mrUntappd struct {
@ -407,6 +415,12 @@ func (p *BeersPlugin) checkUntappd(c bot.Connector, channel string) {
msg = fmt.Sprintf("%s -- %s", msg = fmt.Sprintf("%s -- %s",
msg, checkin.Checkin_comment) 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{}{ args := []interface{}{
channel, channel,
@ -421,6 +435,14 @@ func (p *BeersPlugin) checkUntappd(c bot.Connector, channel string) {
AltTxt: "Here's a photo", AltTxt: "Here's a photo",
}) })
} }
if checkin.Badges.Count > 0 {
for _, b := range checkin.Badges.Items {
args = append(args, bot.ImageAttachment{
URL: b.BadgeImage,
AltTxt: b.BadgeDescription,
})
}
}
user.lastCheckin = checkin.Checkin_id user.lastCheckin = checkin.Checkin_id
_, err := p.db.Exec(`update untappd set _, err := p.db.Exec(`update untappd set