diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2021-12-05 06:27:14 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2021-12-05 06:27:14 +0300 |
commit | 2a1c09fcdd66732e5ec454b828a0cfdc1902250f (patch) | |
tree | e794177bd04081d9419035571d5bb7e0c1ca4203 /telegram/utils.go | |
parent | 105f5017c35f92a9e2f5398a06cfdd3f1da31bad (diff) |
Fix a crash on big emojis
Diffstat (limited to 'telegram/utils.go')
-rw-r--r-- | telegram/utils.go | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/telegram/utils.go b/telegram/utils.go index 3082b5f..476ae43 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -247,11 +247,13 @@ func (c *Client) formatMessage(chatID int64, messageID int64, preview bool, mess } var text string - switch message.Content.MessageContentType() { - case client.TypeMessageText: - messageText, _ := message.Content.(*client.MessageText) - text = messageText.Text.Text - // TODO: handle other message types with labels (not supported in Zhabogram!) + if message.Content != nil { + switch message.Content.MessageContentType() { + case client.TypeMessageText: + messageText, _ := message.Content.(*client.MessageText) + text = messageText.Text.Text + // TODO: handle other message types with labels (not supported in Zhabogram!) + } } if text != "" { if !preview { @@ -285,6 +287,11 @@ func (c *Client) formatContent(file *client.File, filename string) string { } func (c *Client) messageToText(message *client.Message) string { + if message.Content == nil { + log.Warnf("Unknown message (big emoji?): %#v", message) + return "<BIG EMOJI>" + } + markupFunction := formatter.EntityToMarkdown switch message.Content.MessageContentType() { case client.TypeMessageSticker: @@ -378,6 +385,10 @@ func (c *Client) messageToText(message *client.Message) string { } func (c *Client) contentToFilename(content client.MessageContent) (*client.File, string) { + if content == nil { + return nil, "" + } + switch content.MessageContentType() { case client.TypeMessageSticker: sticker, _ := content.(*client.MessageSticker) |