Skip to content

Commit

Permalink
简化设置原神vits key流程
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Dec 14, 2022
1 parent e9e0498 commit f56929c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
13 changes: 5 additions & 8 deletions plugin/ai_reply/ai_tts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions plugin/ai_reply/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})

Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions plugin/moegoe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f56929c

Please sign in to comment.