mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 05:30:07 +08:00
fix(emozi): login
This commit is contained in:
parent
48a2703b99
commit
105553c386
@ -5,6 +5,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/FloatTech/AnimeAPI/emozi"
|
"github.com/FloatTech/AnimeAPI/emozi"
|
||||||
ctrl "github.com/FloatTech/zbpctrl"
|
ctrl "github.com/FloatTech/zbpctrl"
|
||||||
@ -24,7 +26,20 @@ func init() {
|
|||||||
})
|
})
|
||||||
usr := emozi.Anonymous()
|
usr := emozi.Anonymous()
|
||||||
data, err := os.ReadFile(en.DataFolder() + "user.txt")
|
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 {
|
if err == nil {
|
||||||
arr := strings.Split(string(data), "\n")
|
arr := strings.Split(string(data), "\n")
|
||||||
if len(arr) >= 2 {
|
if len(arr) >= 2 {
|
||||||
@ -35,7 +50,7 @@ func init() {
|
|||||||
usr = emozi.Anonymous()
|
usr = emozi.Anonymous()
|
||||||
} else {
|
} else {
|
||||||
logrus.Infoln("[emozi]", "以", arr[0], "身份登录成功")
|
logrus.Infoln("[emozi]", "以", arr[0], "身份登录成功")
|
||||||
hasaccount = true
|
refresher.Do(refresh)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,16 +59,8 @@ func init() {
|
|||||||
txt := strings.TrimSpace(ctx.State["args"].(string))
|
txt := strings.TrimSpace(ctx.State["args"].(string))
|
||||||
out, chs, err := usr.Marshal(false, txt)
|
out, chs, err := usr.Marshal(false, txt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if hasaccount {
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
err2 := usr.Login()
|
return
|
||||||
if err2 == nil {
|
|
||||||
out, chs, err = usr.Marshal(false, txt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
ctx.SendChain(message.Text("ERROR: ", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if len(chs) == 0 {
|
if len(chs) == 0 {
|
||||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text(out)))
|
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) {
|
en.OnPrefix("抽象还原").Limit(ctxext.LimitByUser).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||||
txt := strings.TrimSpace(ctx.State["args"].(string))
|
txt := strings.TrimSpace(ctx.State["args"].(string))
|
||||||
out, err := usr.Unmarshal(false, txt)
|
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 {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("ERROR: ", err))
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
return
|
return
|
||||||
@ -115,7 +110,7 @@ func init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
usr = newusr
|
usr = newusr
|
||||||
hasaccount = true
|
refresher.Do(refresh)
|
||||||
ctx.SendChain(message.Text("成功"))
|
ctx.SendChain(message.Text("成功"))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user