Add logging
This commit is contained in:
parent
514574ef03
commit
b140847daa
2 changed files with 12 additions and 0 deletions
8
main.go
8
main.go
|
@ -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{
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue