From 42b61108e22bf63cbb533414d337803d25c8b5ca Mon Sep 17 00:00:00 2001 From: Ivanq Date: Wed, 29 Dec 2021 16:35:07 +0300 Subject: [PATCH] Parse Telegram formatting --- bridge/telegram/handlers.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bridge/telegram/handlers.go b/bridge/telegram/handlers.go index 80a7185c19..a4296d5169 100644 --- a/bridge/telegram/handlers.go +++ b/bridge/telegram/handlers.go @@ -461,6 +461,24 @@ func (b *Btelegram) handleEntities(rmsg *config.Message, message *tgbotapi.Messa rmsg.Text = strings.Replace(rmsg.Text, string(link), url.String(), 1) } + if e.Type == "bold" { + offset := e.Offset + indexMovedBy + rmsg.Text = rmsg.Text[:offset] + "**" + rmsg.Text[offset:offset+e.Length] + "**" + rmsg.Text[offset+e.Length:] + indexMovedBy += 4 + } + + if e.Type == "italic" { + offset := e.Offset + indexMovedBy + rmsg.Text = rmsg.Text[:offset] + "*" + rmsg.Text[offset:offset+e.Length] + "*" + rmsg.Text[offset+e.Length:] + indexMovedBy += 2 + } + + if e.Type == "strikethrough" { + offset := e.Offset + indexMovedBy + rmsg.Text = rmsg.Text[:offset] + "~~" + rmsg.Text[offset:offset+e.Length] + "~~" + rmsg.Text[offset+e.Length:] + indexMovedBy += 4 + } + if e.Type == "code" { offset := e.Offset + indexMovedBy rmsg.Text = rmsg.Text[:offset] + "`" + rmsg.Text[offset:offset+e.Length] + "`" + rmsg.Text[offset+e.Length:]