Skip to content

Commit

Permalink
Merge pull request #168 from singularity-s0/patch-2
Browse files Browse the repository at this point in the history
change: clean leading quote from notification message
  • Loading branch information
JingYiJun authored Nov 30, 2024
2 parents ed083d2 + e626841 commit 6d697ec
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion models/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"io"
"math/rand"
"net/http"
"regexp"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -154,7 +156,7 @@ func (message Notification) Send() (Message, error) {
return Message{}, nil
}
message.Title = utils.StripContent(message.Title, 32) //varchar(32)
message.Description = utils.StripContent(message.Description, 64) //varchar(64)
message.Description = utils.StripContent(cleanNotificationDescription(message.Description), 64) //varchar(64)
body.Title = message.Title
body.Description = message.Description

Expand Down Expand Up @@ -262,3 +264,22 @@ func UpdateAdminList(ctx context.Context) {
}
}
}

var (
reHole = regexp.MustCompile(`#{1,2}\d+`)
reFormula = regexp.MustCompile(`(?s)\${1,2}.*?\${1,2}`)
reSticker = regexp.MustCompile(`!\[\]\(dx_\S+\)`)
reImage = regexp.MustCompile(`!\[.*?\]\(.*?\)`)
)

func cleanNotificationDescription(content string) string {
newContent := reHole.ReplaceAllString(content, "")
newContent = reFormula.ReplaceAllString(newContent, "[公式]")
newContent = reSticker.ReplaceAllString(newContent, "[表情]")
newContent = reImage.ReplaceAllString(newContent, "[图片]")
newContent = strings.ReplaceAll(newContent, "\n", "")
if newContent == "" {
return content
}
return newContent
}

0 comments on commit 6d697ec

Please sign in to comment.