diff options
author | bodqhrohro <bodqhrohro@gmail.com> | 2020-01-10 00:16:40 +0300 |
---|---|---|
committer | bodqhrohro <bodqhrohro@gmail.com> | 2020-01-10 00:16:40 +0300 |
commit | 70383bee128b11451211e514200b23f47bf272db (patch) | |
tree | bfc56f26264e206e66e4a6c150f70cf8625e8d66 /telegram/utils.go | |
parent | b8fcac6ae24dd5e07f366741f0f282f33b18b503 (diff) |
Convert formatting entities to Markdown
Diffstat (limited to 'telegram/utils.go')
-rw-r--r-- | telegram/utils.go | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/telegram/utils.go b/telegram/utils.go index 8de1f5f..f7e7a28 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -15,6 +15,7 @@ import ( "time" "dev.narayana.im/narayana/telegabber/telegram/cache" + "dev.narayana.im/narayana/telegabber/telegram/formatter" "dev.narayana.im/narayana/telegabber/xmpp/gateway" log "github.com/sirupsen/logrus" @@ -281,6 +282,7 @@ func (c *Client) formatContent(file *client.File, filename string) string { } func (c *Client) messageToText(message *client.Message) string { + markupFunction := formatter.EntityToMarkdown switch message.Content.MessageContentType() { case client.TypeMessageSticker: sticker, _ := message.Content.(*client.MessageSticker) @@ -318,27 +320,55 @@ func (c *Client) messageToText(message *client.Message) string { ) case client.TypeMessagePhoto: photo, _ := message.Content.(*client.MessagePhoto) - return photo.Caption.Text + return formatter.Format( + photo.Caption.Text, + formatter.SortEntities(photo.Caption.Entities), + markupFunction, + ) case client.TypeMessageAudio: audio, _ := message.Content.(*client.MessageAudio) - return audio.Caption.Text + return formatter.Format( + audio.Caption.Text, + formatter.SortEntities(audio.Caption.Entities), + markupFunction, + ) case client.TypeMessageVideo: video, _ := message.Content.(*client.MessageVideo) - return video.Caption.Text + return formatter.Format( + video.Caption.Text, + formatter.SortEntities(video.Caption.Entities), + markupFunction, + ) case client.TypeMessageDocument: document, _ := message.Content.(*client.MessageDocument) - return document.Caption.Text + return formatter.Format( + document.Caption.Text, + formatter.SortEntities(document.Caption.Entities), + markupFunction, + ) case client.TypeMessageText: text, _ := message.Content.(*client.MessageText) - return text.Text.Text + return formatter.Format( + text.Text.Text, + formatter.SortEntities(text.Text.Entities), + markupFunction, + ) case client.TypeMessageVoiceNote: voice, _ := message.Content.(*client.MessageVoiceNote) - return voice.Caption.Text + return formatter.Format( + voice.Caption.Text, + formatter.SortEntities(voice.Caption.Entities), + markupFunction, + ) case client.TypeMessageVideoNote: return "" case client.TypeMessageAnimation: animation, _ := message.Content.(*client.MessageAnimation) - return animation.Caption.Text + return formatter.Format( + animation.Caption.Text, + formatter.SortEntities(animation.Caption.Entities), + markupFunction, + ) } return fmt.Sprintf("unknown message (%s)", message.Content.MessageContentType()) |