Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vildan-valeev committed Dec 28, 2023
1 parent d73ff63 commit 358d260
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 34 deletions.
34 changes: 4 additions & 30 deletions dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,11 @@ func (d *Dispatcher) Poll() error {
}

func (d *Dispatcher) PollOptions(dropPendingUpdates bool) error {
//var (
// timeout = d.Wait
// isFirstRun = true //TODO: сброс апдейтов
//)

//// deletes webhook if present to run in long polling mode
//if _, err := d.api.DeleteWebhook(dropPendingUpdates); err != nil {
// return err
//}

for {
//TODO: сброс апдейтов
//if isFirstRun {
// opts.Timeout = 0
//}
time.Sleep(2 * time.Second)

time.Sleep(100 * time.Millisecond)

result, err := d.api.GetUpdates(&d.opts)
if err != nil {
return err
Expand All @@ -101,25 +90,11 @@ func (d *Dispatcher) PollOptions(dropPendingUpdates bool) error {
if err != nil {
return err
}
//
//if !dropPendingUpdates || !isFirstRun {
// for _, u := range response.Result {
// d.updates <- u
// }
//}

for _, u := range updates {
fmt.Println("UPDATES!", u.Object.MessageNew)
d.updates <- u
}
//if l := len(response.Result); l > 0 {
// opts.Offset = response.Result[l-1].ID + 1
//}
//
//if isFirstRun {
// isFirstRun = false
// opts.Timeout = timeout
//}

}
}

Expand Down Expand Up @@ -171,7 +146,6 @@ func (d *Dispatcher) autoSetting(ctx context.Context) error {
APIVersion: APIVersion,
}
_, err := d.api.GroupsSetLongPollSettings(&opts)
log.Println("SetLongPollSettings", err)
return err
}

Expand Down
7 changes: 3 additions & 4 deletions requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/url"
)
Expand All @@ -20,13 +19,13 @@ func get[T Response](base, endpoint string, vals url.Values) (res T, err error)
url = fmt.Sprintf("%s?%s", url, queries)
}
}
log.Printf("Request URL: %s", url)
//log.Printf("Request URL: %s", url)
cnt, err := SendGetRequest(url)
if err != nil {
return res, err
}
log.Printf("Response Error: %v", err)
log.Printf("Response BODY: %s", string(cnt))
//log.Printf("Response Error: %v", err)
//log.Printf("Response BODY: %s", string(cnt))
if err = json.Unmarshal(cnt, &res); err != nil {
return
}
Expand Down

0 comments on commit 358d260

Please sign in to comment.