2023-01-22 23:54:54 +03:00
|
|
|
package nechotron
|
|
|
|
|
|
|
|
import (
|
2023-01-24 23:16:58 +03:00
|
|
|
"fmt"
|
2023-01-22 23:54:54 +03:00
|
|
|
"regexp"
|
|
|
|
"strings"
|
2023-01-24 23:16:58 +03:00
|
|
|
|
|
|
|
"github.com/NicoNex/echotron/v3"
|
2023-01-22 23:54:54 +03:00
|
|
|
)
|
|
|
|
|
2023-06-15 17:04:09 +03:00
|
|
|
var chars = []string{"_", "\\*", "\\[", "\\]", "\\(", "\\)", "~", "`", ">", "#", "\\+", "\\-", "=", "|", "{", "}", "\\.", "!"}
|
2023-01-22 23:54:54 +03:00
|
|
|
var r = strings.Join(chars, "")
|
|
|
|
var reg = regexp.MustCompile("[" + r + "]+")
|
|
|
|
|
|
|
|
func EscapeMd2(s string) string {
|
|
|
|
return reg.ReplaceAllString(s, "\\$0")
|
|
|
|
}
|
2023-01-24 23:16:58 +03:00
|
|
|
|
|
|
|
func UserMention(u *echotron.User) string {
|
|
|
|
return fmt.Sprintf("[%s](tg://user?id=%d)", EscapeMd2(u.FirstName), u.ID)
|
|
|
|
}
|