fix: nwife dup slash & genshin vits

This commit is contained in:
源文雨 2022-10-10 10:12:23 +08:00
parent c4c3f79c8c
commit 77f7567b29
4 changed files with 16 additions and 17 deletions

View File

@ -12,7 +12,7 @@ import (
) )
const ( const (
cnapi = "http://233366.proxy.nscc-gz.cn:8888?speaker=%s&text=%s" cnapi = "https://genshin.azurewebsites.net/api/speak?format=mp3&id=%d&text=%s"
// testString = "这是测试语音......" // testString = "这是测试语音......"
) )
@ -133,14 +133,14 @@ func (tts *ttsmode) setSoundMode(ctx *zero.Ctx, name string) error {
return m.SetData(gid, int64(i)) return m.SetData(gid, int64(i))
} }
func (tts *ttsmode) getSoundMode(ctx *zero.Ctx) (name string) { func (tts *ttsmode) getSoundMode(ctx *zero.Ctx) (i int64) {
gid := ctx.Event.GroupID gid := ctx.Event.GroupID
if gid == 0 { if gid == 0 {
gid = -ctx.Event.UserID gid = -ctx.Event.UserID
} }
tts.RLock() tts.RLock()
defer tts.RUnlock() defer tts.RUnlock()
return soundList[tts.mode[gid]] return tts.mode[gid]
} }
func (tts *ttsmode) resetSoundMode(ctx *zero.Ctx) { func (tts *ttsmode) resetSoundMode(ctx *zero.Ctx) {

View File

@ -43,10 +43,8 @@ func init() { // 插件主体
r := aireply.NewAIReply(getReplyMode(ctx)) r := aireply.NewAIReply(getReplyMode(ctx))
// 获取回复的文本 // 获取回复的文本
reply := r.TalkPlain(msg, zero.BotConfig.NickName[0]) reply := r.TalkPlain(msg, zero.BotConfig.NickName[0])
// 获取角色
name := tts.getSoundMode(ctx)
// 获取语音 // 获取语音
record := message.Record(fmt.Sprintf(cnapi, url.QueryEscape(name), url.QueryEscape( record := message.Record(fmt.Sprintf(cnapi, tts.getSoundMode(ctx), url.QueryEscape(
// 将数字转文字 // 将数字转文字
re.ReplaceAllStringFunc(reply, func(s string) string { re.ReplaceAllStringFunc(reply, func(s string) string {
f, err := strconv.ParseFloat(s, 64) f, err := strconv.ParseFloat(s, 64)
@ -81,12 +79,12 @@ func init() { // 插件主体
return return
} }
// 设置验证 // 设置验证
name := tts.getSoundMode(ctx) i := tts.getSoundMode(ctx)
if _, ok := testRecord[name]; !ok { if _, ok := testRecord[soundList[i]]; !ok {
ctx.SendChain(message.Text("配置的语音人物数据丢失!请重新设置语音人物。")) ctx.SendChain(message.Text("配置的语音人物数据丢失!请重新设置语音人物。"))
return return
} }
record := message.Record(fmt.Sprintf(cnapi, url.QueryEscape(name), url.QueryEscape(testRecord[name]))).Add("cache", 0) record := message.Record(fmt.Sprintf(cnapi, i, url.QueryEscape(testRecord[soundList[i]]))).Add("cache", 0)
if ID := ctx.SendChain(record); ID.ID() == 0 { if ID := ctx.SendChain(record); ID.ID() == 0 {
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("设置失败!无法发送测试语音,请重试。")) ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("设置失败!无法发送测试语音,请重试。"))
return return

View File

@ -16,12 +16,13 @@ import (
const ( const (
jpapi = "https://moegoe.azurewebsites.net/api/speak?text=%s&id=%d" jpapi = "https://moegoe.azurewebsites.net/api/speak?text=%s&id=%d"
krapi = "https://moegoe.azurewebsites.net/api/speakkr?text=%s&id=%d" krapi = "https://moegoe.azurewebsites.net/api/speakkr?text=%s&id=%d"
cnapi = "http://233366.proxy.nscc-gz.cn:8888?speaker=%s&text=%s" cnapi = "https://genshin.azurewebsites.net/api/speak?format=mp3&text=%s&id=%d"
) )
var speakers = map[string]uint{ var speakers = map[string]uint{
"宁宁": 0, "爱瑠": 1, "芳乃": 2, "茉子": 3, "丛雨": 4, "小春": 5, "七海": 6, "宁宁": 0, "爱瑠": 1, "芳乃": 2, "茉子": 3, "丛雨": 4, "小春": 5, "七海": 6,
"Sua": 0, "Mimiru": 1, "Arin": 2, "Yeonhwa": 3, "Yuhwa": 4, "Seonbae": 5, "Sua": 0, "Mimiru": 1, "Arin": 2, "Yeonhwa": 3, "Yuhwa": 4, "Seonbae": 5,
"派蒙": 0, "凯亚": 1, "安柏": 2, "丽莎": 3, "琴": 4, "香菱": 5, "枫原万叶": 6, "迪卢克": 7, "温迪": 8, "可莉": 9, "早柚": 10, "托马": 11, "芭芭拉": 12, "优菈": 13, "云堇": 14, "钟离": 15, "魈": 16, "凝光": 17, "雷电将军": 18, "北斗": 19, "甘雨": 20, "七七": 21, "刻晴": 22, "神里绫华": 23, "戴因斯雷布": 24, "雷泽": 25, "神里绫人": 26, "罗莎莉亚": 27, "阿贝多": 28, "八重神子": 29, "宵宫": 30, "荒泷一斗": 31, "九条裟罗": 32, "夜兰": 33, "珊瑚宫心海": 34, "五郎": 35, "散兵": 36, "女士": 37, "达达利亚": 38, "莫娜": 39, "班尼特": 40, "申鹤": 41, "行秋": 42, "烟绯": 43, "久岐忍": 44, "辛焱": 45, "砂糖": 46, "胡桃": 47, "重云": 48, "菲谢尔": 49, "诺艾尔": 50, "迪奥娜": 51, "鹿野院平藏": 52,
} }
func init() { func init() {
@ -46,8 +47,8 @@ func init() {
}) })
en.OnRegex("^让(派蒙|凯亚|安柏|丽莎|琴|香菱|枫原万叶|迪卢克|温迪|可莉|早柚|托马|芭芭拉|优菈|云堇|钟离|魈|凝光|雷电将军|北斗|甘雨|七七|刻晴|神里绫华|雷泽|神里绫人|罗莎莉亚|阿贝多|八重神子|宵宫|荒泷一斗|九条裟罗|夜兰|珊瑚宫心海|五郎|达达利亚|莫娜|班尼特|申鹤|行秋|烟绯|久岐忍|辛焱|砂糖|胡桃|重云|菲谢尔|诺艾尔|迪奥娜|鹿野院平藏)说([\\s\u4e00-\u9fa5\\pP]+)$").Limit(ctxext.LimitByGroup).SetBlock(true). en.OnRegex("^让(派蒙|凯亚|安柏|丽莎|琴|香菱|枫原万叶|迪卢克|温迪|可莉|早柚|托马|芭芭拉|优菈|云堇|钟离|魈|凝光|雷电将军|北斗|甘雨|七七|刻晴|神里绫华|雷泽|神里绫人|罗莎莉亚|阿贝多|八重神子|宵宫|荒泷一斗|九条裟罗|夜兰|珊瑚宫心海|五郎|达达利亚|莫娜|班尼特|申鹤|行秋|烟绯|久岐忍|辛焱|砂糖|胡桃|重云|菲谢尔|诺艾尔|迪奥娜|鹿野院平藏)说([\\s\u4e00-\u9fa5\\pP]+)$").Limit(ctxext.LimitByGroup).SetBlock(true).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
speaker := ctx.State["regex_matched"].([]string)[1]
text := ctx.State["regex_matched"].([]string)[2] text := ctx.State["regex_matched"].([]string)[2]
ctx.SendChain(message.Record(fmt.Sprintf(cnapi, url.QueryEscape(speaker), url.QueryEscape(text)))) id := speakers[ctx.State["regex_matched"].([]string)[1]]
ctx.SendChain(message.Record(fmt.Sprintf(cnapi, url.QueryEscape(text), id)))
}) })
} }

View File

@ -32,7 +32,7 @@ func init() {
engine.OnPrefix("抽wife", zero.OnlyGroup).SetBlock(true). engine.OnPrefix("抽wife", zero.OnlyGroup).SetBlock(true).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
grpf := strconv.FormatInt(ctx.Event.GroupID, 36) grpf := strconv.FormatInt(ctx.Event.GroupID, 36)
wifes, err := os.ReadDir(base + "/" + grpf) wifes, err := os.ReadDir(base + grpf)
if err != nil { if err != nil {
ctx.SendChain(message.Text("一个wife也没有哦~")) ctx.SendChain(message.Text("一个wife也没有哦~"))
return return
@ -42,7 +42,7 @@ func init() {
ctx.SendChain(message.Text("一个wife也没有哦~")) ctx.SendChain(message.Text("一个wife也没有哦~"))
case 1: case 1:
wn := wifes[0].Name() wn := wifes[0].Name()
ctx.SendChain(message.Text("大家的wife都是", wn, "\n"), message.Image(baseuri+"/"+grpf+"/"+wn), message.Text("\n哦~")) ctx.SendChain(message.Text("大家的wife都是", wn, "\n"), message.Image(baseuri+grpf+"/"+wn), message.Text("\n哦~"))
default: default:
// 获取名字 // 获取名字
name := ctx.NickName() name := ctx.NickName()
@ -51,7 +51,7 @@ func init() {
r := rand.New(rand.NewSource(int64(binary.LittleEndian.Uint64(s[:])))) r := rand.New(rand.NewSource(int64(binary.LittleEndian.Uint64(s[:]))))
n := r.Intn(len(wifes)) n := r.Intn(len(wifes))
wn := wifes[n].Name() wn := wifes[n].Name()
ctx.SendChain(message.Text(name, "的wife是", wn, "\n"), message.Image(baseuri+"/"+grpf+"/"+wn), message.Text("\n哦~")) ctx.SendChain(message.Text(name, "的wife是", wn, "\n"), message.Image(baseuri+grpf+"/"+wn), message.Text("\n哦~"))
} }
}) })
// 上传一张图 // 上传一张图
@ -69,7 +69,7 @@ func init() {
} }
if name != "" { if name != "" {
url := ctx.State["image_url"].([]string)[0] url := ctx.State["image_url"].([]string)[0]
grpfolder := base + "/" + strconv.FormatInt(ctx.Event.GroupID, 36) grpfolder := base + strconv.FormatInt(ctx.Event.GroupID, 36)
if file.IsNotExist(grpfolder) { if file.IsNotExist(grpfolder) {
err := os.Mkdir(grpfolder, 0755) err := os.Mkdir(grpfolder, 0755)
if err != nil { if err != nil {
@ -100,7 +100,7 @@ func init() {
} }
} }
if name != "" { if name != "" {
grpfolder := base + "/" + strconv.FormatInt(ctx.Event.GroupID, 36) grpfolder := base + strconv.FormatInt(ctx.Event.GroupID, 36)
err := os.Remove(grpfolder + "/" + name) err := os.Remove(grpfolder + "/" + name)
if err == nil { if err == nil {
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("成功!")) ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("成功!"))