From eb901a2f73231f962b440d6f95f60aac76016724 Mon Sep 17 00:00:00 2001 From: fumiama Date: Thu, 3 Jun 2021 16:57:36 +0800 Subject: [PATCH 1/8] =?UTF-8?q?shindan=20api=E5=A4=B1=E6=95=88=E6=97=B6?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E5=87=BA=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shindan/shindan.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shindan/shindan.go b/shindan/shindan.go index f1f776b2..b48f9a6b 100644 --- a/shindan/shindan.go +++ b/shindan/shindan.go @@ -119,6 +119,9 @@ func shindanmaker(id, name string) (string, error) { return "", err } defer resp.Body.Close() + if resp.ContentLength <= 0 { + return "出错啦", nil + } // 解析XPATH doc, err := xpath.Parse(resp.Body) if err != nil { From 36e338e9ddfb1dec278513dd05d889ee4ca3bf92 Mon Sep 17 00:00:00 2001 From: fumiama Date: Thu, 3 Jun 2021 19:42:59 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0mips=E6=9E=B6=E6=9E=84?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build_mips.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 build_mips.sh diff --git a/build_mips.sh b/build_mips.sh new file mode 100644 index 00000000..df3fc57f --- /dev/null +++ b/build_mips.sh @@ -0,0 +1,6 @@ +go version +mips-linux-musl-gcc -v +go env -w GOPROXY=https://goproxy.cn,direct +go env -w GO111MODULE=auto +go mod tidy +GOOS=linux GOARCH=mips GOMIPS=softfloat CGO_ENABLED=1 CC=mips-linux-musl-gcc CXX=mips-linux-musl-g++ go build -ldflags "-s -w" -o zerobot \ No newline at end of file From e2c5905d0ad32c3d894aa37ce3a6bb89ff019d54 Mon Sep 17 00:00:00 2001 From: fumiama Date: Thu, 3 Jun 2021 20:06:16 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E4=BB=A5=E5=85=A5=E5=8F=82=E5=BD=A2?= =?UTF-8?q?=E5=BC=8F=E6=8C=87=E5=AE=9Asuperusers=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E5=8F=8D=E5=A4=8D=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build_mips.sh | 4 +++- main.go | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/build_mips.sh b/build_mips.sh index df3fc57f..bf39b1e5 100644 --- a/build_mips.sh +++ b/build_mips.sh @@ -3,4 +3,6 @@ mips-linux-musl-gcc -v go env -w GOPROXY=https://goproxy.cn,direct go env -w GO111MODULE=auto go mod tidy -GOOS=linux GOARCH=mips GOMIPS=softfloat CGO_ENABLED=1 CC=mips-linux-musl-gcc CXX=mips-linux-musl-g++ go build -ldflags "-s -w" -o zerobot \ No newline at end of file +export CCBIN=~/openwrt_with_lean_packages/staging_dir/toolchain-mips_24kc_gcc-8.4.0_musl/bin/mips-openwrt-linux-musl-gcc +export CXXBIN=~/openwrt_with_lean_packages/staging_dir/toolchain-mips_24kc_gcc-8.4.0_musl/bin/mips-openwrt-linux-musl-g++ +GOOS=linux GOARCH=mips GOMIPS=softfloat CGO_ENABLED=1 CC=${CCBIN} CXX=${CXXBIN} go build -ldflags "-s -w" -o zerobot \ No newline at end of file diff --git a/main.go b/main.go index 84919165..716ff478 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "os" log "github.com/sirupsen/logrus" easy "github.com/t-tomalak/logrus-easy-formatter" @@ -47,7 +48,7 @@ func main() { zero.Run(zero.Config{ NickName: []string{"椛椛", "ATRI", "atri", "亚托莉", "アトリ"}, CommandPrefix: "/", - SuperUsers: []string{"825111790", "213864964"}, // 必须修改,否则无权限 + SuperUsers: os.Args[1:], // 必须修改,否则无权限 Driver: []zero.Driver{ driver.NewWebSocketClient("127.0.0.1", "6700", ""), }, From be9f4293fd513f2efde5c66ab9571404c0dde28d Mon Sep 17 00:00:00 2001 From: fumiama Date: Thu, 3 Jun 2021 20:08:54 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BF=AE=E6=AD=A3bulid=5Fmips?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build_mips.sh | 1 - 1 file changed, 1 deletion(-) mode change 100644 => 100755 build_mips.sh diff --git a/build_mips.sh b/build_mips.sh old mode 100644 new mode 100755 index bf39b1e5..4fac2088 --- a/build_mips.sh +++ b/build_mips.sh @@ -1,5 +1,4 @@ go version -mips-linux-musl-gcc -v go env -w GOPROXY=https://goproxy.cn,direct go env -w GO111MODULE=auto go mod tidy From 6b604d8b9fe48e0d90122457cc3ccbc7af9a97ff Mon Sep 17 00:00:00 2001 From: fumiama Date: Thu, 3 Jun 2021 22:49:36 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E4=BB=A50755=E5=88=9B=E5=BB=BA=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E4=BB=A5=E9=81=BF=E5=85=8D=E6=97=A0=E6=B3=95=E4=BF=9D?= =?UTF-8?q?=E5=AD=98cache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setutime/utils/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setutime/utils/utils.go b/setutime/utils/utils.go index 24d75f74..e4c4013c 100644 --- a/setutime/utils/utils.go +++ b/setutime/utils/utils.go @@ -39,7 +39,7 @@ func CreatePath(path string) { // } if !PathExists(path) { - err := os.MkdirAll(path, 0644) + err := os.MkdirAll(path, 0755) if err != nil { panic(err) } From c199a0ac6d4a8d84cb09660d7e9d209711fac16a Mon Sep 17 00:00:00 2001 From: fumiama Date: Thu, 3 Jun 2021 23:46:37 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=8C=96=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=89=A9=E5=B1=95=E3=80=81=E5=A2=9E=E5=8A=A0=E7=AE=80?= =?UTF-8?q?=E6=98=93=E9=9A=8F=E6=9C=BA=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 1 + manager/manager.go | 5 +++-- manager/timer.go | 23 ----------------------- msgext/msgext.go | 26 ++++++++++++++++++++++++++ randimg/setu_geter.go | 29 +++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 msgext/msgext.go create mode 100644 randimg/setu_geter.go diff --git a/main.go b/main.go index 716ff478..c065ed9a 100644 --- a/main.go +++ b/main.go @@ -24,6 +24,7 @@ import ( // 娱乐类 _ "github.com/Yiwen-Chan/ZeroBot-Plugin/music" // 点歌 + _ "github.com/Yiwen-Chan/ZeroBot-Plugin/randimg" //简易随机图片 _ "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime" // 涩图 _ "github.com/Yiwen-Chan/ZeroBot-Plugin/shindan" // 测定 ) diff --git a/manager/manager.go b/manager/manager.go index 7e103974..81e5cc66 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -4,6 +4,7 @@ import ( "strconv" "strings" + "github.com/Yiwen-Chan/ZeroBot-Plugin/msgext" zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/message" ) @@ -238,9 +239,9 @@ func init() { // 插件主体 if ts.enable { go timer(ts, func() { if ts.url == "" { - ctx.SendChain(AtAll(), message.Text(ts.alert)) + ctx.SendChain(msgext.AtAll(), message.Text(ts.alert)) } else { - ctx.SendChain(AtAll(), message.Text(ts.alert), ImageNoCache(ts.url)) + ctx.SendChain(msgext.AtAll(), message.Text(ts.alert), msgext.ImageNoCache(ts.url)) } }) ctx.Send("记住了~") diff --git a/manager/timer.go b/manager/timer.go index a42916da..5bed7bae 100644 --- a/manager/timer.go +++ b/manager/timer.go @@ -6,8 +6,6 @@ import ( "strings" "time" "unicode" - - "github.com/wdvxdr1123/ZeroBot/message" ) type TimeStamp struct { @@ -175,24 +173,3 @@ func chineseChar2Int(c rune) int { return 0 } } - -//@全体成员 -func AtAll() message.MessageSegment { - return message.MessageSegment{ - Type: "at", - Data: map[string]string{ - "qq": "all", - }, - } -} - -//无缓存发送图片 -func ImageNoCache(url string) message.MessageSegment { - return message.MessageSegment{ - Type: "image", - Data: map[string]string{ - "file": url, - "cache": "0", - }, - } -} diff --git a/msgext/msgext.go b/msgext/msgext.go new file mode 100644 index 00000000..b0f1dacb --- /dev/null +++ b/msgext/msgext.go @@ -0,0 +1,26 @@ +package msgext + +import ( + "github.com/wdvxdr1123/ZeroBot/message" +) + +//@全体成员 +func AtAll() message.MessageSegment { + return message.MessageSegment{ + Type: "at", + Data: map[string]string{ + "qq": "all", + }, + } +} + +//无缓存发送图片 +func ImageNoCache(url string) message.MessageSegment { + return message.MessageSegment{ + Type: "image", + Data: map[string]string{ + "file": url, + "cache": "0", + }, + } +} diff --git a/randimg/setu_geter.go b/randimg/setu_geter.go new file mode 100644 index 00000000..2f8cb31c --- /dev/null +++ b/randimg/setu_geter.go @@ -0,0 +1,29 @@ +package randimg + +import ( + "strings" + + "github.com/Yiwen-Chan/ZeroBot-Plugin/msgext" + zero "github.com/wdvxdr1123/ZeroBot" +) + +var RANDOM_API_URL = "https://api.pixivweb.com/anime18r.php?return=img" + +func init() { // 插件主体 + zero.OnRegex(`^设置随机图片网址(.*)$`, zero.SuperUserPermission).SetBlock(true).SetPriority(20). + Handle(func(ctx *zero.Ctx) { + url := ctx.State["regex_matched"].([]string)[1] + if !strings.HasPrefix(url, "http") { + ctx.Send("URL非法!") + } else { + RANDOM_API_URL = url + } + return + }) + // 随机图片 + zero.OnFullMatchGroup([]string{"随机图片"}).SetBlock(true).SetPriority(24). + Handle(func(ctx *zero.Ctx) { + ctx.Send(msgext.ImageNoCache(RANDOM_API_URL)) + return + }) +} From 08b2102528687a433ab0ab3fd0c9fb2dc066a69e Mon Sep 17 00:00:00 2001 From: fumiama Date: Fri, 4 Jun 2021 13:45:50 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E5=88=86=E7=A6=BB=E6=90=9C=E5=9B=BE?= =?UTF-8?q?=E4=B8=8E=E9=9A=8F=E6=9C=BA=E5=9B=BE(=E9=9A=8F=E6=9C=BA?= =?UTF-8?q?=E5=9B=BE=E9=9C=80=E8=A6=81cgo=E8=80=8C=E6=90=9C=E5=9B=BE?= =?UTF-8?q?=E4=B8=8D=E7=94=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {setutime/utils => api/pixiv}/download.go | 2 +- {setutime/utils => api/pixiv}/pixiv_api.go | 45 ++++++++++++++++- {setutime/utils => api/pixiv}/utils.go | 2 +- build_mips.sh | 2 +- main.go | 9 ++-- {setutime => picsearcher}/pic_searcher.go | 15 ++++-- {setutime => picsearcher}/utils/ascii2d.go | 5 +- {setutime => picsearcher}/utils/saucenao.go | 0 setutime/setu_geter.go | 19 ++++---- setutime/utils/pic_pool.go | 53 +++------------------ 10 files changed, 82 insertions(+), 70 deletions(-) rename {setutime/utils => api/pixiv}/download.go (99%) rename {setutime/utils => api/pixiv}/pixiv_api.go (67%) rename {setutime/utils => api/pixiv}/utils.go (98%) rename {setutime => picsearcher}/pic_searcher.go (88%) rename {setutime => picsearcher}/utils/ascii2d.go (95%) rename {setutime => picsearcher}/utils/saucenao.go (100%) diff --git a/setutime/utils/download.go b/api/pixiv/download.go similarity index 99% rename from setutime/utils/download.go rename to api/pixiv/download.go index 3c0ee9a7..3640e86b 100644 --- a/setutime/utils/download.go +++ b/api/pixiv/download.go @@ -1,4 +1,4 @@ -package utils +package pixiv import ( "crypto/md5" diff --git a/setutime/utils/pixiv_api.go b/api/pixiv/pixiv_api.go similarity index 67% rename from setutime/utils/pixiv_api.go rename to api/pixiv/pixiv_api.go index 09a20307..7b027277 100644 --- a/setutime/utils/pixiv_api.go +++ b/api/pixiv/pixiv_api.go @@ -1,4 +1,4 @@ -package utils +package pixiv import ( "crypto/tls" @@ -92,3 +92,46 @@ func (this *Illust) IllustInfo(id int64) (err error) { this.UserName = json.Get("userName").Str return nil } + +// BigPic 返回一张XML大图CQ码 +func (i *Illust) BigPic(file string) string { + var hash = PicHash(file) + return fmt.Sprintf(`[CQ:xml,data= + +]`, + hash, + hash, + hash, + i.Title, + i.Pid, + i.UserName, + ) +} + +// NormalPic 返回一张普通图CQ码 +func (i *Illust) NormalPic(file string) string { + return fmt.Sprintf(`[CQ:image,file=file:///%s]`, file) +} + +// DetailPic 返回一张带详细信息的图片CQ码 +func (i *Illust) DetailPic(file string) string { + return fmt.Sprintf(`[SetuTime] %s +标题:%s +插画ID:%d +画师:%s +画师ID:%d +直链:https://pixivel.moe/detail?id=%d`, + i.NormalPic(file), + i.Title, + i.Pid, + i.UserName, + i.UserId, + i.Pid, + ) +} diff --git a/setutime/utils/utils.go b/api/pixiv/utils.go similarity index 98% rename from setutime/utils/utils.go rename to api/pixiv/utils.go index e4c4013c..21e1733d 100644 --- a/setutime/utils/utils.go +++ b/api/pixiv/utils.go @@ -1,4 +1,4 @@ -package utils +package pixiv import ( "os" diff --git a/build_mips.sh b/build_mips.sh index 4fac2088..98abb55e 100755 --- a/build_mips.sh +++ b/build_mips.sh @@ -4,4 +4,4 @@ go env -w GO111MODULE=auto go mod tidy export CCBIN=~/openwrt_with_lean_packages/staging_dir/toolchain-mips_24kc_gcc-8.4.0_musl/bin/mips-openwrt-linux-musl-gcc export CXXBIN=~/openwrt_with_lean_packages/staging_dir/toolchain-mips_24kc_gcc-8.4.0_musl/bin/mips-openwrt-linux-musl-g++ -GOOS=linux GOARCH=mips GOMIPS=softfloat CGO_ENABLED=1 CC=${CCBIN} CXX=${CXXBIN} go build -ldflags "-s -w" -o zerobot \ No newline at end of file +GOOS=linux GOARCH=mips GOMIPS=softfloat CGO_ENABLED=0 CC=${CCBIN} CXX=${CXXBIN} go build -ldflags "-s -w" -o zerobot \ No newline at end of file diff --git a/main.go b/main.go index c065ed9a..a431de5f 100644 --- a/main.go +++ b/main.go @@ -23,10 +23,11 @@ import ( _ "github.com/Yiwen-Chan/ZeroBot-Plugin/runcode" // 在线运行代码 // 娱乐类 - _ "github.com/Yiwen-Chan/ZeroBot-Plugin/music" // 点歌 - _ "github.com/Yiwen-Chan/ZeroBot-Plugin/randimg" //简易随机图片 - _ "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime" // 涩图 - _ "github.com/Yiwen-Chan/ZeroBot-Plugin/shindan" // 测定 + _ "github.com/Yiwen-Chan/ZeroBot-Plugin/music" // 点歌 + _ "github.com/Yiwen-Chan/ZeroBot-Plugin/picsearcher" // 搜图 + _ "github.com/Yiwen-Chan/ZeroBot-Plugin/randimg" //简易随机图片 + _ "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime" // 涩图 + _ "github.com/Yiwen-Chan/ZeroBot-Plugin/shindan" // 测定 ) func init() { diff --git a/setutime/pic_searcher.go b/picsearcher/pic_searcher.go similarity index 88% rename from setutime/pic_searcher.go rename to picsearcher/pic_searcher.go index 5b9a6840..09904be3 100644 --- a/setutime/pic_searcher.go +++ b/picsearcher/pic_searcher.go @@ -1,4 +1,4 @@ -package setutime +package picsearcher import ( "fmt" @@ -9,17 +9,24 @@ import ( zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/message" - utils "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime/utils" + "github.com/Yiwen-Chan/ZeroBot-Plugin/api/pixiv" + utils "github.com/Yiwen-Chan/ZeroBot-Plugin/picsearcher/utils" +) + +var ( + BOTPATH = pixiv.PathExecute() // 当前bot运行目录 + DATAPATH = BOTPATH + "data/SetuTime/" // 数据目录 + CACHEPATH = DATAPATH + "cache/" // 缓冲图片路径 ) func init() { // 插件主体 // 根据PID搜图 zero.OnRegex(`^搜图(\d+)$`).SetBlock(true).SetPriority(30). Handle(func(ctx *zero.Ctx) { - id := utils.Str2Int(ctx.State["regex_matched"].([]string)[1]) + id := pixiv.Str2Int(ctx.State["regex_matched"].([]string)[1]) ctx.Send("少女祈祷中......") // 获取P站插图信息 - illust := &utils.Illust{} + illust := &pixiv.Illust{} if err := illust.IllustInfo(id); err != nil { ctx.Send(fmt.Sprintf("ERROR: %v", err)) return diff --git a/setutime/utils/ascii2d.go b/picsearcher/utils/ascii2d.go similarity index 95% rename from setutime/utils/ascii2d.go rename to picsearcher/utils/ascii2d.go index 82ecbec6..d4c3a6ef 100644 --- a/setutime/utils/ascii2d.go +++ b/picsearcher/utils/ascii2d.go @@ -6,6 +6,7 @@ import ( "net/url" "strings" + "github.com/Yiwen-Chan/ZeroBot-Plugin/api/pixiv" xpath "github.com/antchfx/htmlquery" "github.com/wdvxdr1123/ZeroBot/message" ) @@ -71,12 +72,12 @@ func Ascii2dSearch(pic string) (message.Message, error) { if link == "" || index == -1 { return nil, fmt.Errorf("Ascii2d not found") } - var id = Str2Int(link[index+1:]) + var id = pixiv.Str2Int(link[index+1:]) if id == 0 { return nil, fmt.Errorf("convert to pid error") } // 根据PID查询插图信息 - var illust = &Illust{} + var illust = &pixiv.Illust{} if err := illust.IllustInfo(id); err != nil { return nil, err } diff --git a/setutime/utils/saucenao.go b/picsearcher/utils/saucenao.go similarity index 100% rename from setutime/utils/saucenao.go rename to picsearcher/utils/saucenao.go diff --git a/setutime/setu_geter.go b/setutime/setu_geter.go index c8e4f0d5..cb0a44fa 100644 --- a/setutime/setu_geter.go +++ b/setutime/setu_geter.go @@ -9,13 +9,14 @@ import ( zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/extension/rate" + "github.com/Yiwen-Chan/ZeroBot-Plugin/api/pixiv" "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime/utils" ) var limit = rate.NewManager(time.Minute*1, 5) var ( - BOTPATH = utils.PathExecute() // 当前bot运行目录 + BOTPATH = pixiv.PathExecute() // 当前bot运行目录 DATAPATH = BOTPATH + "data/SetuTime/" // 数据目录 DBPATH = DATAPATH + "SetuTime.db" // 数据库路径 @@ -33,11 +34,11 @@ func init() { PoolsCache.Group = CACHEGROUP // 图片缓冲群 PoolsCache.Path = CACHEPATH // 缓冲图片路径 - utils.CreatePath(DBPATH) - utils.CreatePath(CACHEPATH) + pixiv.CreatePath(DBPATH) + pixiv.CreatePath(CACHEPATH) for i := range PoolList { - if err := DB.Create(PoolList[i], &utils.Illust{}); err != nil { + if err := DB.Create(PoolList[i], &pixiv.Illust{}); err != nil { panic(err) } } @@ -53,9 +54,9 @@ func init() { // 插件主体 var type_ = ctx.State["regex_matched"].([]string)[1] // 补充池子 go func() { - times := utils.Min(PoolsCache.Max-PoolsCache.Size(type_), 2) + times := pixiv.Min(PoolsCache.Max-PoolsCache.Size(type_), 2) for i := 0; i < times; i++ { - illust := &utils.Illust{} + illust := &pixiv.Illust{} // 查询出一张图片 if err := DB.Select(type_, illust, "ORDER BY RANDOM() limit 1"); err != nil { ctx.Send(fmt.Sprintf("ERROR: %v", err)) @@ -96,8 +97,8 @@ func init() { // 插件主体 Handle(func(ctx *zero.Ctx) { var ( type_ = ctx.State["regex_matched"].([]string)[1] - id = utils.Str2Int(ctx.State["regex_matched"].([]string)[2]) - illust = &utils.Illust{} + id = pixiv.Str2Int(ctx.State["regex_matched"].([]string)[2]) + illust = &pixiv.Illust{} ) ctx.Send("少女祈祷中......") // 查询P站插图信息 @@ -129,7 +130,7 @@ func init() { // 插件主体 Handle(func(ctx *zero.Ctx) { var ( type_ = ctx.State["regex_matched"].([]string)[1] - id = utils.Str2Int(ctx.State["regex_matched"].([]string)[2]) + id = pixiv.Str2Int(ctx.State["regex_matched"].([]string)[2]) ) // 查询数据库 if err := DB.Delete(type_, fmt.Sprintf("WHERE pid=%d", id)); err != nil { diff --git a/setutime/utils/pic_pool.go b/setutime/utils/pic_pool.go index 7692a2bd..17ab21a0 100644 --- a/setutime/utils/pic_pool.go +++ b/setutime/utils/pic_pool.go @@ -3,6 +3,8 @@ package utils import ( "fmt" "sync" + + "github.com/Yiwen-Chan/ZeroBot-Plugin/api/pixiv" ) // PoolsCache 图片缓冲池 @@ -11,7 +13,7 @@ type PoolsCache struct { Max int Path string Group int64 - Pool map[string][]*Illust + Pool map[string][]*pixiv.Illust } // NewPoolsCache 返回一个缓冲池对象 @@ -20,7 +22,7 @@ func NewPoolsCache() *PoolsCache { Max: 10, Path: "./data/SetuTime/cache/", Group: 1048452984, - Pool: map[string][]*Illust{}, + Pool: map[string][]*pixiv.Illust{}, } } @@ -35,7 +37,7 @@ func (p *PoolsCache) IsFull(type_ string) bool { } // Push 向缓冲池插入一张图片,返回错误 -func (p *PoolsCache) Push(type_ string, illust *Illust) (err error) { +func (p *PoolsCache) Push(type_ string, illust *pixiv.Illust) (err error) { p.Lock.Lock() defer p.Lock.Unlock() p.Pool[type_] = append(p.Pool[type_], illust) @@ -43,7 +45,7 @@ func (p *PoolsCache) Push(type_ string, illust *Illust) (err error) { } // Push 在缓冲池拿出一张图片,返回错误 -func (p *PoolsCache) Pop(type_ string) (illust *Illust) { +func (p *PoolsCache) Pop(type_ string) (illust *pixiv.Illust) { p.Lock.Lock() defer p.Lock.Unlock() if p.Size(type_) == 0 { @@ -69,46 +71,3 @@ func (p *PoolsCache) GetOnePic(type_ string, form string) string { return illust.NormalPic(file) } } - -// BigPic 返回一张XML大图CQ码 -func (i *Illust) BigPic(file string) string { - var hash = PicHash(file) - return fmt.Sprintf(`[CQ:xml,data= - -]`, - hash, - hash, - hash, - i.Title, - i.Pid, - i.UserName, - ) -} - -// NormalPic 返回一张普通图CQ码 -func (i *Illust) NormalPic(file string) string { - return fmt.Sprintf(`[CQ:image,file=file:///%s]`, file) -} - -// DetailPic 返回一张带详细信息的图片CQ码 -func (i *Illust) DetailPic(file string) string { - return fmt.Sprintf(`[SetuTime] %s -标题:%s -插画ID:%d -画师:%s -画师ID:%d -直链:https://pixivel.moe/detail?id=%d`, - i.NormalPic(file), - i.Title, - i.Pid, - i.UserName, - i.UserId, - i.Pid, - ) -} From 352fd2eb79ed3ae8c839a287aebb1db65dfa2ba7 Mon Sep 17 00:00:00 2001 From: fumiama Date: Fri, 4 Jun 2021 13:51:37 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E4=B8=8A=E4=B8=80=E4=B8=AA=E9=9A=8F?= =?UTF-8?q?=E6=9C=BA=E5=9B=BE=E7=89=87=E6=9C=AA=E5=AE=8C=E6=88=90=E5=89=8D?= =?UTF-8?q?=E6=8B=92=E7=BB=9D=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {msgext => api/msgext}/msgext.go | 0 manager/manager.go | 2 +- randimg/setu_geter.go | 11 +++++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) rename {msgext => api/msgext}/msgext.go (100%) diff --git a/msgext/msgext.go b/api/msgext/msgext.go similarity index 100% rename from msgext/msgext.go rename to api/msgext/msgext.go diff --git a/manager/manager.go b/manager/manager.go index 81e5cc66..31dbe9a8 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -4,7 +4,7 @@ import ( "strconv" "strings" - "github.com/Yiwen-Chan/ZeroBot-Plugin/msgext" + "github.com/Yiwen-Chan/ZeroBot-Plugin/api/msgext" zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/message" ) diff --git a/randimg/setu_geter.go b/randimg/setu_geter.go index 2f8cb31c..2bf3a960 100644 --- a/randimg/setu_geter.go +++ b/randimg/setu_geter.go @@ -3,11 +3,12 @@ package randimg import ( "strings" - "github.com/Yiwen-Chan/ZeroBot-Plugin/msgext" + "github.com/Yiwen-Chan/ZeroBot-Plugin/api/msgext" zero "github.com/wdvxdr1123/ZeroBot" ) var RANDOM_API_URL = "https://api.pixivweb.com/anime18r.php?return=img" +var BLOCK_REQUEST = false func init() { // 插件主体 zero.OnRegex(`^设置随机图片网址(.*)$`, zero.SuperUserPermission).SetBlock(true).SetPriority(20). @@ -23,7 +24,13 @@ func init() { // 插件主体 // 随机图片 zero.OnFullMatchGroup([]string{"随机图片"}).SetBlock(true).SetPriority(24). Handle(func(ctx *zero.Ctx) { - ctx.Send(msgext.ImageNoCache(RANDOM_API_URL)) + if BLOCK_REQUEST { + ctx.Send("请稍后再试哦") + } else { + BLOCK_REQUEST = true + ctx.Send(msgext.ImageNoCache(RANDOM_API_URL)) + BLOCK_REQUEST = false + } return }) }