bot: remove closures around runHandler

pull/279/head
Orivej Desh 4 years ago
parent 95769df144
commit 953bcdf552

@ -186,7 +186,7 @@ func (b *Bot) Start() {
select {
// handle incoming updates
case upd := <-b.Updates:
b.ProcessUpdate(&upd)
b.ProcessUpdate(upd)
// call to stop polling
case <-b.stop:
stop <- struct{}{}
@ -202,7 +202,7 @@ func (b *Bot) Stop() {
// ProcessUpdate processes a single incoming update.
// A started bot calls this function automatically.
func (b *Bot) ProcessUpdate(upd *Update) {
func (b *Bot) ProcessUpdate(upd Update) {
if upd.Message != nil {
m := upd.Message
@ -293,9 +293,7 @@ func (b *Bot) ProcessUpdate(upd *Update) {
panic("telebot: migration handler is bad")
}
func(b *Bot, handler func(int64, int64), from, to int64) {
b.runHandler(func() { handler(from, to) })
}(b, handler, m.Chat.ID, m.MigrateTo)
b.runHandler(func() { handler(m.Chat.ID, m.MigrateTo) })
}
return
@ -347,9 +345,7 @@ func (b *Bot) ProcessUpdate(upd *Update) {
}
upd.Callback.Data = payload
func(b *Bot, handler func(*Callback), c *Callback) {
b.runHandler(func() { handler(c) })
}(b, handler, upd.Callback)
b.runHandler(func() { handler(upd.Callback) })
return
}
@ -363,9 +359,7 @@ func (b *Bot) ProcessUpdate(upd *Update) {
panic("telebot: callback handler is bad")
}
func(b *Bot, handler func(*Callback), c *Callback) {
b.runHandler(func() { handler(c) })
}(b, handler, upd.Callback)
b.runHandler(func() { handler(upd.Callback) })
}
return
@ -378,9 +372,7 @@ func (b *Bot) ProcessUpdate(upd *Update) {
panic("telebot: query handler is bad")
}
func(b *Bot, handler func(*Query), q *Query) {
b.runHandler(func() { handler(q) })
}(b, handler, upd.Query)
b.runHandler(func() { handler(upd.Query) })
}
return
@ -393,9 +385,7 @@ func (b *Bot) ProcessUpdate(upd *Update) {
panic("telebot: chosen inline result handler is bad")
}
func(b *Bot, handler func(*ChosenInlineResult), r *ChosenInlineResult) {
b.runHandler(func() { handler(r) })
}(b, handler, upd.ChosenInlineResult)
b.runHandler(func() { handler(upd.ChosenInlineResult) })
}
return
@ -408,9 +398,7 @@ func (b *Bot) ProcessUpdate(upd *Update) {
panic("telebot: pre checkout query handler is bad")
}
func(b *Bot, handler func(*PreCheckoutQuery), pre *PreCheckoutQuery) {
b.runHandler(func() { handler(pre) })
}(b, handler, upd.PreCheckoutQuery)
b.runHandler(func() { handler(upd.PreCheckoutQuery) })
}
return
@ -423,9 +411,7 @@ func (b *Bot) ProcessUpdate(upd *Update) {
panic("telebot: poll handler is bad")
}
func(b *Bot, handler func(*Poll), p *Poll) {
b.runHandler(func() { handler(p) })
}(b, handler, upd.Poll)
b.runHandler(func() { handler(upd.Poll) })
}
return
@ -438,9 +424,7 @@ func (b *Bot) ProcessUpdate(upd *Update) {
panic("telebot: poll answer handler is bad")
}
func(b *Bot, handler func(*PollAnswer), pa *PollAnswer) {
b.runHandler(func() { handler(pa) })
}(b, handler, upd.PollAnswer)
b.runHandler(func() { handler(upd.PollAnswer) })
}
return

