22package aireply
33
44import (
5+ "crypto/md5"
6+ "encoding/hex"
7+ "os"
58 "regexp"
69 "strconv"
10+ "strings"
711 "time"
812
913 "github.com/FloatTech/AnimeAPI/tts/genshin"
14+ "github.com/FloatTech/floatbox/binary"
15+ "github.com/FloatTech/floatbox/file"
1016 ctrl "github.com/FloatTech/zbpctrl"
1117 "github.com/FloatTech/zbputils/control"
1218 "github.com/FloatTech/zbputils/ctxext"
@@ -75,6 +81,12 @@ func init() { // 插件主体
7581 })
7682
7783 endpre := regexp .MustCompile (`\pP$` )
84+ ttscachedir := ent .DataFolder () + "cache/"
85+ _ = os .RemoveAll (ttscachedir )
86+ err := os .MkdirAll (ttscachedir , 0755 )
87+ if err != nil {
88+ panic (err )
89+ }
7890 ent .OnMessage (zero .OnlyToMe ).SetBlock (true ).Limit (ctxext .LimitByUser ).
7991 Handle (func (ctx * zero.Ctx ) {
8092 msg := ctx .ExtractPlainText ()
@@ -98,6 +110,17 @@ func init() { // 插件主体
98110 ctx .SendChain (message .Reply (ctx .Event .MessageID ), message .Text (reply ))
99111 return
100112 }
113+ if strings .HasPrefix (rec , "http" ) {
114+ b := md5 .Sum (binary .StringToBytes (rec ))
115+ fn := hex .EncodeToString (b [:])
116+ fp := ttscachedir + fn
117+ if file .IsNotExist (fp ) {
118+ if file .DownloadTo (rec , fp ) != nil {
119+ return
120+ }
121+ }
122+ rec = "file:///" + file .BOTPATH + "/" + fp
123+ }
101124 // 发送语音
102125 if id := ctx .SendChain (message .Record (rec )); id .ID () == 0 {
103126 ctx .SendChain (message .Reply (ctx .Event .MessageID ), message .Text (reply ))
0 commit comments