Skip to content

Commit d76a65e

Browse files
committed
fix tts
1 parent ed7cef7 commit d76a65e

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

plugin/ai_reply/ai_tts.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,10 @@ func (tts *ttsmode) getAPIKey(ctx *zero.Ctx) string {
178178
return url.QueryEscape(tts.APIKey)
179179
}
180180

181-
func (tts *ttsmode) setAPIKey(ctx *zero.Ctx, key string) error {
182-
gid := ctx.Event.GroupID
183-
if gid == 0 {
184-
gid = -ctx.Event.UserID
185-
}
186-
m := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
187-
err := m.Manager.SetExtra(gid, &key)
181+
func (tts *ttsmode) setAPIKey(m *ctrl.Control[*zero.Ctx], grp int64, key string) error {
182+
err := m.Manager.SetExtra(grp, &key)
188183
if err != nil {
189-
return errors.New("内部错误")
184+
return err
190185
}
191186
tts.APIKey = key
192187
return nil

plugin/ai_reply/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func init() { // 插件主体
2727
"- 设置语音模式[原神人物]\n" +
2828
"- 设置默认语音模式[原神人物]\n" +
2929
"- 恢复成默认语音模式\n" +
30-
"- 设置原神语音 api key xxxxxx (key请加开发群获得)\n" +
30+
"- 为群 xxx 设置原神语音 api key xxxxxx (key请加开发群获得)\n" +
3131
"当前适用的原神人物含有以下:\n" + list(soundList[:], 5),
3232
})
3333
tts := newttsmode()
@@ -143,8 +143,9 @@ func init() { // 插件主体
143143
index := tts.getSoundMode(ctx)
144144
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("设置成功,当前为", soundList[index]))
145145
})
146-
ent.OnRegex(`^设置原神语音\s*api\s*key\s*([0-9a-zA-Z-_]{54}==)$`, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
147-
err := tts.setAPIKey(ctx, ctx.State["regex_matched"].([]string)[1])
146+
ent.OnRegex(`^为群\s*(-?\d+)\s*设置原神语音\s*api\s*key\s*([0-9a-zA-Z-_]{54}==)$`, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
147+
grp, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64)
148+
err := tts.setAPIKey(ctx.State["manager"].(*ctrl.Control[*zero.Ctx]), grp, ctx.State["regex_matched"].([]string)[2])
148149
if err != nil {
149150
ctx.SendChain(message.Text("ERROR: ", err))
150151
return

0 commit comments

Comments
 (0)