@ -234,41 +234,41 @@ func TestBotIncomingUpdate(t *testing.T) {
assert.Equal(t, "poll", pa.PollID)
})
b.ProcessUpdate(&Update{Message: &Message{Text: "/start"}})
b.ProcessUpdate(&Update{Message: &Message{Text: "/start@other_bot"}})
b.ProcessUpdate(&Update{Message: &Message{Text: "hello"}})
b.ProcessUpdate(&Update{Message: &Message{Text: "text"}})
b.ProcessUpdate(&Update{Message: &Message{PinnedMessage: &Message{}}})
b.ProcessUpdate(&Update{Message: &Message{Photo: &Photo{}}})
b.ProcessUpdate(&Update{Message: &Message{Voice: &Voice{}}})
b.ProcessUpdate(&Update{Message: &Message{Audio: &Audio{}}})
b.ProcessUpdate(&Update{Message: &Message{Document: &Document{}}})
b.ProcessUpdate(&Update{Message: &Message{Sticker: &Sticker{}}})
b.ProcessUpdate(&Update{Message: &Message{Video: &Video{}}})
b.ProcessUpdate(&Update{Message: &Message{VideoNote: &VideoNote{}}})
b.ProcessUpdate(&Update{Message: &Message{Contact: &Contact{}}})
b.ProcessUpdate(&Update{Message: &Message{Location: &Location{}}})
b.ProcessUpdate(&Update{Message: &Message{Venue: &Venue{}}})
b.ProcessUpdate(&Update{Message: &Message{GroupCreated: true}})
b.ProcessUpdate(&Update{Message: &Message{UserJoined: &User{}}})
b.ProcessUpdate(&Update{Message: &Message{UsersJoined: []User{{}}}})
b.ProcessUpdate(&Update{Message: &Message{UserLeft: &User{}}})
b.ProcessUpdate(&Update{Message: &Message{NewGroupTitle: "title"}})
b.ProcessUpdate(&Update{Message: &Message{NewGroupPhoto: &Photo{}}})
b.ProcessUpdate(&Update{Message: &Message{GroupPhotoDeleted: true}})
b.ProcessUpdate(&Update{Message: &Message{Chat: &Chat{ID: 1}, MigrateTo: 2}})
b.ProcessUpdate(&Update{EditedMessage: &Message{Text: "edited"}})
b.ProcessUpdate(&Update{ChannelPost: &Message{Text: "post"}})
b.ProcessUpdate(&Update{ChannelPost: &Message{PinnedMessage: &Message{}}})
b.ProcessUpdate(&Update{EditedChannelPost: &Message{Text: "edited post"}})
b.ProcessUpdate(&Update{Callback: &Callback{MessageID: "inline", Data: "callback"}})
b.ProcessUpdate(&Update{Callback: &Callback{Data: "callback"}})
b.ProcessUpdate(&Update{Callback: &Callback{Data: "\funique|callback"}})
b.ProcessUpdate(&Update{Query: &Query{Text: "query"}})
b.ProcessUpdate(&Update{ChosenInlineResult: &ChosenInlineResult{ResultID: "result"}})
b.ProcessUpdate(&Update{PreCheckoutQuery: &PreCheckoutQuery{ID: "checkout"}})
b.ProcessUpdate(&Update{Poll: &Poll{ID: "poll"}})
b.ProcessUpdate(&Update{PollAnswer: &PollAnswer{PollID: "poll"}})
b.ProcessUpdate(Update{Message: &Message{Text: "/start"}})
b.ProcessUpdate(Update{Message: &Message{Text: "/start@other_bot"}})
b.ProcessUpdate(Update{Message: &Message{Text: "hello"}})
b.ProcessUpdate(Update{Message: &Message{Text: "text"}})
b.ProcessUpdate(Update{Message: &Message{PinnedMessage: &Message{}}})
b.ProcessUpdate(Update{Message: &Message{Photo: &Photo{}}})
b.ProcessUpdate(Update{Message: &Message{Voice: &Voice{}}})
b.ProcessUpdate(Update{Message: &Message{Audio: &Audio{}}})
b.ProcessUpdate(Update{Message: &Message{Document: &Document{}}})
b.ProcessUpdate(Update{Message: &Message{Sticker: &Sticker{}}})
b.ProcessUpdate(Update{Message: &Message{Video: &Video{}}})
b.ProcessUpdate(Update{Message: &Message{VideoNote: &VideoNote{}}})
b.ProcessUpdate(Update{Message: &Message{Contact: &Contact{}}})
b.ProcessUpdate(Update{Message: &Message{Location: &Location{}}})
b.ProcessUpdate(Update{Message: &Message{Venue: &Venue{}}})
b.ProcessUpdate(Update{Message: &Message{GroupCreated: true}})
b.ProcessUpdate(Update{Message: &Message{UserJoined: &User{}}})
b.ProcessUpdate(Update{Message: &Message{UsersJoined: []User{{}}}})
b.ProcessUpdate(Update{Message: &Message{UserLeft: &User{}}})
b.ProcessUpdate(Update{Message: &Message{NewGroupTitle: "title"}})
b.ProcessUpdate(Update{Message: &Message{NewGroupPhoto: &Photo{}}})
b.ProcessUpdate(Update{Message: &Message{GroupPhotoDeleted: true}})
b.ProcessUpdate(Update{Message: &Message{Chat: &Chat{ID: 1}, MigrateTo: 2}})
b.ProcessUpdate(Update{EditedMessage: &Message{Text: "edited"}})
b.ProcessUpdate(Update{ChannelPost: &Message{Text: "post"}})
b.ProcessUpdate(Update{ChannelPost: &Message{PinnedMessage: &Message{}}})
b.ProcessUpdate(Update{EditedChannelPost: &Message{Text: "edited post"}})
b.ProcessUpdate(Update{Callback: &Callback{MessageID: "inline", Data: "callback"}})
b.ProcessUpdate(Update{Callback: &Callback{Data: "callback"}})
b.ProcessUpdate(Update{Callback: &Callback{Data: "\funique|callback"}})
b.ProcessUpdate(Update{Query: &Query{Text: "query"}})
b.ProcessUpdate(Update{ChosenInlineResult: &ChosenInlineResult{ResultID: "result"}})
b.ProcessUpdate(Update{PreCheckoutQuery: &PreCheckoutQuery{ID: "checkout"}})
b.ProcessUpdate(Update{Poll: &Poll{ID: "poll"}})
b.ProcessUpdate(Update{PollAnswer: &PollAnswer{PollID: "poll"}})
}
func TestBot(t *testing.T) {

Loading…
Cancel
Save