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

25
main.go
View file

@ -96,11 +96,15 @@ func webhook(update tg.APIUpdate) {
if 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{
Type: "photo",
ResultID: card.ID,
PhotoURL: card.ImageUris.Large,
ThumbURL: card.ImageUris.Normal,
PhotoURL: face.Large,
ThumbURL: face.Normal,
Title: card.Name,
Caption: strings.Join(captions, " - "),
Width: 672,
@ -141,10 +145,19 @@ func webhook(update tg.APIUpdate) {
if err != nil {
errlist = append(errlist, cardname)
} else {
cardmedia = append(cardmedia, tg.APIInputMediaPhoto{
Type: "photo",
Media: card.ImageUris.Large,
})
if card.CardFaces != nil {
for _, cardface := range card.CardFaces {
cardmedia = append(cardmedia, tg.APIInputMediaPhoto{
Type: "photo",
Media: cardface.ImageUris.Large,
})
}
} else {
cardmedia = append(cardmedia, tg.APIInputMediaPhoto{
Type: "photo",
Media: card.ImageUris.Large,
})
}
}
}
if len(cardmedia) > 0 {

View file

@ -15,24 +15,31 @@ type CardSearchResults struct {
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 {
ID string `json:"id"`
Name string `json:"name"`
URI string `json:"uri"`
ScryfallURI string `json:"scryfall_uri"`
Layout string `json:"layout"`
HighresImage bool `json:"highres_image"`
ImageUris 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"`
} `json:"image_uris"`
Eur string `json:"eur"`
EdhrecRank *int `json:"edhrec_rank"`
RelatedUris struct {
ID string `json:"id"`
Name string `json:"name"`
URI string `json:"uri"`
ScryfallURI string `json:"scryfall_uri"`
Layout string `json:"layout"`
HighresImage bool `json:"highres_image"`
ImageUris CardImage `json:"image_uris"`
CardFaces []CardFaces `json:"card_faces"`
Eur string `json:"eur"`
EdhrecRank *int `json:"edhrec_rank"`
RelatedUris struct {
Gatherer string `json:"gatherer"`
TcgplayerDecks string `json:"tcgplayer_decks"`
Edhrec string `json:"edhrec"`