diff options
| author | la-ninpre <leobrekalini@gmail.com> | 2022-10-17 13:12:23 +0300 |
|---|---|---|
| committer | la-ninpre <leobrekalini@gmail.com> | 2022-10-17 13:24:47 +0300 |
| commit | bc6954d1fe773b2ffaec71e64575c56c042caa81 (patch) | |
| tree | f79ee2b2d005a2864d4a2c737d98c1af1bad621d | |
| parent | 35e839782be9df360365efb527770615965184c0 (diff) | |
| download | telebonk-bc6954d1fe773b2ffaec71e64575c56c042caa81.tar.gz telebonk-bc6954d1fe773b2ffaec71e64575c56c042caa81.zip | |
store only honks in the honkMap
we only need the message id from TelegramResponse, so no need to store
everything else inside a struct inside a map. on a way to encapsulate
and isolate the honkMap!
| -rw-r--r-- | changelog.txt | 1 | ||||
| -rw-r--r-- | main.go | 22 |
2 files changed, 9 insertions, 14 deletions
diff --git a/changelog.txt b/changelog.txt index d92fc67..717439d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,4 +2,5 @@ changelog === next ++ removed TelegramResponse from the honkMap + make gethonks retry 5 times before giving up
\ No newline at end of file @@ -98,7 +98,7 @@ func (h *Honk) Check() error { if !ok { return fmt.Errorf("cannot reply to nonexisting telebonk") } - h.replyToID = hi.t.Result.MessageID + h.replyToID = hi.messID default: return fmt.Errorf("unsupported honk type: %s", h.What) } @@ -118,19 +118,19 @@ func (h *Honk) Check() error { func (h *Honk) Decide() honkAction { hi, ok := honkMap[h.XID] if ok { - if hi.t == nil || hi.h.Date.Equal(h.Date) { - h.save(hi.t) // is this wrong? + if hi.messID == 0 || hi.Date.Equal(h.Date) { + h.save(hi.messID) return honkIgnore } - h.messID = hi.t.Result.MessageID return honkEdit } return honkSend } // save records a Honk to a honkMap -func (h *Honk) save(t *TelegramResponse) { - honkMap[h.XID] = honkInfo{h: h, t: t} +func (h *Honk) save(messID int) { + h.messID = messID + honkMap[h.XID] = h } // forget removes a Honk from a honkMap @@ -313,12 +313,6 @@ const ( tgSendDocument = "sendDocument" ) -// A honkInfo stores data for honk that is sent to Telegram. -type honkInfo struct { - h *Honk - t *TelegramResponse -} - // getHonks receives and unmarshals some honks from a Honk instance. func getHonks(after int) ([]*Honk, error) { query := url.Values{} @@ -403,7 +397,7 @@ func init() { } var client = http.DefaultClient -var honkMap = make(map[string]honkInfo) // FIXME: not safe for use by multiple goroutines! +var honkMap = make(map[string]*Honk) // FIXME: not safe for use by multiple goroutines! var now = time.Now() func main() { @@ -442,7 +436,7 @@ func main() { continue } // remember only the first mess' response - honk.save(resp) + honk.save(resp.Result.MessageID) for _, mess := range messes[1:] { if _, err := mess.Send(); err != nil { log.Print(err) // error |
