diff --git a/plugin/ai_reply/ai_tts.go b/plugin/ai_reply/ai_tts.go index ab787135..0bdc5065 100644 --- a/plugin/ai_reply/ai_tts.go +++ b/plugin/ai_reply/ai_tts.go @@ -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 diff --git a/plugin/ai_reply/main.go b/plugin/ai_reply/main.go index 5c068192..ba25627e 100644 --- a/plugin/ai_reply/main.go +++ b/plugin/ai_reply/main.go @@ -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() @@ -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