mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-18 20:50:12 +08:00
fix(emozi): login
This commit is contained in:
parent
48a2703b99
commit
105553c386
@ -5,6 +5,8 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/emozi"
|
||||
ctrl "github.com/FloatTech/zbpctrl"
|
||||
@ -24,7 +26,20 @@ func init() {
|
||||
})
|
||||
usr := emozi.Anonymous()
|
||||
data, err := os.ReadFile(en.DataFolder() + "user.txt")
|
||||
hasaccount := false
|
||||
refresh := func() {
|
||||
t := time.NewTicker(time.Hour)
|
||||
defer t.Stop()
|
||||
for range t.C {
|
||||
if !usr.IsValid() {
|
||||
time.Sleep(time.Second * 2)
|
||||
err := usr.Login()
|
||||
if err != nil {
|
||||
logrus.Warnln("[emozi] 重新登录账号失败:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
refresher := sync.Once{}
|
||||
if err == nil {
|
||||
arr := strings.Split(string(data), "\n")
|
||||
if len(arr) >= 2 {
|
||||
@ -35,7 +50,7 @@ func init() {
|
||||
usr = emozi.Anonymous()
|
||||
} else {
|
||||
logrus.Infoln("[emozi]", "以", arr[0], "身份登录成功")
|
||||
hasaccount = true
|
||||
refresher.Do(refresh)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -44,16 +59,8 @@ func init() {
|
||||
txt := strings.TrimSpace(ctx.State["args"].(string))
|
||||
out, chs, err := usr.Marshal(false, txt)
|
||||
if err != nil {
|
||||
if hasaccount {
|
||||
err2 := usr.Login()
|
||||
if err2 == nil {
|
||||
out, chs, err = usr.Marshal(false, txt)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
if len(chs) == 0 {
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text(out)))
|
||||
@ -82,18 +89,6 @@ 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 {
|
||||
err2 := usr.Login()
|
||||
if err2 == 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
|
||||
@ -115,7 +110,7 @@ func init() {
|
||||
return
|
||||
}
|
||||
usr = newusr
|
||||
hasaccount = true
|
||||
refresher.Do(refresh)
|
||||
ctx.SendChain(message.Text("成功"))
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user