mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 05:30:07 +08:00
fix: customize tts download
This commit is contained in:
parent
f043fbf0c0
commit
9dade7f3e8
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.20
|
||||
require (
|
||||
github.com/Baidu-AIP/golang-sdk v1.1.1
|
||||
github.com/FloatTech/AnimeAPI v1.6.1-0.20230827144904-758793598579
|
||||
github.com/FloatTech/floatbox v0.0.0-20230331064925-9af336a84944
|
||||
github.com/FloatTech/floatbox v0.0.0-20230827160415-f0865337a824
|
||||
github.com/FloatTech/gg v1.1.3-0.20230226151425-6ea91286ba08
|
||||
github.com/FloatTech/imgfactory v0.2.2-0.20230413152719-e101cc3606ef
|
||||
github.com/FloatTech/rendercard v0.0.10-0.20230223064326-45d29fa4ede9
|
||||
|
||||
4
go.sum
4
go.sum
@ -4,8 +4,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
|
||||
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
||||
github.com/FloatTech/AnimeAPI v1.6.1-0.20230827144904-758793598579 h1:IMbVe2zNXAgoNaSnNzXq9F3PSgf6tbqbDUjzBwmCOkA=
|
||||
github.com/FloatTech/AnimeAPI v1.6.1-0.20230827144904-758793598579/go.mod h1:6vYu7bW5gPQsBnXB+I6yk+eJQaaAwusoQ/I/wQMwOAI=
|
||||
github.com/FloatTech/floatbox v0.0.0-20230331064925-9af336a84944 h1:/eQoMa6Aj3coF5F7yhzZe1+SzX6SItul7MW8//pl18o=
|
||||
github.com/FloatTech/floatbox v0.0.0-20230331064925-9af336a84944/go.mod h1:FwQm6wk+b4wuW54KCKn3zccMX47Q5apnHD/Yakzv0fI=
|
||||
github.com/FloatTech/floatbox v0.0.0-20230827160415-f0865337a824 h1:w72fzQg1Y9+VLSRl7iKzaZ6fG3myyMJfpOSajcjaMDM=
|
||||
github.com/FloatTech/floatbox v0.0.0-20230827160415-f0865337a824/go.mod h1:FwQm6wk+b4wuW54KCKn3zccMX47Q5apnHD/Yakzv0fI=
|
||||
github.com/FloatTech/gg v1.1.3-0.20230226151425-6ea91286ba08 h1:dPLeoiTVSBlgls+66EB/UJ2e38BaASmBN5nANaycSBU=
|
||||
github.com/FloatTech/gg v1.1.3-0.20230226151425-6ea91286ba08/go.mod h1:uzPzAeT35egARdRuu+1oyjU3CmTwCceoq3Vvje7LpcI=
|
||||
github.com/FloatTech/imgfactory v0.2.2-0.20230413152719-e101cc3606ef h1:CJbK/2FRwPuZpeb6M4sWK2d7oXDnBEGhpkQuQrgc91A=
|
||||
|
||||
@ -2,11 +2,17 @@
|
||||
package aireply
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/tts/genshin"
|
||||
"github.com/FloatTech/floatbox/binary"
|
||||
"github.com/FloatTech/floatbox/file"
|
||||
ctrl "github.com/FloatTech/zbpctrl"
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
@ -75,6 +81,12 @@ func init() { // 插件主体
|
||||
})
|
||||
|
||||
endpre := regexp.MustCompile(`\pP$`)
|
||||
ttscachedir := ent.DataFolder() + "cache/"
|
||||
_ = os.RemoveAll(ttscachedir)
|
||||
err := os.MkdirAll(ttscachedir, 0755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ent.OnMessage(zero.OnlyToMe).SetBlock(true).Limit(ctxext.LimitByUser).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
msg := ctx.ExtractPlainText()
|
||||
@ -98,6 +110,17 @@ func init() { // 插件主体
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(reply))
|
||||
return
|
||||
}
|
||||
if strings.HasPrefix(rec, "http") {
|
||||
b := md5.Sum(binary.StringToBytes(rec))
|
||||
fn := hex.EncodeToString(b[:])
|
||||
fp := ttscachedir + fn
|
||||
if file.IsNotExist(fp) {
|
||||
if file.DownloadTo(rec, fp) != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
rec = "file:///" + file.BOTPATH + "/" + fp
|
||||
}
|
||||
// 发送语音
|
||||
if id := ctx.SendChain(message.Record(rec)); id.ID() == 0 {
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(reply))
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
package moegoe
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
@ -9,6 +11,8 @@ import (
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/tts/genshin"
|
||||
"github.com/FloatTech/floatbox/binary"
|
||||
"github.com/FloatTech/floatbox/file"
|
||||
ctrl "github.com/FloatTech/zbpctrl"
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
@ -53,6 +57,16 @@ func init() {
|
||||
}
|
||||
text := ctx.State["regex_matched"].([]string)[2]
|
||||
name := ctx.State["regex_matched"].([]string)[1]
|
||||
ctx.SendChain(message.Record(fmt.Sprintf(genshin.CNAPI, name, url.QueryEscape(text), url.QueryEscape(原.k))))
|
||||
rec := fmt.Sprintf(genshin.CNAPI, name, url.QueryEscape(text), url.QueryEscape(原.k))
|
||||
b := md5.Sum(binary.StringToBytes(rec))
|
||||
fn := hex.EncodeToString(b[:])
|
||||
fp := "data/tts/" + fn
|
||||
if file.IsNotExist(fp) {
|
||||
if file.DownloadTo(rec, fp) != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
rec = "file:///" + file.BOTPATH + "/" + fp
|
||||
ctx.SendChain(message.Record(rec))
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user