Fix for double face cards

This commit is contained in:
Hamcha 2018-12-13 12:01:24 +01:00
parent a2d2189585
commit 7f97c3144b
Signed by: hamcha
GPG key ID: A40413D21021EAEE
2 changed files with 43 additions and 23 deletions

17
main.go
View file

@ -96,11 +96,15 @@ func webhook(update tg.APIUpdate) {
if card.Eur != "" { if card.Eur != "" {
captions = append(captions, fmt.Sprintf("cardmarket: € %s", card.Eur)) captions = append(captions, fmt.Sprintf("cardmarket: € %s", card.Eur))
} }
face := card.ImageUris
if card.CardFaces != nil {
face = card.CardFaces[0].ImageUris
}
photos[i] = tg.APIInlineQueryResultPhoto{ photos[i] = tg.APIInlineQueryResultPhoto{
Type: "photo", Type: "photo",
ResultID: card.ID, ResultID: card.ID,
PhotoURL: card.ImageUris.Large, PhotoURL: face.Large,
ThumbURL: card.ImageUris.Normal, ThumbURL: face.Normal,
Title: card.Name, Title: card.Name,
Caption: strings.Join(captions, " - "), Caption: strings.Join(captions, " - "),
Width: 672, Width: 672,
@ -140,6 +144,14 @@ func webhook(update tg.APIUpdate) {
card, err := scryfallGetCard(cardname) card, err := scryfallGetCard(cardname)
if err != nil { if err != nil {
errlist = append(errlist, cardname) errlist = append(errlist, cardname)
} else {
if card.CardFaces != nil {
for _, cardface := range card.CardFaces {
cardmedia = append(cardmedia, tg.APIInputMediaPhoto{
Type: "photo",
Media: cardface.ImageUris.Large,
})
}
} else { } else {
cardmedia = append(cardmedia, tg.APIInputMediaPhoto{ cardmedia = append(cardmedia, tg.APIInputMediaPhoto{
Type: "photo", Type: "photo",
@ -147,6 +159,7 @@ func webhook(update tg.APIUpdate) {
}) })
} }
} }
}
if len(cardmedia) > 0 { if len(cardmedia) > 0 {
api.SendAlbum(tg.ClientAlbumData{ api.SendAlbum(tg.ClientAlbumData{
ChatID: update.Message.Chat.ChatID, ChatID: update.Message.Chat.ChatID,

View file

@ -15,6 +15,19 @@ type CardSearchResults struct {
NextPage string `json:"next_page"` NextPage string `json:"next_page"`
} }
type CardImage struct {
Small string `json:"small"`
Normal string `json:"normal"`
Large string `json:"large"`
Png string `json:"png"`
ArtCrop string `json:"art_crop"`
BorderCrop string `json:"border_crop"`
}
type CardFaces struct {
ImageUris CardImage `json:"image_uris"`
}
type CardData struct { type CardData struct {
ID string `json:"id"` ID string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
@ -22,14 +35,8 @@ type CardData struct {
ScryfallURI string `json:"scryfall_uri"` ScryfallURI string `json:"scryfall_uri"`
Layout string `json:"layout"` Layout string `json:"layout"`
HighresImage bool `json:"highres_image"` HighresImage bool `json:"highres_image"`
ImageUris struct { ImageUris CardImage `json:"image_uris"`
Small string `json:"small"` CardFaces []CardFaces `json:"card_faces"`
Normal string `json:"normal"`
Large string `json:"large"`
Png string `json:"png"`
ArtCrop string `json:"art_crop"`
BorderCrop string `json:"border_crop"`
} `json:"image_uris"`
Eur string `json:"eur"` Eur string `json:"eur"`
EdhrecRank *int `json:"edhrec_rank"` EdhrecRank *int `json:"edhrec_rank"`
RelatedUris struct { RelatedUris struct {