✏️ 优化 updater log

This commit is contained in:
fumiama 2021-12-14 13:18:26 +08:00
parent 4485d3d5a9
commit 218119e10e

View File

@ -70,119 +70,119 @@ func init() { // 插件主体
go func() { go func() {
process.SleepAbout1sTo2s() process.SleepAbout1sTo2s()
pool = newPools() pool = newPools()
}() engine := control.Register("setutime", &control.Options{
engine := control.Register("setutime", &control.Options{ DisableOnDefault: false,
DisableOnDefault: false, Help: "涩图\n" +
Help: "涩图\n" + "- 来份[涩图/二次元/风景/车万]\n" +
"- 来份[涩图/二次元/风景/车万]\n" + "- 添加[涩图/二次元/风景/车万][P站图片ID]\n" +
"- 添加[涩图/二次元/风景/车万][P站图片ID]\n" + "- 删除[涩图/二次元/风景/车万][P站图片ID]\n" +
"- 删除[涩图/二次元/风景/车万][P站图片ID]\n" + "- >setu status",
"- >setu status", })
}) engine.OnRegex(`^来份(.*)$`, rule.FirstValueInList(pool.List)).SetBlock(true).SetPriority(20).
engine.OnRegex(`^来份(.*)$`, rule.FirstValueInList(pool.List)).SetBlock(true).SetPriority(20). Handle(func(ctx *zero.Ctx) {
Handle(func(ctx *zero.Ctx) { if !limit.Load(ctx.Event.UserID).Acquire() {
if !limit.Load(ctx.Event.UserID).Acquire() { ctx.SendChain(message.Text("请稍后重试0x0..."))
ctx.SendChain(message.Text("请稍后重试0x0..."))
return
}
var imgtype = ctx.State["regex_matched"].([]string)[1]
// 补充池子
go func() {
times := math.Min(pool.Max-pool.size(imgtype), 2)
for i := 0; i < times; i++ {
illust := &pixiv.Illust{}
// 查询出一张图片
if err := pool.DB.Pick(imgtype, illust); err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
continue
}
// 下载图片
if err := download(illust, pool.Path); err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
continue
}
ctx.SendGroupMessage(pool.Group, []message.MessageSegment{message.Image(file(illust))})
// 向缓冲池添加一张图片
pool.push(imgtype, illust)
time.Sleep(time.Second * 1)
}
}()
// 如果没有缓存阻塞5秒
if pool.size(imgtype) == 0 {
ctx.SendChain(message.Text("INFO: 正在填充弹药......"))
<-time.After(time.Second * 5)
if pool.size(imgtype) == 0 {
ctx.SendChain(message.Text("ERROR: 等待填充,请稍后再试......"))
return return
} }
} var imgtype = ctx.State["regex_matched"].([]string)[1]
// 从缓冲池里抽一张 // 补充池子
if id := ctx.SendChain(message.Image(file(pool.pop(imgtype)))); id == 0 { go func() {
ctx.SendChain(message.Text("ERROR: 可能被风控了")) times := math.Min(pool.Max-pool.size(imgtype), 2)
} for i := 0; i < times; i++ {
}) illust := &pixiv.Illust{}
// 查询出一张图片
engine.OnRegex(`^添加(.*?)(\d+)$`, rule.FirstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(21). if err := pool.DB.Pick(imgtype, illust); err != nil {
Handle(func(ctx *zero.Ctx) { ctx.SendChain(message.Text("ERROR: ", err))
var ( continue
imgtype = ctx.State["regex_matched"].([]string)[1] }
id, _ = strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64) // 下载图片
) if err := download(illust, pool.Path); err != nil {
ctx.SendChain(message.Text("少女祈祷中......")) ctx.SendChain(message.Text("ERROR: ", err))
// 查询P站插图信息 continue
illust, err := pixiv.Works(id) }
if err != nil { ctx.SendGroupMessage(pool.Group, []message.MessageSegment{message.Image(file(illust))})
ctx.SendChain(message.Text("ERROR: ", err)) // 向缓冲池添加一张图片
return pool.push(imgtype, illust)
} time.Sleep(time.Second * 1)
// 下载插画 }
if err := download(illust, pool.Path); err != nil { }()
ctx.SendChain(message.Text("ERROR: ", err)) // 如果没有缓存阻塞5秒
return if pool.size(imgtype) == 0 {
} ctx.SendChain(message.Text("INFO: 正在填充弹药......"))
// 发送到发送者 <-time.After(time.Second * 5)
if id := ctx.SendChain(message.Image(file(illust))); id == 0 { if pool.size(imgtype) == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控,发送失败")) ctx.SendChain(message.Text("ERROR: 等待填充,请稍后再试......"))
return return
} }
// 添加插画到对应的数据库table
if err := pool.DB.Insert(imgtype, illust); err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
ctx.SendChain(message.Text("添加成功"))
})
engine.OnRegex(`^删除(.*?)(\d+)$`, rule.FirstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(22).
Handle(func(ctx *zero.Ctx) {
var (
imgtype = ctx.State["regex_matched"].([]string)[1]
id, _ = strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
)
// 查询数据库
if err := pool.DB.Del(imgtype, fmt.Sprintf("WHERE pid=%d", id)); err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
ctx.SendChain(message.Text("删除成功"))
})
// 查询数据库涩图数量
engine.OnFullMatchGroup([]string{">setu status"}).SetBlock(true).SetPriority(23).
Handle(func(ctx *zero.Ctx) {
state := []string{"[SetuTime]"}
for i := range pool.List {
num, err := pool.DB.Count(pool.List[i])
if err != nil {
num = 0
} }
state = append(state, "\n") // 从缓冲池里抽一张
state = append(state, pool.List[i]) if id := ctx.SendChain(message.Image(file(pool.pop(imgtype)))); id == 0 {
state = append(state, ": ") ctx.SendChain(message.Text("ERROR: 可能被风控了"))
state = append(state, fmt.Sprintf("%d", num)) }
} })
ctx.SendChain(message.Text(state))
}) engine.OnRegex(`^添加(.*?)(\d+)$`, rule.FirstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(21).
Handle(func(ctx *zero.Ctx) {
var (
imgtype = ctx.State["regex_matched"].([]string)[1]
id, _ = strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
)
ctx.SendChain(message.Text("少女祈祷中......"))
// 查询P站插图信息
illust, err := pixiv.Works(id)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
// 下载插画
if err := download(illust, pool.Path); err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
// 发送到发送者
if id := ctx.SendChain(message.Image(file(illust))); id == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控,发送失败"))
return
}
// 添加插画到对应的数据库table
if err := pool.DB.Insert(imgtype, illust); err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
ctx.SendChain(message.Text("添加成功"))
})
engine.OnRegex(`^删除(.*?)(\d+)$`, rule.FirstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(22).
Handle(func(ctx *zero.Ctx) {
var (
imgtype = ctx.State["regex_matched"].([]string)[1]
id, _ = strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
)
// 查询数据库
if err := pool.DB.Del(imgtype, fmt.Sprintf("WHERE pid=%d", id)); err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
ctx.SendChain(message.Text("删除成功"))
})
// 查询数据库涩图数量
engine.OnFullMatchGroup([]string{">setu status"}).SetBlock(true).SetPriority(23).
Handle(func(ctx *zero.Ctx) {
state := []string{"[SetuTime]"}
for i := range pool.List {
num, err := pool.DB.Count(pool.List[i])
if err != nil {
num = 0
}
state = append(state, "\n")
state = append(state, pool.List[i])
state = append(state, ": ")
state = append(state, fmt.Sprintf("%d", num))
}
ctx.SendChain(message.Text(state))
})
}()
} }
// size 返回缓冲池指定类型的现有大小 // size 返回缓冲池指定类型的现有大小