From a2d2189585934bcdc67b47c30a52175277ed98ce Mon Sep 17 00:00:00 2001 From: Hamcha Date: Thu, 13 Dec 2018 11:22:10 +0100 Subject: [PATCH] Fix for tg api change AND scryfall api change --- main.go | 42 ++++++++++++++++++++++++++++-------------- scryfall.go | 18 +++++++++--------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/main.go b/main.go index aff04b9..c94c146 100644 --- a/main.go +++ b/main.go @@ -70,29 +70,43 @@ func webhook(update tg.APIUpdate) { } photos := make([]tg.APIInlineQueryResultPhoto, len(results.Data)) for i, card := range results.Data { - caption := fmt.Sprintf("EDHREC rank: #%d - cardmarket: € %s", card.EdhrecRank, card.Eur) + buttons := []tg.APIInlineKeyboardButton{ + { + Text: "Scryfall", + URL: card.ScryfallURI, + }, + } + if card.RelatedUris.Edhrec != "" { + buttons = append(buttons, tg.APIInlineKeyboardButton{ + Text: "EDHREC", + URL: card.RelatedUris.Edhrec, + }) + } + if card.PurchaseUris.Cardmarket != "" { + buttons = append(buttons, tg.APIInlineKeyboardButton{ + Text: "MCM", + URL: card.PurchaseUris.Cardmarket, + }) + } + + captions := []string{} + if card.EdhrecRank != nil { + captions = append(captions, fmt.Sprintf("EDHREC rank: #%d", *card.EdhrecRank)) + } + if card.Eur != "" { + captions = append(captions, fmt.Sprintf("cardmarket: € %s", card.Eur)) + } photos[i] = tg.APIInlineQueryResultPhoto{ Type: "photo", ResultID: card.ID, PhotoURL: card.ImageUris.Large, ThumbURL: card.ImageUris.Normal, Title: card.Name, - Caption: caption, + Caption: strings.Join(captions, " - "), Width: 672, Height: 936, ReplyMarkup: &tg.APIInlineKeyboardMarkup{ - InlineKeyboard: [][]tg.APIInlineKeyboardButton{{ - { - Text: "Scryfall", - URL: card.ScryfallURI, - }, { - Text: "EDHREC", - URL: card.RelatedUris.Edhrec, - }, { - Text: "MCM", - URL: card.PurchaseUris.Magiccardmarket, - }, - }}, + InlineKeyboard: [][]tg.APIInlineKeyboardButton{buttons}, }, } } diff --git a/scryfall.go b/scryfall.go index 7b365f4..21a7326 100644 --- a/scryfall.go +++ b/scryfall.go @@ -31,7 +31,7 @@ type CardData struct { BorderCrop string `json:"border_crop"` } `json:"image_uris"` Eur string `json:"eur"` - EdhrecRank int `json:"edhrec_rank"` + EdhrecRank *int `json:"edhrec_rank"` RelatedUris struct { Gatherer string `json:"gatherer"` TcgplayerDecks string `json:"tcgplayer_decks"` @@ -39,14 +39,14 @@ type CardData struct { Mtgtop8 string `json:"mtgtop8"` } `json:"related_uris"` PurchaseUris struct { - Amazon string `json:"amazon"` - Ebay string `json:"ebay"` - Tcgplayer string `json:"tcgplayer"` - Magiccardmarket string `json:"magiccardmarket"` - Cardhoarder string `json:"cardhoarder"` - CardKingdom string `json:"card_kingdom"` - MtgoTraders string `json:"mtgo_traders"` - Coolstuffinc string `json:"coolstuffinc"` + Amazon string `json:"amazon"` + Ebay string `json:"ebay"` + Tcgplayer string `json:"tcgplayer"` + Cardmarket string `json:"cardmarket"` + Cardhoarder string `json:"cardhoarder"` + CardKingdom string `json:"card_kingdom"` + MtgoTraders string `json:"mtgo_traders"` + Coolstuffinc string `json:"coolstuffinc"` } `json:"purchase_uris"` }