简化设置原神vits key流程

This commit is contained in:
源文雨 2022-12-14 21:38:55 +08:00
parent e9e0498b34
commit f56929c852
3 changed files with 9 additions and 17 deletions

View File

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

View File

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

View File

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