Skip to content

Commit

Permalink
fix tts
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Dec 7, 2022
1 parent ed7cef7 commit d76a65e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
11 changes: 3 additions & 8 deletions plugin/ai_reply/ai_tts.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,10 @@ func (tts *ttsmode) getAPIKey(ctx *zero.Ctx) string {
return url.QueryEscape(tts.APIKey)
}

func (tts *ttsmode) setAPIKey(ctx *zero.Ctx, key string) error {
gid := ctx.Event.GroupID
if gid == 0 {
gid = -ctx.Event.UserID
}
m := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
err := m.Manager.SetExtra(gid, &key)
func (tts *ttsmode) setAPIKey(m *ctrl.Control[*zero.Ctx], grp int64, key string) error {
err := m.Manager.SetExtra(grp, &key)
if err != nil {
return errors.New("内部错误")
return err
}
tts.APIKey = key
return nil
Expand Down
7 changes: 4 additions & 3 deletions plugin/ai_reply/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func init() { // 插件主体
"- 设置语音模式[原神人物]\n" +
"- 设置默认语音模式[原神人物]\n" +
"- 恢复成默认语音模式\n" +
"- 设置原神语音 api key xxxxxx (key请加开发群获得)\n" +
"- 为群 xxx 设置原神语音 api key xxxxxx (key请加开发群获得)\n" +
"当前适用的原神人物含有以下:\n" + list(soundList[:], 5),
})
tts := newttsmode()
Expand Down Expand Up @@ -143,8 +143,9 @@ func init() { // 插件主体
index := tts.getSoundMode(ctx)
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("设置成功,当前为", soundList[index]))
})
ent.OnRegex(`^设置原神语音\s*api\s*key\s*([0-9a-zA-Z-_]{54}==)$`, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) {
err := tts.setAPIKey(ctx, ctx.State["regex_matched"].([]string)[1])
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) {
grp, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64)
err := tts.setAPIKey(ctx.State["manager"].(*ctrl.Control[*zero.Ctx]), grp, ctx.State["regex_matched"].([]string)[2])
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
Expand Down

0 comments on commit d76a65e

Please sign in to comment.