Skip to content

Commit

Permalink
feat(xtelebot): add EscapeMarkdownV2
Browse files Browse the repository at this point in the history
  • Loading branch information
seefs001 committed Oct 26, 2024
1 parent 8621fc0 commit 4ff107d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion xjson/xjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func Map(data interface{}, fn func(key interface{}, value interface{}) (interfac
}
return result, nil
default:
return nil, fmt.Errorf("Map can only be applied to JSONObject, JSONArray, or []interface{}")
return nil, fmt.Errorf("map can only be applied to JSONObject, JSONArray, or []interface{}")
}
}

Expand Down
25 changes: 25 additions & 0 deletions xtelebot/xtelebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -1323,3 +1323,28 @@ func (b *Bot) uploadFile(ctx context.Context, method string, params url.Values,

return resp, nil
}

// EscapeMarkdownV2 escapes MarkdownV2 reserved characters
func EscapeMarkdownV2(text string) string {
replacer := strings.NewReplacer(
"_", "\\_",
"*", "\\*",
"[", "\\[",
"]", "\\]",
"(", "\\(",
")", "\\)",
"~", "\\~",
"`", "\\`",
">", "\\>",
"#", "\\#",
"+", "\\+",
"-", "\\-",
"=", "\\=",
"|", "\\|",
"{", "\\{",
"}", "\\}",
".", "\\.",
"!", "\\!",
)
return replacer.Replace(text)
}

0 comments on commit 4ff107d

Please sign in to comment.