Add logging

This commit is contained in:
Hamcha 2019-08-20 15:04:38 +02:00
parent 514574ef03
commit b140847daa
Signed by: hamcha
GPG key ID: 44AD3571EB09A39E
2 changed files with 12 additions and 0 deletions

View file

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
"log"
"os" "os"
"strconv" "strconv"
"strings" "strings"
@ -18,6 +19,7 @@ type config struct {
WebhookURL string WebhookURL string
WebhookPath string WebhookPath string
MaxRequestsPerMessage int MaxRequestsPerMessage int
Log bool
} }
func checkErr(err error, msg string, args ...interface{}) { func checkErr(err error, msg string, args ...interface{}) {
@ -70,6 +72,9 @@ func webhook(update tg.APIUpdate) {
// DO SOMETHING // DO SOMETHING
return return
} }
if cfg.Log {
log.Printf(" -> %d cards", len(results.Data))
}
photos := make([]tg.APIInlineQueryResultPhoto, len(results.Data)) photos := make([]tg.APIInlineQueryResultPhoto, len(results.Data))
for i, card := range results.Data { for i, card := range results.Data {
@ -118,6 +123,9 @@ func webhook(update tg.APIUpdate) {
if err != nil { if err != nil {
errlist = append(errlist, cardname) errlist = append(errlist, cardname)
} else { } else {
if cfg.Log {
log.Printf(" -> %d cards", len(cards.Data))
}
for _, card := range cards.Data { for _, card := range cards.Data {
face, _, _ := getCardEntry(card, 0) face, _, _ := getCardEntry(card, 0)
cardmedia = append(cardmedia, tg.APIInputMediaPhoto{ cardmedia = append(cardmedia, tg.APIInputMediaPhoto{

View file

@ -4,6 +4,7 @@ import (
"crypto/tls" "crypto/tls"
"encoding/json" "encoding/json"
"fmt" "fmt"
"log"
"net/http" "net/http"
"net/url" "net/url"
"time" "time"
@ -35,6 +36,9 @@ var netClient = &http.Client{
func mlpapiSearch(query string) (results CardSearchResults, err error) { func mlpapiSearch(query string) (results CardSearchResults, err error) {
query = url.QueryEscape(query) query = url.QueryEscape(query)
requrl := fmt.Sprintf("https://www.ferrictorus.com/mlpapi1/cards?query=%s", query) requrl := fmt.Sprintf("https://www.ferrictorus.com/mlpapi1/cards?query=%s", query)
if cfg.Log {
log.Println(requrl)
}
response, err := netClient.Get(requrl) response, err := netClient.Get(requrl)
if err != nil { if err != nil {
return return