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

View File

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