twitchapon

[Twi]tch [Cha]nnel [Po]ints Rewards Redemption Listener
git clone git://bsandro.tech/twitchapon
Log | Files | Refs | README | LICENSE

commit d19ed541751ea2a5a17913af3f5db44281bfab62
parent 7d9710b9b98a9c52ca5fb3a829d971a0f324738c
Author: bsandro <brian.drosan@gmail.com>
Date:   Sun,  9 May 2021 06:06:10 +0300

Removed debug stdout messages

Diffstat:
ATODO | 12++++++++++++
Mauth.go | 5+----
Mclient.go | 2--
Mlisten.go | 4----
Mlocal_server.go | 4----
Mping.go | 2--
Muser.go | 2--
7 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/TODO b/TODO @@ -0,0 +1,12 @@ +Brief TODO list of features to implement. +Symbols as I use them: "-" is "planned", "?" is "questionable", "+" is "done" + +- unmarshal nested json received in messages and forward it properly +- cache authorization token till it expires +- authorization token renewal process +- handle reconnections properly +- request info about user from received event, cache and forward it further +- global feature: listen to bits and channel subscription events +? open system default browser with an oauth link instead of just printing its +- delay between ping messages should be configurable +- put some comments into code diff --git a/auth.go b/auth.go @@ -28,15 +28,12 @@ func (auth *TAuth) Init(auth_code string) error { if err != nil { return err } - fmt.Println("Auth response:", string(body)) if err := json.Unmarshal(body, auth); err != nil { return err } - fmt.Println("Auth response parsed:", auth) + if len(auth.AccessToken) == 0 { - fmt.Println("no access token") if len(auth.Message) > 0 { - fmt.Println("msg:", auth.Message) return errors.New(auth.Message) } else { return errors.New("Auth error") diff --git a/client.go b/client.go @@ -23,12 +23,10 @@ func ListenJob() { if err := websocket.JSON.Receive(App.Connection, &msg); err != nil { log.Fatal(err) } - fmt.Println("Received message:", msg) // ignore PING and RESPONSE for now if msg.Type != "MESSAGE" { continue } - fmt.Println("App.Config.AnimServer:", App.Config.AnimServer) if resp, err := http.Get(App.Config.AnimServer); err == nil { resp.Body.Close() } else { diff --git a/listen.go b/listen.go @@ -1,7 +1,6 @@ package main import ( - "encoding/json" "fmt" "golang.org/x/net/websocket" ) @@ -20,14 +19,11 @@ func OnListen(auth_token string, user_id string) interface{} { req.MsgType = "LISTEN" req.Data.AuthToken = auth_token req.Data.Topics = append(req.Data.Topics, fmt.Sprintf("channel-points-channel-v1.%s", user_id)) - req_text, _ := json.Marshal(req) - fmt.Println("LISTEN message:", string(req_text)) return &req } func RequestListen() error { msg := OnListen(App.Auth.AccessToken, App.User.Id) websocket.JSON.Send(App.Connection, msg) - fmt.Println("Sending message:", msg) return nil } diff --git a/local_server.go b/local_server.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "io" "log" "net/http" @@ -25,21 +24,18 @@ func HandleHttpRequest(w http.ResponseWriter, req *http.Request) { codes, exists := req.URL.Query()["code"] if exists && len(codes) > 0 { auth_code := codes[0] - fmt.Printf("Got code: %s\n", auth_code) err := App.InitAuth(auth_code) if err != nil { resp = err.Error() return } - fmt.Println("Auth init ok", App.Auth.AccessToken) err = App.InitUser() if err != nil { resp = err.Error() return } - fmt.Println("User init ok", App.User.Id) RequestListen() resp = "OK" diff --git a/ping.go b/ping.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "golang.org/x/net/websocket" "time" ) @@ -20,7 +19,6 @@ func PingJob() { for App.Connection != nil { msg, _ := OnPing() websocket.JSON.Send(App.Connection, msg) - fmt.Println("Sending message:", msg) time.Sleep(4 * time.Minute) } diff --git a/user.go b/user.go @@ -44,13 +44,11 @@ func getUser(user_name string, user *TUser) error { if err != nil { return err } - fmt.Println("users response:", string(body)) var users TUsersResponse if err := json.Unmarshal(body, &users); err != nil { return err } - fmt.Println("users response parsed:", users) if len(users.Data) == 0 { return errors.New("getUser(): no users returned") }