aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go22
1 files changed, 8 insertions, 14 deletions
diff --git a/main.go b/main.go
index 885fe1e..203f6a6 100644
--- a/main.go
+++ b/main.go
@@ -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