mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-18 20:50:12 +08:00
🐛 修复tts语音切换问题 (#890)
* 🐛 修复tts语音切换问题 * 🎨 文案不变化 * 🎨 语音放到上层方法 * ✨ 添加新回复模式 * ✨ 优化回复内容 * 🐛 调整顺序
This commit is contained in:
parent
2ff164c2df
commit
b050b5d5b5
@ -977,7 +977,7 @@ print("run[CQ:image,file="+j["img"]+"]")
|
||||
|
||||
- [x] 发病 嘉然
|
||||
|
||||
- [x] 让[塔菲|嘉然|东雪莲]说我测尼玛
|
||||
- [x] 让[嘉然|塔菲|东雪莲|懒羊羊|科比|孙笑川|陈泽|丁真|空|荧|派蒙|纳西妲|阿贝多|温迪|枫原万叶|钟离|荒泷一斗|八重神子|艾尔海森|提纳里|迪希雅|卡维|宵宫|莱依拉|赛诺|诺艾尔|托马|凝光|莫娜|北斗|神里绫华|雷电将军|芭芭拉|鹿野院平藏|五郎|迪奥娜|凯亚|安柏|班尼特|琴|柯莱|夜兰|妮露|辛焱|珐露珊|魈|香菱|达达利亚|砂糖|早柚|云堇|刻晴|丽莎|迪卢克|烟绯|重云|珊瑚宫心海|胡桃|可莉|流浪者|久岐忍|神里绫人|甘雨|戴因斯雷布|优菈|菲谢尔|行秋|白术|九条裟罗|雷泽|申鹤|迪娜泽黛|凯瑟琳|多莉|坎蒂丝|萍姥姥|罗莎莉亚|留云借风真君|绮良良|瑶瑶|七七|奥兹|米卡|夏洛蒂|埃洛伊|博士|女士|大慈树王|三月七|娜塔莎|希露瓦|虎克|克拉拉|丹恒|希儿|布洛妮娅|瓦尔特|杰帕德|佩拉|姬子|艾丝妲|白露|星|穹|桑博|伦纳德|停云|罗刹|卡芙卡|彦卿|史瓦罗|螺丝咕姆|阿兰|银狼|素裳|丹枢|黑塔|景元|帕姆|可可利亚|半夏|符玄|公输师傅|奥列格|青雀|大毫|青镞|费斯曼|绿芙蓉|镜流|信使|丽塔|失落迷迭|缭乱星棘|伊甸|伏特加女孩|狂热蓝调|莉莉娅|萝莎莉娅|八重樱|八重霞|卡莲|第六夜想曲|卡萝尔|姬子|极地战刃|布洛妮娅|次生银翼|理之律者|真理之律者|迷城骇兔|希儿|魇夜星渊|黑希儿|帕朵菲莉丝|天元骑英|幽兰黛尔|德丽莎|月下初拥|朔夜观星|暮光骑士|明日香|李素裳|格蕾修|梅比乌斯|渡鸦|人之律者|爱莉希雅|爱衣|天穹游侠|琪亚娜|空之律者|终焉之律者|薪炎之律者|云墨丹心|符华|识之律者|维尔薇|始源之律者|芽衣|雷之律者|苏莎娜|阿波尼亚|陆景和|莫弈|夏彦|左然]说我测尼玛
|
||||
|
||||
</details>
|
||||
<details>
|
||||
@ -1610,7 +1610,7 @@ print("run[CQ:image,file="+j["img"]+"]")
|
||||
- [x] 随机污句子
|
||||
- [x] 随机美句
|
||||
- [x] 土味情话
|
||||
- [x] 让[丁真|陈泽|梅西|孙笑川|科比|懒羊羊|胡桃|雫るる]说我测尼玛
|
||||
- [x] 让[lulu]说我测尼玛
|
||||
|
||||
</details>
|
||||
|
||||
@ -1633,7 +1633,7 @@ print("run[CQ:image,file="+j["img"]+"]")
|
||||
|
||||
- [x] @Bot 任意文本(任意一句话回复)
|
||||
|
||||
- [x] 设置回复模式[青云客 | 小爱 | ChatGPT]
|
||||
- [x] 设置文字回复模式[婧枫|沫沫|青云客|小爱|ChatGPT]
|
||||
|
||||
- [x] 设置 ChatGPT api key xxx
|
||||
|
||||
|
||||
2
go.mod
2
go.mod
@ -4,7 +4,7 @@ go 1.20
|
||||
|
||||
require (
|
||||
github.com/Baidu-AIP/golang-sdk v1.1.1
|
||||
github.com/FloatTech/AnimeAPI v1.7.1-0.20240411073357-0be3d9a5706d
|
||||
github.com/FloatTech/AnimeAPI v1.7.1-0.20240423052513-58ad4b85322a
|
||||
github.com/FloatTech/floatbox v0.0.0-20240304064110-78a83f1af9a6
|
||||
github.com/FloatTech/gg v1.1.3-0.20230226151425-6ea91286ba08
|
||||
github.com/FloatTech/imgfactory v0.2.2-0.20230413152719-e101cc3606ef
|
||||
|
||||
4
go.sum
4
go.sum
@ -2,8 +2,8 @@ github.com/Baidu-AIP/golang-sdk v1.1.1 h1:RQsAmgDSAkiq22I6n7XJ2t3afgzFeqjY46FGhv
|
||||
github.com/Baidu-AIP/golang-sdk v1.1.1/go.mod h1:bXnGw7xPeKt8aF7UCELKrV6UZ/46spItONK1RQBQj1Y=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
||||
github.com/FloatTech/AnimeAPI v1.7.1-0.20240411073357-0be3d9a5706d h1:eKJxkCzayyHPvQ7+uhF6acGBTnoq5c9K7J6sHbv6xwQ=
|
||||
github.com/FloatTech/AnimeAPI v1.7.1-0.20240411073357-0be3d9a5706d/go.mod h1:bNHsYcUd1+Y5Al3CR6tdzKxcc0XLivXjmUsL9xG6sSw=
|
||||
github.com/FloatTech/AnimeAPI v1.7.1-0.20240423052513-58ad4b85322a h1:K+1RAkIBb+3kkSxSkSTdTugSIsXJXrjEbwuv/BwUsP8=
|
||||
github.com/FloatTech/AnimeAPI v1.7.1-0.20240423052513-58ad4b85322a/go.mod h1:bNHsYcUd1+Y5Al3CR6tdzKxcc0XLivXjmUsL9xG6sSw=
|
||||
github.com/FloatTech/floatbox v0.0.0-20240304064110-78a83f1af9a6 h1:Vaj8ulVbN8vTD4W7aj+BYeT6x8iKFneDnkgBCezomDY=
|
||||
github.com/FloatTech/floatbox v0.0.0-20240304064110-78a83f1af9a6/go.mod h1:TeTlp+hTxpJti4JSdmUqzxGEr4wUBOVct9YWBepilpc=
|
||||
github.com/FloatTech/gg v1.1.3-0.20230226151425-6ea91286ba08 h1:dPLeoiTVSBlgls+66EB/UJ2e38BaASmBN5nANaycSBU=
|
||||
|
||||
@ -11,28 +11,29 @@ import (
|
||||
"github.com/FloatTech/AnimeAPI/tts"
|
||||
"github.com/FloatTech/AnimeAPI/tts/baidutts"
|
||||
"github.com/FloatTech/AnimeAPI/tts/genshin"
|
||||
"github.com/FloatTech/AnimeAPI/tts/lolimi"
|
||||
"github.com/FloatTech/AnimeAPI/tts/ttscn"
|
||||
ctrl "github.com/FloatTech/zbpctrl"
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
)
|
||||
|
||||
// 数据结构: [4 bits] [4 bits] [8 bits] [8 bits]
|
||||
// [ttscn模式] [百度模式] [tts模式] [回复模式]
|
||||
// 数据结构: [8 bits] [8 bits] [8 bits]
|
||||
// [具体人物] [tts模式] [回复模式]
|
||||
|
||||
// defaultttsindexkey
|
||||
// 数据结构: [4 bits] [4 bits] [8 bits]
|
||||
// [ttscn模式] [百度模式] [tts模式]
|
||||
// 数据结构: [8 bits] [8 bits]
|
||||
// [具体人物] [tts模式]
|
||||
|
||||
// [tts模式]: 0~200 genshin 201 baidu 202 ttscn
|
||||
// [tts模式]: 0~200 genshin 201 baidu 202 ttscn 203 lolimi
|
||||
|
||||
const (
|
||||
lastgsttsindex = 200 + iota
|
||||
baiduttsindex
|
||||
baiduttsindex = 201 + iota
|
||||
ttscnttsindex
|
||||
lolimittsindex
|
||||
)
|
||||
|
||||
// extrattsname is the tts other than genshin vits
|
||||
var extrattsname = []string{"百度", "TTSCN"}
|
||||
var extrattsname = []string{"百度", "TTSCN", "桑帛云"}
|
||||
|
||||
var ttscnspeakers = [...]string{
|
||||
"晓晓(女 - 年轻人)",
|
||||
@ -84,7 +85,7 @@ func (r replymode) setReplyMode(ctx *zero.Ctx, name string) error {
|
||||
if !ok {
|
||||
return errors.New("no such plugin")
|
||||
}
|
||||
return m.SetData(gid, (m.GetData(index)&^0xff)|(index&0xff))
|
||||
return m.SetData(gid, (m.GetData(gid)&^0xff)|(index&0xff))
|
||||
}
|
||||
|
||||
func (r replymode) getReplyMode(ctx *zero.Ctx) aireply.AIReply {
|
||||
@ -96,18 +97,22 @@ func (r replymode) getReplyMode(ctx *zero.Ctx) aireply.AIReply {
|
||||
if ok {
|
||||
switch m.GetData(gid) & 0xff {
|
||||
case 0:
|
||||
return aireply.NewQYK(aireply.QYKURL, aireply.QYKBotName)
|
||||
return aireply.NewLolimiAi(aireply.JingfengURL, aireply.JingfengBotName)
|
||||
case 1:
|
||||
return aireply.NewXiaoAi(aireply.XiaoAiURL, aireply.XiaoAiBotName)
|
||||
return aireply.NewLolimiAi(aireply.MomoURL, aireply.MomoBotName)
|
||||
case 2:
|
||||
return aireply.NewQYK(aireply.QYKURL, aireply.QYKBotName)
|
||||
case 3:
|
||||
return aireply.NewXiaoAi(aireply.XiaoAiURL, aireply.XiaoAiBotName)
|
||||
case 4:
|
||||
k := ཆཏ.k
|
||||
if k != "" {
|
||||
return aireply.NewChatGPT(aireply.ChatGPTURL, k)
|
||||
}
|
||||
return aireply.NewQYK(aireply.QYKURL, aireply.QYKBotName)
|
||||
return aireply.NewLolimiAi(aireply.JingfengURL, aireply.JingfengBotName)
|
||||
}
|
||||
}
|
||||
return aireply.NewQYK(aireply.QYKURL, aireply.QYKBotName)
|
||||
return aireply.NewLolimiAi(aireply.JingfengURL, aireply.JingfengBotName)
|
||||
}
|
||||
|
||||
var ttsins = func() map[string]tts.TTS {
|
||||
@ -119,7 +124,7 @@ var ttsins = func() map[string]tts.TTS {
|
||||
}()
|
||||
|
||||
var ttsModes = func() []string {
|
||||
s := append(genshin.SoundList[:], make([]string, lastgsttsindex-len(genshin.SoundList))...) // 0-200
|
||||
s := append(genshin.SoundList[:], make([]string, baiduttsindex-len(genshin.SoundList))...) // 0-200
|
||||
s = append(s, extrattsname...) // 201 202 ...
|
||||
return s
|
||||
}()
|
||||
@ -146,14 +151,14 @@ func newttsmode() *ttsmode {
|
||||
if ok {
|
||||
index := m.GetData(defaultttsindexkey)
|
||||
msk := index & 0xff
|
||||
if msk >= 0 && (msk < int64(len(genshin.SoundList)) || msk == baiduttsindex || msk == ttscnttsindex) {
|
||||
if msk >= 0 && (msk < int64(len(ttsModes))) {
|
||||
(*syncx.Map[int64, int64])(t).Store(defaultttsindexkey, index)
|
||||
}
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *ttsmode) setSoundMode(ctx *zero.Ctx, name string, baiduper, mockingsynt int) error {
|
||||
func (t *ttsmode) setSoundMode(ctx *zero.Ctx, name string, character int) error {
|
||||
gid := ctx.Event.GroupID
|
||||
if gid == 0 {
|
||||
gid = -ctx.Event.UserID
|
||||
@ -165,7 +170,7 @@ func (t *ttsmode) setSoundMode(ctx *zero.Ctx, name string, baiduper, mockingsynt
|
||||
var index = int64(-1)
|
||||
for i, s := range genshin.SoundList {
|
||||
if s == name {
|
||||
index = int64(i)
|
||||
index = int64(i + 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -175,13 +180,17 @@ func (t *ttsmode) setSoundMode(ctx *zero.Ctx, name string, baiduper, mockingsynt
|
||||
index = baiduttsindex
|
||||
case extrattsname[1]:
|
||||
index = ttscnttsindex
|
||||
case extrattsname[2]:
|
||||
index = lolimittsindex
|
||||
default:
|
||||
return errors.New("语音人物" + name + "未注册index")
|
||||
}
|
||||
}
|
||||
m := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
|
||||
(*syncx.Map[int64, int64])(t).Store(gid, index)
|
||||
return m.SetData(gid, (m.GetData(gid)&^0xffff00)|((index<<8)&0xff00)|((int64(baiduper)<<16)&0x0f0000)|((int64(mockingsynt)<<20)&0xf00000))
|
||||
//按原来的逻辑map存的是前16位
|
||||
storeIndex := (m.GetData(gid) &^ 0xffff00) | ((index << 8) & 0xff00) | ((int64(character) << 16) & 0xff0000)
|
||||
(*syncx.Map[int64, int64])(t).Store(gid, (storeIndex>>8)&0xffff)
|
||||
return m.SetData(gid, storeIndex)
|
||||
}
|
||||
|
||||
func (t *ttsmode) getSoundMode(ctx *zero.Ctx) (tts.TTS, error) {
|
||||
@ -195,8 +204,12 @@ func (t *ttsmode) getSoundMode(ctx *zero.Ctx) (tts.TTS, error) {
|
||||
i = m.GetData(gid) >> 8
|
||||
}
|
||||
m := i & 0xff
|
||||
if m < 0 || (m >= int64(len(genshin.SoundList)) && m != baiduttsindex && m != ttscnttsindex) {
|
||||
if m <= 0 || (m >= int64(len(ttsModes))) {
|
||||
i, _ = (*syncx.Map[int64, int64])(t).Load(defaultttsindexkey)
|
||||
if i == 0 {
|
||||
i = ctx.State["manager"].(*ctrl.Control[*zero.Ctx]).GetData(defaultttsindexkey)
|
||||
(*syncx.Map[int64, int64])(t).Store(defaultttsindexkey, i)
|
||||
}
|
||||
m = i & 0xff
|
||||
}
|
||||
mode := ttsModes[m]
|
||||
@ -205,20 +218,22 @@ func (t *ttsmode) getSoundMode(ctx *zero.Ctx) (tts.TTS, error) {
|
||||
switch mode {
|
||||
case extrattsname[0]:
|
||||
id, sec, _ := strings.Cut(百.k, ",")
|
||||
ins = baidutts.NewBaiduTTS(int(i&0x0f00)>>8, id, sec)
|
||||
ins = baidutts.NewBaiduTTS(int(i&0xff00)>>8, id, sec)
|
||||
case extrattsname[1]:
|
||||
var err error
|
||||
ins, err = ttscn.NewTTSCN("中文(普通话,简体)", ttscnspeakers[int(i&0xf000)>>12], ttscn.KBRates[0])
|
||||
ins, err = ttscn.NewTTSCN("中文(普通话,简体)", ttscnspeakers[int(i&0xff00)>>8], ttscn.KBRates[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case extrattsname[2]:
|
||||
ins = lolimi.NewLolimi(int(i&0xff00) >> 8)
|
||||
default: // 原神
|
||||
k := 原.k
|
||||
if k != "" {
|
||||
ins = genshin.NewGenshin(int(m), 原.k)
|
||||
ins = genshin.NewGenshin(int(m-1), 原.k)
|
||||
ttsins[mode] = ins
|
||||
} else {
|
||||
return nil, errors.New("no valid speaker")
|
||||
ins = lolimi.NewLolimi(int(i&0xff00) >> 8)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -231,11 +246,12 @@ func (t *ttsmode) resetSoundMode(ctx *zero.Ctx) error {
|
||||
gid = -ctx.Event.UserID
|
||||
}
|
||||
m := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
|
||||
index := m.GetData(defaultttsindexkey)
|
||||
return m.SetData(gid, (m.GetData(gid)&0xff)|((index&^0xff)<<8)) // 重置数据
|
||||
// 只保留后面8位
|
||||
(*syncx.Map[int64, int64])(t).Delete(gid)
|
||||
return m.SetData(gid, (m.GetData(gid) & 0xff)) // 重置数据
|
||||
}
|
||||
|
||||
func (t *ttsmode) setDefaultSoundMode(name string, baiduper, mockingsynt int) error {
|
||||
func (t *ttsmode) setDefaultSoundMode(name string, character int) error {
|
||||
_, ok := ttsins[name]
|
||||
if !ok {
|
||||
return errors.New("不支持设置语音人物" + name)
|
||||
@ -243,7 +259,7 @@ func (t *ttsmode) setDefaultSoundMode(name string, baiduper, mockingsynt int) er
|
||||
index := int64(-1)
|
||||
for i, s := range genshin.SoundList {
|
||||
if s == name {
|
||||
index = int64(i)
|
||||
index = int64(i + 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -253,6 +269,8 @@ func (t *ttsmode) setDefaultSoundMode(name string, baiduper, mockingsynt int) er
|
||||
index = baiduttsindex
|
||||
case extrattsname[1]:
|
||||
index = ttscnttsindex
|
||||
case extrattsname[2]:
|
||||
index = lolimittsindex
|
||||
default:
|
||||
return errors.New("语音人物" + name + "未注册index")
|
||||
}
|
||||
@ -261,6 +279,7 @@ func (t *ttsmode) setDefaultSoundMode(name string, baiduper, mockingsynt int) er
|
||||
if !ok {
|
||||
return errors.New("[tts] service not found")
|
||||
}
|
||||
(*syncx.Map[int64, int64])(t).Store(defaultttsindexkey, index)
|
||||
return m.SetData(defaultttsindexkey, (index&0xff)|((int64(baiduper)<<8)&0x0f00)|((int64(mockingsynt)<<12)&0xf000))
|
||||
storeIndex := (index & 0xff) | ((int64(character) << 8) & 0xff00)
|
||||
(*syncx.Map[int64, int64])(t).Store(defaultttsindexkey, storeIndex)
|
||||
return m.SetData(defaultttsindexkey, storeIndex)
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/tts/genshin"
|
||||
@ -16,7 +17,7 @@ import (
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
|
||||
var replmd = replymode([]string{"青云客", "小爱", "ChatGPT"})
|
||||
var replmd = replymode([]string{"婧枫", "沫沫", "青云客", "小爱", "ChatGPT"})
|
||||
|
||||
var ttsmd = newttsmode()
|
||||
|
||||
@ -25,9 +26,10 @@ func init() { // 插件主体
|
||||
DisableOnDefault: true,
|
||||
Brief: "人工智能语音回复",
|
||||
Help: "- @Bot 任意文本(任意一句话回复)\n" +
|
||||
"- 设置语音模式[原神人物/百度/TTSCN] 数字(百度/TTSCN说话人)\n" +
|
||||
"- 设置默认语音模式[原神人物/百度/TTSCN] 数字(百度/TTSCN说话人)\n" +
|
||||
"- 设置语音模式[原神人物/百度/TTSCN/桑帛云] 数字(百度/TTSCN说话人/桑帛云)\n" +
|
||||
"- 设置默认语音模式[原神人物/百度/TTSCN/桑帛云] 数字(百度/TTSCN说话人/桑帛云)\n" +
|
||||
"- 恢复成默认语音模式\n" +
|
||||
"- 设置语音回复模式[沫沫|婧枫|青云客|小爱|ChatGPT]\n" +
|
||||
"- 设置原神语音 api key xxxxxx (key请加开发群获得)\n" +
|
||||
"- 设置百度语音 api id xxxxxx secret xxxxxx (请自行获得)\n" +
|
||||
"当前适用的原神人物含有以下: \n" + list(genshin.SoundList[:], 5) +
|
||||
@ -38,7 +40,7 @@ func init() { // 插件主体
|
||||
enr := control.Register("aireply", &ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "人工智能回复",
|
||||
Help: "- @Bot 任意文本(任意一句话回复)\n- 设置回复模式[青云客|小爱|ChatGPT]\n- 设置 ChatGPT api key xxx",
|
||||
Help: "- @Bot 任意文本(任意一句话回复)\n- 设置文字回复模式[婧枫|沫沫|青云客|小爱|ChatGPT]\n- 设置 ChatGPT api key xxx",
|
||||
PrivateDataFolder: "aireply",
|
||||
})
|
||||
|
||||
@ -48,15 +50,10 @@ func init() { // 插件主体
|
||||
reply := message.ParseMessageFromString(aireply.Talk(ctx.Event.UserID, ctx.ExtractPlainText(), zero.BotConfig.NickName[0]))
|
||||
// 回复
|
||||
time.Sleep(time.Second * 1)
|
||||
if zero.OnlyPublic(ctx) {
|
||||
reply = append(reply, message.Reply(ctx.Event.MessageID))
|
||||
ctx.Send(reply)
|
||||
return
|
||||
}
|
||||
ctx.Send(reply)
|
||||
})
|
||||
|
||||
enr.OnPrefix("设置回复模式", zero.AdminPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||
setReplyMode := func(ctx *zero.Ctx) {
|
||||
param := ctx.State["args"].(string)
|
||||
err := replmd.setReplyMode(ctx, param)
|
||||
if err != nil {
|
||||
@ -64,8 +61,8 @@ func init() { // 插件主体
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("成功"))
|
||||
})
|
||||
|
||||
}
|
||||
enr.OnPrefix("设置文字回复模式", zero.AdminPermission).SetBlock(true).Handle(setReplyMode)
|
||||
enr.OnRegex(`^设置\s*ChatGPT\s*api\s*key\s*(.*)$`, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||
err := ཆཏ.set(ctx.State["regex_matched"].([]string)[1])
|
||||
if err != nil {
|
||||
@ -88,7 +85,20 @@ func init() { // 插件主体
|
||||
// 获取回复模式
|
||||
r := replmd.getReplyMode(ctx)
|
||||
// 获取回复的文本
|
||||
reply := r.TalkPlain(ctx.Event.UserID, msg, zero.BotConfig.NickName[0])
|
||||
reply := message.ParseMessageFromString(r.TalkPlain(ctx.Event.UserID, msg, zero.BotConfig.NickName[0]))
|
||||
// 过滤掉文字消息
|
||||
filterMsg := make([]message.MessageSegment, 0, len(reply))
|
||||
sb := strings.Builder{}
|
||||
for _, v := range reply {
|
||||
if v.Type != "text" {
|
||||
filterMsg = append(filterMsg, v)
|
||||
} else {
|
||||
sb.WriteString(v.Data["text"])
|
||||
}
|
||||
}
|
||||
// 纯文本
|
||||
plainReply := sb.String()
|
||||
plainReply = strings.ReplaceAll(plainReply, "\n", "")
|
||||
// 获取语音
|
||||
speaker, err := ttsmd.getSoundMode(ctx)
|
||||
if err != nil {
|
||||
@ -96,21 +106,26 @@ func init() { // 插件主体
|
||||
return
|
||||
}
|
||||
rec, err := speaker.Speak(ctx.Event.UserID, func() string {
|
||||
if !endpre.MatchString(reply) {
|
||||
return reply + "。"
|
||||
if !endpre.MatchString(plainReply) {
|
||||
return plainReply + "。"
|
||||
}
|
||||
return reply
|
||||
return plainReply
|
||||
})
|
||||
// 发送前面的图片
|
||||
if len(filterMsg) != 0 {
|
||||
filterMsg = append(filterMsg, message.Reply(ctx.Event.MessageID))
|
||||
ctx.Send(filterMsg)
|
||||
}
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(reply))
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(plainReply))
|
||||
return
|
||||
}
|
||||
// 发送语音
|
||||
if id := ctx.SendChain(message.Record(rec)); id.ID() == 0 {
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(reply))
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(plainReply))
|
||||
}
|
||||
})
|
||||
|
||||
ent.OnPrefix("设置语音回复模式", zero.AdminPermission).SetBlock(true).Handle(setReplyMode)
|
||||
ent.OnRegex(`^设置语音模式\s*([\S\D]*)\s+(\d*)$`, zero.AdminPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||
param := ctx.State["regex_matched"].([]string)[1]
|
||||
num := ctx.State["regex_matched"].([]string)[2]
|
||||
@ -124,8 +139,8 @@ func init() { // 插件主体
|
||||
}
|
||||
}
|
||||
// 保存设置
|
||||
logrus.Debugln("[tts] t.setSoundMode( ctx", param, n, n, ")")
|
||||
err = ttsmd.setSoundMode(ctx, param, n, n)
|
||||
logrus.Debugln("[tts] t.setSoundMode( ctx", param, n, ")")
|
||||
err = ttsmd.setSoundMode(ctx, param, n)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(err))
|
||||
return
|
||||
@ -153,7 +168,7 @@ func init() { // 插件主体
|
||||
return
|
||||
}
|
||||
time.Sleep(time.Second * 2)
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("设置成功"))
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("设置成功,当前为", speaker))
|
||||
})
|
||||
|
||||
ent.OnRegex(`^设置默认语音模式\s*([\S\D]*)\s+(\d*)$`, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||
@ -169,7 +184,7 @@ func init() { // 插件主体
|
||||
}
|
||||
}
|
||||
// 保存设置
|
||||
err = ttsmd.setDefaultSoundMode(param, n, n)
|
||||
err = ttsmd.setDefaultSoundMode(param, n)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(err))
|
||||
return
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/tts/lolimi"
|
||||
"github.com/FloatTech/floatbox/binary"
|
||||
"github.com/FloatTech/floatbox/web"
|
||||
ctrl "github.com/FloatTech/zbpctrl"
|
||||
@ -19,9 +20,6 @@ import (
|
||||
|
||||
const (
|
||||
lolimiURL = "https://api.lolimi.cn"
|
||||
jiaranURL = lolimiURL + "/API/yyhc/jr.php?msg=%v&type=2"
|
||||
tafeiURL = lolimiURL + "/API/yyhc/taf.php?msg=%v&type=2"
|
||||
dxlURL = lolimiURL + "/API/yyhc/dxl.php?msg=%v&type=2"
|
||||
raoURL = lolimiURL + "/API/rao/api.php"
|
||||
yanURL = lolimiURL + "/API/yan/?url=%v"
|
||||
xjjURL = lolimiURL + "/API/tup/xjj.php"
|
||||
@ -33,7 +31,7 @@ var (
|
||||
engine = control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "桑帛云 API",
|
||||
Help: "- 让[塔菲|嘉然|东雪莲]说我测尼玛\n- 随机绕口令\n- 颜值鉴定[图片]\n" +
|
||||
Help: "- 让[嘉然|塔菲|东雪莲|懒羊羊|科比|孙笑川|陈泽|丁真|空|荧|派蒙|纳西妲|阿贝多|温迪|枫原万叶|钟离|荒泷一斗|八重神子|艾尔海森|提纳里|迪希雅|卡维|宵宫|莱依拉|赛诺|诺艾尔|托马|凝光|莫娜|北斗|神里绫华|雷电将军|芭芭拉|鹿野院平藏|五郎|迪奥娜|凯亚|安柏|班尼特|琴|柯莱|夜兰|妮露|辛焱|珐露珊|魈|香菱|达达利亚|砂糖|早柚|云堇|刻晴|丽莎|迪卢克|烟绯|重云|珊瑚宫心海|胡桃|可莉|流浪者|久岐忍|神里绫人|甘雨|戴因斯雷布|优菈|菲谢尔|行秋|白术|九条裟罗|雷泽|申鹤|迪娜泽黛|凯瑟琳|多莉|坎蒂丝|萍姥姥|罗莎莉亚|留云借风真君|绮良良|瑶瑶|七七|奥兹|米卡|夏洛蒂|埃洛伊|博士|女士|大慈树王|三月七|娜塔莎|希露瓦|虎克|克拉拉|丹恒|希儿|布洛妮娅|瓦尔特|杰帕德|佩拉|姬子|艾丝妲|白露|星|穹|桑博|伦纳德|停云|罗刹|卡芙卡|彦卿|史瓦罗|螺丝咕姆|阿兰|银狼|素裳|丹枢|黑塔|景元|帕姆|可可利亚|半夏|符玄|公输师傅|奥列格|青雀|大毫|青镞|费斯曼|绿芙蓉|镜流|信使|丽塔|失落迷迭|缭乱星棘|伊甸|伏特加女孩|狂热蓝调|莉莉娅|萝莎莉娅|八重樱|八重霞|卡莲|第六夜想曲|卡萝尔|姬子|极地战刃|布洛妮娅|次生银翼|理之律者|真理之律者|迷城骇兔|希儿|魇夜星渊|黑希儿|帕朵菲莉丝|天元骑英|幽兰黛尔|德丽莎|月下初拥|朔夜观星|暮光骑士|明日香|李素裳|格蕾修|梅比乌斯|渡鸦|人之律者|爱莉希雅|爱衣|天穹游侠|琪亚娜|空之律者|终焉之律者|薪炎之律者|云墨丹心|符华|识之律者|维尔薇|始源之律者|芽衣|雷之律者|苏莎娜|阿波尼亚|陆景和|莫弈|夏彦|左然]说我测尼玛\n- 随机绕口令\n- 颜值鉴定[图片]\n" +
|
||||
"- 随机妹子\n- 随机情话\n- 发病 嘉然\n\n说明: 颜值鉴定只能鉴定三次元图片",
|
||||
})
|
||||
)
|
||||
@ -100,33 +98,15 @@ func init() {
|
||||
ctx.SendChain(message.Text(text.String())) // 发送构建好的字符串
|
||||
}
|
||||
})
|
||||
engine.OnRegex("^让(塔菲|嘉然|东雪莲)说([\\s\u4e00-\u9fa5\u3040-\u309F\u30A0-\u30FF\\w\\p{P}\u3000-\u303F\uFF00-\uFFEF]+)$").Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) {
|
||||
engine.OnRegex("^让(嘉然|塔菲|东雪莲|懒羊羊|科比|孙笑川|陈泽|丁真|空|荧|派蒙|纳西妲|阿贝多|温迪|枫原万叶|钟离|荒泷一斗|八重神子|艾尔海森|提纳里|迪希雅|卡维|宵宫|莱依拉|赛诺|诺艾尔|托马|凝光|莫娜|北斗|神里绫华|雷电将军|芭芭拉|鹿野院平藏|五郎|迪奥娜|凯亚|安柏|班尼特|琴|柯莱|夜兰|妮露|辛焱|珐露珊|魈|香菱|达达利亚|砂糖|早柚|云堇|刻晴|丽莎|迪卢克|烟绯|重云|珊瑚宫心海|胡桃|可莉|流浪者|久岐忍|神里绫人|甘雨|戴因斯雷布|优菈|菲谢尔|行秋|白术|九条裟罗|雷泽|申鹤|迪娜泽黛|凯瑟琳|多莉|坎蒂丝|萍姥姥|罗莎莉亚|留云借风真君|绮良良|瑶瑶|七七|奥兹|米卡|夏洛蒂|埃洛伊|博士|女士|大慈树王|三月七|娜塔莎|希露瓦|虎克|克拉拉|丹恒|希儿|布洛妮娅|瓦尔特|杰帕德|佩拉|姬子|艾丝妲|白露|星|穹|桑博|伦纳德|停云|罗刹|卡芙卡|彦卿|史瓦罗|螺丝咕姆|阿兰|银狼|素裳|丹枢|黑塔|景元|帕姆|可可利亚|半夏|符玄|公输师傅|奥列格|青雀|大毫|青镞|费斯曼|绿芙蓉|镜流|信使|丽塔|失落迷迭|缭乱星棘|伊甸|伏特加女孩|狂热蓝调|莉莉娅|萝莎莉娅|八重樱|八重霞|卡莲|第六夜想曲|卡萝尔|姬子|极地战刃|布洛妮娅|次生银翼|理之律者|真理之律者|迷城骇兔|希儿|魇夜星渊|黑希儿|帕朵菲莉丝|天元骑英|幽兰黛尔|德丽莎|月下初拥|朔夜观星|暮光骑士|明日香|李素裳|格蕾修|梅比乌斯|渡鸦|人之律者|爱莉希雅|爱衣|天穹游侠|琪亚娜|空之律者|终焉之律者|薪炎之律者|云墨丹心|符华|识之律者|维尔薇|始源之律者|芽衣|雷之律者|苏莎娜|阿波尼亚|陆景和|莫弈|夏彦|左然)说([\\s\u4e00-\u9fa5\u3040-\u309F\u30A0-\u30FF\\w\\p{P}\u3000-\u303F\uFF00-\uFFEF]+)$").Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) {
|
||||
name := ctx.State["regex_matched"].([]string)[1]
|
||||
msg := ctx.State["regex_matched"].([]string)[2]
|
||||
recordURL := ""
|
||||
switch name {
|
||||
case "塔菲", "东雪莲":
|
||||
ttsURL := ""
|
||||
if name == "塔菲" {
|
||||
ttsURL = tafeiURL
|
||||
} else {
|
||||
ttsURL = dxlURL
|
||||
}
|
||||
data, err := web.GetData(fmt.Sprintf(ttsURL, url.QueryEscape(msg)))
|
||||
ctx.SendChain(message.Text("少女祈祷中......"))
|
||||
recordURL, err := lolimi.TTS(name, msg)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
recordURL = gjson.Get(binary.BytesToString(data), "music").String()
|
||||
case "嘉然":
|
||||
recordURL = fmt.Sprintf(jiaranURL, url.QueryEscape(msg))
|
||||
default:
|
||||
recordURL = fmt.Sprintf(jiaranURL, url.QueryEscape(msg))
|
||||
}
|
||||
if recordURL == "" {
|
||||
ctx.SendChain(message.Text("ERROR: 语音生成失败"))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Record(recordURL))
|
||||
})
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ func init() {
|
||||
text = strings.ReplaceAll(text, "</p>", "")
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(text))
|
||||
})
|
||||
engine.OnRegex("^让(丁真|陈泽|梅西|孙笑川|科比|懒羊羊|胡桃|雫るる)说([\\s\u4e00-\u9fa5\u3040-\u309F\u30A0-\u30FF\\w\\p{P}\u3000-\u303F\uFF00-\uFFEF]+)$").Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) {
|
||||
engine.OnRegex("^让(lulu)说([\\s\u4e00-\u9fa5\u3040-\u309F\u30A0-\u30FF\\w\\p{P}\u3000-\u303F\uFF00-\uFFEF]+)$").Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) {
|
||||
name := ctx.State["regex_matched"].([]string)[1]
|
||||
msg := ctx.State["regex_matched"].([]string)[2]
|
||||
data, err := web.GetData(fmt.Sprintf(yuyinURL, url.QueryEscape(name), url.QueryEscape(msg)))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user