This commit is contained in:
源文雨 2022-12-07 11:52:16 +08:00
parent ed7cef7566
commit d76a65ec07
2 changed files with 7 additions and 11 deletions

View File

@ -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

View File

@ -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