From f56929c852df2d08b9e1e2aecd26e8c17ac9dc54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Wed, 14 Dec 2022 21:38:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=E8=AE=BE=E7=BD=AE=E5=8E=9F?= =?UTF-8?q?=E7=A5=9Evits=20key=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/ai_reply/ai_tts.go | 13 +++++-------- plugin/ai_reply/main.go | 7 +++---- plugin/moegoe/main.go | 6 +----- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/plugin/ai_reply/ai_tts.go b/plugin/ai_reply/ai_tts.go index 3f6bf950..9496ac17 100644 --- a/plugin/ai_reply/ai_tts.go +++ b/plugin/ai_reply/ai_tts.go @@ -135,19 +135,16 @@ func newttsmode() *ttsmode { func (t *ttsmode) getAPIKey(ctx *zero.Ctx) string { if t.APIKey == "" { m := ctx.State["manager"].(*ctrl.Control[*zero.Ctx]) - gid := ctx.Event.GroupID - if gid == 0 { - gid = -ctx.Event.UserID - } - _ = m.Manager.GetExtra(gid, &t) + _ = m.Manager.GetExtra(-1, &t) + logrus.Debugln("[tts] get api key:", t.APIKey) } - logrus.Debugln("[tts] get api key:", t.APIKey) return url.QueryEscape(t.APIKey) } -func (t *ttsmode) setAPIKey(m *ctrl.Control[*zero.Ctx], grp int64, key string) error { +func (t *ttsmode) setAPIKey(m *ctrl.Control[*zero.Ctx], key string) error { t.APIKey = key - return m.Manager.SetExtra(grp, t) + _ = m.Manager.Response(-1) + return m.Manager.SetExtra(-1, t) } func (t *ttsmode) setSoundMode(ctx *zero.Ctx, name string, baiduper, mockingsynt int) error { diff --git a/plugin/ai_reply/main.go b/plugin/ai_reply/main.go index ab79d19c..6c904369 100644 --- a/plugin/ai_reply/main.go +++ b/plugin/ai_reply/main.go @@ -28,7 +28,7 @@ func init() { // 插件主体 "- 设置语音模式[原神人物/百度/拟声鸟] 数字(百度/拟声鸟模式)\n" + "- 设置默认语音模式[原神人物/百度/拟声鸟] 数字(百度/拟声鸟模式)\n" + "- 恢复成默认语音模式\n" + - "- 为群 xxx 设置原神语音 api key xxxxxx (key请加开发群获得, 群号不代表设置之后只能在该群使用, 而是设置后, 必须在该群触发过语音后, 其他位置才会正常)\n" + + "- 设置原神语音 api key xxxxxx (key请加开发群获得)\n" + "当前适用的原神人物含有以下:\n" + list(genshin.SoundList[:], 5), }) @@ -262,9 +262,8 @@ func init() { // 插件主体 ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("设置成功,当前为", speaker)) }) - 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 := t.setAPIKey(ctx.State["manager"].(*ctrl.Control[*zero.Ctx]), grp, ctx.State["regex_matched"].([]string)[2]) + ent.OnRegex(`^设置原神语音\s*api\s*key\s*([0-9a-zA-Z-_]{54}==)$`, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) { + err := t.setAPIKey(ctx.State["manager"].(*ctrl.Control[*zero.Ctx]), ctx.State["regex_matched"].([]string)[1]) if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) return diff --git a/plugin/moegoe/main.go b/plugin/moegoe/main.go index ebf3038c..1233e800 100644 --- a/plugin/moegoe/main.go +++ b/plugin/moegoe/main.go @@ -57,11 +57,7 @@ func init() { var key struct { APIKey string } - gid := ctx.Event.GroupID - if gid == 0 { - gid = -ctx.Event.UserID - } - err := c.Manager.GetExtra(gid, &key) + err := c.Manager.GetExtra(-1, &key) if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) return