From ad84cbde5a2818e974016e243f527acbee0ffe64 Mon Sep 17 00:00:00 2001 From: Demian Date: Mon, 14 Nov 2022 13:02:38 +0200 Subject: [PATCH] context: add message Entities function --- context.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/context.go b/context.go index 30a13ab..9654aae 100644 --- a/context.go +++ b/context.go @@ -70,6 +70,10 @@ type Context interface { // In the case when no related data presented, returns an empty string. Text() string + // Entities returns the message entities, whether it's media caption's or the text's. + // In the case when no entities presented, returns a nil. + Entities() Entities + // Data returns the current data, depending on the context type. // If the context contains command, returns its arguments string. // If the context contains payment, returns its payload. @@ -297,6 +301,17 @@ func (c *nativeContext) Text() string { return m.Text } +func (c *nativeContext) Entities() Entities { + m := c.Message() + if m == nil { + return nil + } + if len(m.CaptionEntities) > 0 { + return m.CaptionEntities + } + return m.Entities +} + func (c *nativeContext) Data() string { switch { case c.u.Message != nil: