some fixes and small changes
This commit is contained in:
42
utils.go
42
utils.go
@@ -1,6 +1,10 @@
|
||||
package laniakea
|
||||
|
||||
import "git.nix13.pw/scuroneko/laniakea/utils"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"git.nix13.pw/scuroneko/laniakea/utils"
|
||||
)
|
||||
|
||||
func Ptr[T any](v T) *T { return &v }
|
||||
func Val[T any](p *T, def T) T {
|
||||
@@ -9,7 +13,39 @@ func Val[T any](p *T, def T) T {
|
||||
}
|
||||
return def
|
||||
}
|
||||
func EscapeMarkdown(s string) string { return utils.EscapeMarkdown(s) }
|
||||
func EscapeMarkdownV2(s string) string { return utils.EscapeMarkdownV2(s) }
|
||||
|
||||
// EscapeMarkdown
|
||||
// Deprecated. Use MarkdownV2
|
||||
func EscapeMarkdown(s string) string {
|
||||
s = strings.ReplaceAll(s, "_", `\_`)
|
||||
s = strings.ReplaceAll(s, "*", `\*`)
|
||||
s = strings.ReplaceAll(s, "[", `\[`)
|
||||
return strings.ReplaceAll(s, "`", "\\`")
|
||||
}
|
||||
|
||||
// EscapeHTML escapes special characters for Telegram HTML parse mode.
|
||||
func EscapeHTML(s string) string {
|
||||
s = strings.ReplaceAll(s, "&", "&")
|
||||
s = strings.ReplaceAll(s, "<", "<")
|
||||
s = strings.ReplaceAll(s, ">", ">")
|
||||
return s
|
||||
}
|
||||
|
||||
// EscapeMarkdownV2 escapes special characters for Telegram MarkdownV2.
|
||||
// https://core.telegram.org/bots/api#markdownv2-style
|
||||
func EscapeMarkdownV2(s string) string {
|
||||
symbols := []string{"\\", "_", "*", "[", "]", "(", ")", "~", "`", ">", "#", "+", "-", "=", "|", "{", "}", ".", "!"}
|
||||
for _, symbol := range symbols {
|
||||
s = strings.ReplaceAll(s, symbol, "\\"+symbol)
|
||||
}
|
||||
return s
|
||||
}
|
||||
func EscapePunctuation(s string) string {
|
||||
symbols := []string{".", "!", "-"}
|
||||
for _, symbol := range symbols {
|
||||
s = strings.ReplaceAll(s, symbol, "\\"+symbol)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
const VersionString = utils.VersionString
|
||||
|
||||
Reference in New Issue
Block a user