Skip to content

Commit

Permalink
Parse Telegram formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
purplesyringa committed Dec 29, 2021
1 parent 5ffd2f1 commit 42b6110
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions bridge/telegram/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand Down

0 comments on commit 42b6110

Please sign in to comment.