From 4f8982b3edb5cc129c063881b1d93e75082ad8a6 Mon Sep 17 00:00:00 2001 From: Nikita Date: Mon, 14 Oct 2024 19:52:29 +0300 Subject: [PATCH] context: fix thread inheriting --- context.go | 16 ++++++++++------ options.go | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/context.go b/context.go index 22fc11c..84a3d4a 100644 --- a/context.go +++ b/context.go @@ -424,7 +424,7 @@ func (c *nativeContext) Args() []string { } func (c *nativeContext) Send(what interface{}, opts ...interface{}) error { - opts = c.inheritOpts(opts) + opts = c.inheritOpts(opts...) _, err := c.b.Send(c.Recipient(), what, opts...) return err } @@ -434,6 +434,10 @@ func (c *nativeContext) inheritOpts(opts ...interface{}) []interface{} { ignoreThread bool ) + if opts == nil { + opts = make([]interface{}, 0) + } + for _, opt := range opts { switch opt.(type) { case Option: @@ -447,14 +451,14 @@ func (c *nativeContext) inheritOpts(opts ...interface{}) []interface{} { switch { case !ignoreThread && c.Message() != nil && c.Message().ThreadID != 0: - opts = append(opts, Topic{ThreadID: c.Message().ThreadID}) + opts = append(opts, &Topic{ThreadID: c.Message().ThreadID}) } return opts } func (c *nativeContext) SendAlbum(a Album, opts ...interface{}) error { - opts = c.inheritOpts(opts) + opts = c.inheritOpts(opts...) _, err := c.b.SendAlbum(c.Recipient(), a, opts...) return err @@ -465,7 +469,7 @@ func (c *nativeContext) Reply(what interface{}, opts ...interface{}) error { if msg == nil { return ErrBadContext } - opts = c.inheritOpts(opts) + opts = c.inheritOpts(opts...) _, err := c.b.Reply(msg, what, opts...) return err } @@ -485,7 +489,7 @@ func (c *nativeContext) ForwardTo(to Recipient, opts ...interface{}) error { } func (c *nativeContext) Edit(what interface{}, opts ...interface{}) error { - opts = c.inheritOpts(opts) + opts = c.inheritOpts(opts...) if c.u.InlineResult != nil { _, err := c.b.Edit(c.u.InlineResult, what, opts...) @@ -499,7 +503,7 @@ func (c *nativeContext) Edit(what interface{}, opts ...interface{}) error { } func (c *nativeContext) EditCaption(caption string, opts ...interface{}) error { - opts = c.inheritOpts(opts) + opts = c.inheritOpts(opts...) if c.u.InlineResult != nil { _, err := c.b.EditCaption(c.u.InlineResult, caption, opts...) diff --git a/options.go b/options.go index 5291c73..fe93046 100644 --- a/options.go +++ b/options.go @@ -120,6 +120,8 @@ func (b *Bot) extractOptions(how []interface{}) *SendOptions { } case *ReplyParams: opts.ReplyParams = opt + case *Topic: + opts.ThreadID = opt.ThreadID case Option: switch opt { case NoPreview: @@ -152,8 +154,6 @@ func (b *Bot) extractOptions(how []interface{}) *SendOptions { opts.ParseMode = opt case Entities: opts.Entities = opt - case Topic: - opts.ThreadID = opt.ThreadID default: panic("telebot: unsupported send-option") }