Skip to content

Commit

Permalink
fix(emozi): usr login
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Oct 13, 2024
1 parent baf1a80 commit 001fdcc
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions plugin/emozi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func init() {
})
usr := emozi.Anonymous()
data, err := os.ReadFile(en.DataFolder() + "user.txt")
hasaccount := false
if err == nil {
arr := strings.Split(string(data), "\n")
if len(arr) >= 2 {
Expand All @@ -33,6 +34,7 @@ func init() {
usr = emozi.Anonymous()
} else {
logrus.Infoln("[emozi]", "以", usr, "身份登录成功")
hasaccount = true
}
}
}
Expand All @@ -41,8 +43,16 @@ func init() {
txt := strings.TrimSpace(ctx.State["args"].(string))
out, chs, err := usr.Marshal(false, txt)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
if hasaccount {
err = usr.Login()
if err == nil {
out, chs, err = usr.Marshal(false, txt)
}
}
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
}
if len(chs) == 0 {
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text(out)))
Expand Down Expand Up @@ -71,6 +81,18 @@ func init() {
en.OnPrefix("抽象还原").Limit(ctxext.LimitByUser).SetBlock(true).Handle(func(ctx *zero.Ctx) {
txt := strings.TrimSpace(ctx.State["args"].(string))
out, err := usr.Unmarshal(false, txt)
if err != nil {
if hasaccount {
err = usr.Login()
if err == nil {
out, err = usr.Unmarshal(false, txt)
}
}
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
}
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
Expand All @@ -91,6 +113,8 @@ func init() {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
usr = newusr
hasaccount = true
ctx.SendChain(message.Text("成功"))
})
}

0 comments on commit 001fdcc

Please sign in to comment.