Skip to content

Commit

Permalink
context: check for Message properly
Browse files Browse the repository at this point in the history
  • Loading branch information
demget committed Jan 22, 2022
1 parent c46e31d commit f2a7d45
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ func (c *nativeContext) Migration() (int64, int64) {

func (c *nativeContext) Sender() *User {
switch {
case c.u.Message != nil:
return c.u.Message.Sender
case c.u.Callback != nil:
return c.u.Callback.Sender
case c.Message() != nil:
return c.Message().Sender
case c.u.Query != nil:
return c.u.Query.Sender
case c.u.InlineResult != nil:
Expand All @@ -292,10 +292,8 @@ func (c *nativeContext) Sender() *User {

func (c *nativeContext) Chat() *Chat {
switch {
case c.u.Message != nil:
return c.u.Message.Chat
case c.u.Callback != nil && c.u.Callback.Message != nil:
return c.u.Callback.Message.Chat
case c.Message() != nil:
return c.Message().Chat
case c.u.MyChatMember != nil:
return c.u.MyChatMember.Chat
case c.u.ChatMember != nil:
Expand All @@ -316,21 +314,13 @@ func (c *nativeContext) Recipient() Recipient {
}

func (c *nativeContext) Text() string {
var m *Message

switch {
case c.u.Message != nil:
m = c.u.Message
case c.u.Callback != nil && c.u.Callback.Message != nil:
m = c.u.Callback.Message
default:
m := c.Message()
if m == nil {
return ""
}

if m.Caption != "" {
return m.Caption
}

return m.Text
}

Expand Down

0 comments on commit f2a7d45

Please sign in to comment.