Let's try something
This commit is contained in:
parent
3670cafaac
commit
da60c15f44
1 changed files with 47 additions and 49 deletions
96
main.go
96
main.go
|
@ -51,56 +51,54 @@ func webhook(update tg.APIUpdate) {
|
|||
return
|
||||
}
|
||||
|
||||
go func() {
|
||||
query := update.Inline.Query
|
||||
offset, _ := strconv.Atoi(update.Inline.Offset)
|
||||
results, err := scryfallSearch(query, offset)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
// DO SOMETHING
|
||||
return
|
||||
}
|
||||
query := update.Inline.Query
|
||||
offset, _ := strconv.Atoi(update.Inline.Offset)
|
||||
results, err := scryfallSearch(query, offset)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
// DO SOMETHING
|
||||
return
|
||||
}
|
||||
|
||||
nextcard := ""
|
||||
if results.HasMore {
|
||||
nextcard = strconv.Itoa(offset + len(results.Data))
|
||||
}
|
||||
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)
|
||||
photos[i] = tg.APIInlineQueryResultPhoto{
|
||||
Type: "photo",
|
||||
ResultID: card.ID,
|
||||
PhotoURL: card.ImageUris.Large,
|
||||
ThumbURL: card.ImageUris.Normal,
|
||||
Title: card.Name,
|
||||
Caption: caption,
|
||||
ReplyMarkup: &tg.APIInlineKeyboardMarkup{
|
||||
InlineKeyboard: [][]tg.APIInlineKeyboardButton{{
|
||||
{
|
||||
Text: "Scryfall",
|
||||
URL: card.ScryfallURI,
|
||||
}, {
|
||||
Text: "EDHREC",
|
||||
URL: card.RelatedUris.Edhrec,
|
||||
}, {
|
||||
Text: "MCM",
|
||||
URL: card.PurchaseUris.Magiccardmarket,
|
||||
},
|
||||
}},
|
||||
},
|
||||
}
|
||||
nextcard := ""
|
||||
if results.HasMore {
|
||||
nextcard = strconv.Itoa(offset + len(results.Data))
|
||||
}
|
||||
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)
|
||||
photos[i] = tg.APIInlineQueryResultPhoto{
|
||||
Type: "photo",
|
||||
ResultID: card.ID,
|
||||
PhotoURL: card.ImageUris.Large,
|
||||
ThumbURL: card.ImageUris.Normal,
|
||||
Title: card.Name,
|
||||
Caption: caption,
|
||||
ReplyMarkup: &tg.APIInlineKeyboardMarkup{
|
||||
InlineKeyboard: [][]tg.APIInlineKeyboardButton{{
|
||||
{
|
||||
Text: "Scryfall",
|
||||
URL: card.ScryfallURI,
|
||||
}, {
|
||||
Text: "EDHREC",
|
||||
URL: card.RelatedUris.Edhrec,
|
||||
}, {
|
||||
Text: "MCM",
|
||||
URL: card.PurchaseUris.Magiccardmarket,
|
||||
},
|
||||
}},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
err = api.AnswerInlineQuery(tg.InlineQueryResponse{
|
||||
QueryID: update.Inline.QueryID,
|
||||
Results: photos,
|
||||
NextOffset: nextcard,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
// DO SOMETHING
|
||||
return
|
||||
}
|
||||
}()
|
||||
err = api.AnswerInlineQuery(tg.InlineQueryResponse{
|
||||
QueryID: update.Inline.QueryID,
|
||||
Results: photos,
|
||||
NextOffset: nextcard,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
// DO SOMETHING
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue