mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
fix(emozi): usr login
This commit is contained in:
parent
baf1a80dc2
commit
001fdcceae
@ -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 {
|
||||
@ -33,6 +34,7 @@ func init() {
|
||||
usr = emozi.Anonymous()
|
||||
} else {
|
||||
logrus.Infoln("[emozi]", "以", usr, "身份登录成功")
|
||||
hasaccount = true
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -40,10 +42,18 @@ func init() {
|
||||
en.OnPrefix("抽象转写").Limit(ctxext.LimitByUser).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||
txt := strings.TrimSpace(ctx.State["args"].(string))
|
||||
out, chs, err := usr.Marshal(false, txt)
|
||||
if err != nil {
|
||||
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)))
|
||||
return
|
||||
@ -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
|
||||
@ -91,6 +113,8 @@ func init() {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
usr = newusr
|
||||
hasaccount = true
|
||||
ctx.SendChain(message.Text("成功"))
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user