1
0
mirror of synced 2024-11-22 12:26:02 +03:00

replace markdown symbols

This commit is contained in:
DmitryZagorulko 2018-11-06 13:55:34 +03:00
parent 0d0f70564a
commit 187a797648
2 changed files with 18 additions and 9 deletions

View File

@ -591,7 +591,7 @@ func mgWebhookHandler(c *gin.Context) {
var mb string
switch msg.Data.Type {
case v1.MsgTypeProduct:
mb = fmt.Sprintf("*%s*\n", msg.Data.Product.Name)
mb = fmt.Sprintf("*%s*\n", replaceMarkdownSymbols(msg.Data.Product.Name))
if msg.Data.Product.Cost != nil && msg.Data.Product.Cost.Value != 0 {
mb += fmt.Sprintf(
@ -608,9 +608,9 @@ func mgWebhookHandler(c *gin.Context) {
}
if msg.Data.Product.Url != "" {
mb += msg.Data.Product.Url
mb += replaceMarkdownSymbols(msg.Data.Product.Url)
} else {
mb += msg.Data.Product.Img
mb += replaceMarkdownSymbols(msg.Data.Product.Img)
}
case v1.MsgTypeOrder:
mb = getOrderMessage(msg.Data.Order)
@ -678,7 +678,7 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string {
mb := "*" + getLocalizedMessage("order")
if dataOrder.Number != "" {
mb += " " + dataOrder.Number
mb += " " + replaceMarkdownSymbols(dataOrder.Number)
}
if dataOrder.Date != "" {
@ -691,7 +691,7 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string {
mb += fmt.Sprintf(
"%d. %s",
k+1,
v.Name,
replaceMarkdownSymbols(v.Name),
)
if v.Quantity != nil {
@ -727,7 +727,7 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string {
mb += fmt.Sprintf(
"\n*%s:*\n%s",
getLocalizedMessage("delivery"),
dataOrder.Delivery.Name,
replaceMarkdownSymbols(dataOrder.Delivery.Name),
)
}
@ -747,7 +747,7 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string {
}
if dataOrder.Delivery.Address != "" {
mb += ";\n" + dataOrder.Delivery.Address
mb += ";\n" + replaceMarkdownSymbols(dataOrder.Delivery.Address)
}
mb += "\n"
@ -759,7 +759,7 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string {
getLocalizedMessage("payment"),
)
for _, v := range dataOrder.Payments {
mb += v.Name
mb += replaceMarkdownSymbols(v.Name)
if v.Amount != nil {
if val, ok := currency[strings.ToLower(v.Amount.Currency)]; ok && v.Amount.Value != 0 {
@ -779,7 +779,7 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string {
if v.Status != nil && v.Status.Name != "" {
mb += fmt.Sprintf(
" (%s)",
v.Status.Name,
replaceMarkdownSymbols(v.Status.Name),
)
}

View File

@ -24,6 +24,7 @@ var (
"/api/integration-modules/{code}",
"/api/integration-modules/{code}/edit",
}
markdownSymbols = []string{"*", "_", "`", "["}
)
// GenerateToken function
@ -133,3 +134,11 @@ func getChannelSettingsHash() (hash string, err error) {
return
}
func replaceMarkdownSymbols(s string) string {
for _, v := range markdownSymbols {
s = strings.Replace(s, v, "\\"+v, -1)
}
return s
}