mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 05:30:07 +08:00
fix gitcode 图床
This commit is contained in:
parent
4b288a59b9
commit
baad83172f
6
go.mod
6
go.mod
@ -4,12 +4,12 @@ go 1.19
|
||||
|
||||
require (
|
||||
github.com/Coloured-glaze/gg v1.3.4
|
||||
github.com/FloatTech/AnimeAPI v1.5.1-0.20221003151003-71d7e86c895f
|
||||
github.com/FloatTech/floatbox v0.0.0-20221003150509-1eb268ad10ff
|
||||
github.com/FloatTech/AnimeAPI v1.5.1-0.20221004094358-91497e10dd03
|
||||
github.com/FloatTech/floatbox v0.0.0-20221004092550-1ebf9b4e6198
|
||||
github.com/FloatTech/sqlite v0.4.0
|
||||
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b
|
||||
github.com/FloatTech/zbpctrl v1.5.2-0.20220921013146-40d64bc7799c
|
||||
github.com/FloatTech/zbputils v1.5.1-0.20221003150718-106abe37a694
|
||||
github.com/FloatTech/zbputils v1.5.1-0.20221004094248-ad5a9235757e
|
||||
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c
|
||||
github.com/antchfx/htmlquery v1.2.5
|
||||
github.com/corona10/goimagehash v1.1.0
|
||||
|
||||
12
go.sum
12
go.sum
@ -2,18 +2,18 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
|
||||
github.com/Coloured-glaze/gg v1.3.4 h1:l31zIF/HaVwkzjrj+A56RGQoSKyKuR1IWtIrqXGFStI=
|
||||
github.com/Coloured-glaze/gg v1.3.4/go.mod h1:Ih5NLNNDHOy3RJbB0EPqGTreIzq/H02TGThIagh8HJg=
|
||||
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
||||
github.com/FloatTech/AnimeAPI v1.5.1-0.20221003151003-71d7e86c895f h1:Cei6vTDTGs1ap2o3ufI2I2Tgkz97bKKbVUrFOb4l9gk=
|
||||
github.com/FloatTech/AnimeAPI v1.5.1-0.20221003151003-71d7e86c895f/go.mod h1:a8bKmB4WUKlC/3IT6CjB7bpsb+POjFGf7HhndWmvHX8=
|
||||
github.com/FloatTech/floatbox v0.0.0-20221003150509-1eb268ad10ff h1:eWWdYIfpu91bdvFcdLL27w8O8v3u0O6iph632FAqXww=
|
||||
github.com/FloatTech/floatbox v0.0.0-20221003150509-1eb268ad10ff/go.mod h1:4UDl6E/I2HqAqRnKdsxxfO28fkqGo3CzFOP2BhyI6ag=
|
||||
github.com/FloatTech/AnimeAPI v1.5.1-0.20221004094358-91497e10dd03 h1:BDFRtCpTlJxrEpV26VMauAIURqa5L4BD728L6n0xpvM=
|
||||
github.com/FloatTech/AnimeAPI v1.5.1-0.20221004094358-91497e10dd03/go.mod h1:wY11pOy/T2MBXIGSbYHaynyGzU4Pxz0X2hGPmnlUCCk=
|
||||
github.com/FloatTech/floatbox v0.0.0-20221004092550-1ebf9b4e6198 h1:AkwB7LKMK74yS5rIERhOQbJosDgOefJBSkhEiMbyr+A=
|
||||
github.com/FloatTech/floatbox v0.0.0-20221004092550-1ebf9b4e6198/go.mod h1:4UDl6E/I2HqAqRnKdsxxfO28fkqGo3CzFOP2BhyI6ag=
|
||||
github.com/FloatTech/sqlite v0.4.0 h1:fvQ1vc7fw99jYXccs5KItMluy7QL1t6NxbkH7aN1F4g=
|
||||
github.com/FloatTech/sqlite v0.4.0/go.mod h1:i33d92OtR8jcp5fBUvQtospf27+MkfUxnGwnZ95E/dA=
|
||||
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b h1:tvciXWq2nuvTbFeJGLDNIdRX3BI546D3O7k7vrVueZw=
|
||||
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
|
||||
github.com/FloatTech/zbpctrl v1.5.2-0.20220921013146-40d64bc7799c h1:zYcKvMbwQeifSQg0LnxhmCdyP3mb7ZqS6rjt68jbukw=
|
||||
github.com/FloatTech/zbpctrl v1.5.2-0.20220921013146-40d64bc7799c/go.mod h1:+2mGs9vUWJsvfcbodcmFegqOKEqHnLwopF1jTLVs/gU=
|
||||
github.com/FloatTech/zbputils v1.5.1-0.20221003150718-106abe37a694 h1:5Mrqp7vWfGHa2UaGPlEtEO90oQGZqsLz64OKax9BTKE=
|
||||
github.com/FloatTech/zbputils v1.5.1-0.20221003150718-106abe37a694/go.mod h1:G2moRET7IGbq4ME7lzqzx4FxVzU0NvtYTf3Q6FyYEUw=
|
||||
github.com/FloatTech/zbputils v1.5.1-0.20221004094248-ad5a9235757e h1:3B58NvXqYrIEDhFOl2535yL9zj2cwDAv1eq63adh/Wg=
|
||||
github.com/FloatTech/zbputils v1.5.1-0.20221004094248-ad5a9235757e/go.mod h1:0hU2b4bnYGHBll52SHErCf34yU/PditejgAOkGZ/Czw=
|
||||
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
|
||||
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c h1:cNPOdTNiVwxLpROLjXCgbIPvdkE+BwvxDvgmdYmWx6Q=
|
||||
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c/go.mod h1:KqZzu7slNKROh3TSYEH/IUMG6f4M+1qubZ5e52QypsE=
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/FloatTech/floatbox/file"
|
||||
"github.com/FloatTech/floatbox/web"
|
||||
"github.com/FloatTech/zbputils/img"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@ -18,10 +19,22 @@ type context struct {
|
||||
func dlchan(name string, s *string, wg *sync.WaitGroup, exit func(error)) {
|
||||
defer wg.Done()
|
||||
target := datapath + `materials/` + name
|
||||
var err error
|
||||
if file.IsNotExist(target) {
|
||||
err = file.DownloadTo(`https://gitcode.net/m0_60838134/imagematerials/-/raw/main/`+name, target, true)
|
||||
data, err := web.RequestDataWith(web.NewTLS12Client(), `https://gitcode.net/m0_60838134/imagematerials/-/raw/main/`+name, "GET", "gitcode.net", web.RandUA())
|
||||
if err != nil {
|
||||
_ = os.Remove(target)
|
||||
exit(err)
|
||||
return
|
||||
}
|
||||
f, err := os.Create(target)
|
||||
if err != nil {
|
||||
exit(err)
|
||||
return
|
||||
}
|
||||
_, err = f.Write(data)
|
||||
_ = f.Close()
|
||||
if err != nil {
|
||||
_ = os.Remove(target)
|
||||
exit(err)
|
||||
return
|
||||
}
|
||||
@ -35,8 +48,19 @@ func dlchan(name string, s *string, wg *sync.WaitGroup, exit func(error)) {
|
||||
func dlblock(name string) (string, error) {
|
||||
target := datapath + `materials/` + name
|
||||
if file.IsNotExist(target) {
|
||||
err := file.DownloadTo(`https://gitcode.net/m0_60838134/imagematerials/-/raw/main/`+name, target, true)
|
||||
data, err := web.RequestDataWith(web.NewTLS12Client(), `https://gitcode.net/m0_60838134/imagematerials/-/raw/main/`+name, "GET", "gitcode.net", web.RandUA())
|
||||
if err != nil {
|
||||
_ = os.Remove(target)
|
||||
return "", err
|
||||
}
|
||||
f, err := os.Create(target)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
_, err = f.Write(data)
|
||||
_ = f.Close()
|
||||
if err != nil {
|
||||
_ = os.Remove(target)
|
||||
return "", err
|
||||
}
|
||||
logrus.Debugln("[gif] dl", name, "to", target, "succeeded")
|
||||
|
||||
@ -62,6 +62,10 @@ func init() {
|
||||
PrivateDataFolder: "hyaku",
|
||||
})
|
||||
csvfile := engine.DataFolder() + "hyaku.csv"
|
||||
err := os.MkdirAll(engine.DataFolder()+"img", 0755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
go func() {
|
||||
var f *os.File
|
||||
if file.IsNotExist(csvfile) {
|
||||
@ -109,10 +113,20 @@ func init() {
|
||||
}()
|
||||
engine.OnFullMatch("百人一首").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||
i := rand.Intn(100)
|
||||
img0, err := engine.GetCustomLazyData(bed, fmt.Sprintf("img/%03d.jpg", i+1))
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
img1, err := engine.GetCustomLazyData(bed, fmt.Sprintf("img/%03d.png", i+1))
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(
|
||||
message.Image(fmt.Sprintf(bed+"img/%03d.jpg", i+1)),
|
||||
message.ImageBytes(img0),
|
||||
message.Text("\n", lines[i]),
|
||||
message.Image(fmt.Sprintf(bed+"img/%03d.png", i+1)),
|
||||
message.ImageBytes(img1),
|
||||
)
|
||||
})
|
||||
engine.OnRegex(`^百人一首之\s?(\d+)$`).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||
@ -125,10 +139,20 @@ func init() {
|
||||
ctx.SendChain(message.Text("ERROR: 超出范围"))
|
||||
return
|
||||
}
|
||||
img0, err := engine.GetCustomLazyData(bed, fmt.Sprintf("img/%03d.jpg", i))
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
img1, err := engine.GetCustomLazyData(bed, fmt.Sprintf("img/%03d.png", i))
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(
|
||||
message.Image(fmt.Sprintf(bed+"img/%03d.jpg", i)),
|
||||
message.ImageBytes(img0),
|
||||
message.Text("\n", lines[i-1]),
|
||||
message.Image(fmt.Sprintf(bed+"img/%03d.png", i)),
|
||||
message.ImageBytes(img1),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ import (
|
||||
"github.com/FloatTech/zbputils/img/text"
|
||||
)
|
||||
|
||||
const bed = "https://gitcode.net/u011570312/senso-ji-omikuji/-/raw/main/%d_%d.jpg"
|
||||
const bed = "https://gitcode.net/u011570312/senso-ji-omikuji/-/raw/main/"
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("omikuji", &ctrl.Options[*zero.Ctx]{
|
||||
@ -30,10 +30,20 @@ func init() { // 插件主体
|
||||
engine.OnFullMatchGroup([]string{"求签", "占卜"}).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
i := fcext.RandSenderPerDayN(ctx.Event.UserID, 100) + 1
|
||||
img0, err := engine.GetCustomLazyData(bed, fmt.Sprintf("%d_%d.jpg", i, 0))
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
img1, err := engine.GetCustomLazyData(bed, fmt.Sprintf("%d_%d.jpg", i, 1))
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(
|
||||
message.At(ctx.Event.UserID),
|
||||
message.Image(fmt.Sprintf(bed, i, 0)),
|
||||
message.Image(fmt.Sprintf(bed, i, 1)),
|
||||
message.ImageBytes(img0),
|
||||
message.ImageBytes(img1),
|
||||
)
|
||||
})
|
||||
engine.OnFullMatch("解签", fcext.DoOnceOnSuccess(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user