]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Improve 过滤表情字符
authorqydysky <qydysky@foxmail.com>
Sun, 28 Jul 2024 07:21:49 +0000 (15:21 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 28 Jul 2024 07:21:49 +0000 (15:21 +0800)
Reply/F/danmuEmotes/danmuEmotes.go

index afc3d44aa58a7b2c7f7c39ed500b9ea4c02d3668..81e7e7004bfa2a0a806fb572c4502f10cbc224f6 100644 (file)
@@ -15,6 +15,7 @@ import (
 // path
 var (
        SaveEmote = comp.NewComp(saveEmote)
+       replace   = strings.NewReplacer(`| `, `\ `, `/ `, `: `, `* `, `? `, `" `, `< `, `> `, `| `)
 )
 
 type Danmu struct {
@@ -35,7 +36,7 @@ func saveEmote(ctx context.Context, ptr Danmu) (ret any, err error) {
                                        *ptr.Msg = "[" + *ptr.Msg + emoticon_unique + "]"
                                }
                        }
-                       savePath := "emots/" + *ptr.Msg + ".png"
+                       savePath := "emots/" + replace.Replace(*ptr.Msg) + ".png"
                        if !file.New(savePath, 0, true).IsExist() {
                                go func() {
                                        req := c.C.ReqPool.Get()
@@ -81,7 +82,7 @@ func saveEmote(ctx context.Context, ptr Danmu) (ret any, err error) {
                                                        continue
                                                }
 
-                                               savePath := "emots/" + k + ".png"
+                                               savePath := "emots/" + replace.Replace(k) + ".png"
                                                if file.New(savePath, 0, true).IsExist() {
                                                        continue
                                                }