From 606aec4ec146e08594b984e87104b2ce56ac0dee Mon Sep 17 00:00:00 2001 From: fumiama Date: Tue, 11 Jan 2022 16:09:33 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9A=20=F0=9F=8E=89=20=F0=9F=93=9D=20?= =?UTF-8?q?=20=E5=90=88=E5=B9=B6=20gif?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- go.mod | 6 +- go.sum | 11 ++- main.go | 2 +- plugin_gif/README.md | 31 ++++++++ plugin_gif/context.go | 91 ++++++++++++++++++++++++ plugin_gif/gif.go | 160 ++++++++++++++++++++++++++++++++++++++++++ plugin_gif/logo.go | 17 +++++ plugin_gif/png.go | 66 +++++++++++++++++ plugin_gif/run.go | 63 +++++++++++++++++ 10 files changed, 436 insertions(+), 13 deletions(-) create mode 100644 plugin_gif/README.md create mode 100644 plugin_gif/context.go create mode 100644 plugin_gif/gif.go create mode 100644 plugin_gif/logo.go create mode 100644 plugin_gif/png.go create mode 100644 plugin_gif/run.go diff --git a/README.md b/README.md index 1f31bca0..82882d0e 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ zerobot [-h] [-t token] [-u url] [-n nickname] [-p prefix] [-d|w] [-g 监听地 - [x] 抽老婆[@xxx] - **AIWife** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_aiwife"` - [x] waifu|随机waifu(从[100000个AI生成的waifu](https://www.thiswaifudoesnotexist.net/)中随机一位) -- **gif** `import _ "github.com/tdf1939/ZeroBot-Plugin-Gif/plugin_gif"` +- **gif** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_gif"` - [x] 爬[@xxx] - [x] 摸[@xxx] - [x] 搓[@xxx] diff --git a/go.mod b/go.mod index 472545c1..d00ebed6 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,8 @@ go 1.17 require ( github.com/FloatTech/AnimeAPI v1.2.0 - github.com/FloatTech/ZeroBot-Plugin-Gif v0.2.6 - github.com/FloatTech/zbpctrl v1.2.3-add1 - github.com/FloatTech/zbputils v1.2.3-add1 + github.com/FloatTech/zbpctrl v1.2.3-add2 + github.com/FloatTech/zbputils v1.2.3-add2 github.com/antchfx/htmlquery v1.2.4 github.com/corona10/goimagehash v1.0.3 github.com/fogleman/gg v1.3.0 @@ -26,7 +25,6 @@ require ( ) require ( - github.com/FloatTech/imgfactory v0.1.1 // indirect github.com/antchfx/xpath v1.2.0 // indirect github.com/disintegration/imaging v1.6.2 // indirect github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4 // indirect diff --git a/go.sum b/go.sum index ac7c7e3e..1fdd2e94 100644 --- a/go.sum +++ b/go.sum @@ -1,14 +1,11 @@ github.com/FloatTech/AnimeAPI v1.2.0 h1:1P6hOEqNOB8EeC7PD5LuIRL9aWRKNVjKF6kP8X1ZYmI= github.com/FloatTech/AnimeAPI v1.2.0/go.mod h1:P2pJSBhflFXJsJPUwhHt13obMVBRc9WJxEKx4bJ+11Q= -github.com/FloatTech/ZeroBot-Plugin-Gif v0.2.6 h1:canagsXdWdQWTRwNq5U80dAc22hMARTICBxssUtOxhI= -github.com/FloatTech/ZeroBot-Plugin-Gif v0.2.6/go.mod h1:umANZgKejUlyBT7c6OfaF8pmnf24QHgqhja94iSpQW4= github.com/FloatTech/bot-manager v1.0.0/go.mod h1:8YYRJ16oroGHQGD2En0oVnmcKJkxR9O/jd5BPSfWfOQ= -github.com/FloatTech/imgfactory v0.1.1 h1:ooL2+fV8yrMhv1ShGGKsN0Rm/flWoKnvqXaUD+dC3DQ= -github.com/FloatTech/imgfactory v0.1.1/go.mod h1:ThDALab8aOuU6KVYESVWFqmjcqtm03e0SvGlTw6s+aw= -github.com/FloatTech/zbpctrl v1.2.3-add1 h1:YkLR95p4SOCv6E2EnQ0qFO1O0mcBi+9n0gRhPUVJddA= -github.com/FloatTech/zbpctrl v1.2.3-add1/go.mod h1:70cC4XawE8bpbYz/OFA6d6uecK8jTc61pUCY5eXMaC0= -github.com/FloatTech/zbputils v1.2.3-add1 h1:gzLw4aa7HhVB7cRUIcJUdFoM/fqxy6yEOXwtt5nw+40= +github.com/FloatTech/zbpctrl v1.2.3-add2 h1:lvBIQOo22RPOrc+ZgzmcyGEuhV36NrKMOemZN/UOoig= +github.com/FloatTech/zbpctrl v1.2.3-add2/go.mod h1:s4ux9AgS8m+30ELebKOf7TpMtZEPJpk8ll3CSv0Oz5s= github.com/FloatTech/zbputils v1.2.3-add1/go.mod h1:+NZ6tqt9lR2ilyiIh/+90tZlSW2pXx0IyOFlpOiqadE= +github.com/FloatTech/zbputils v1.2.3-add2 h1:b+W7+cWriDVcUXh6NLnQ/z6hkrY+FvrJuoAowsUaFrQ= +github.com/FloatTech/zbputils v1.2.3-add2/go.mod h1:OXX382tuGcev9XfWG9aYE+OmbvEKGCXfuM+ZmW9BTLw= github.com/Mrs4s/MiraiGo v0.0.0-20211120033824-43b23f4e6fcb h1:Rkj28fqIwGx/EgBzRYtpmJRfH6wqVn7cNdc7aJ0QE4M= github.com/Mrs4s/MiraiGo v0.0.0-20211120033824-43b23f4e6fcb/go.mod h1:imVKbfKqqeit+C/eaWGb4MKQ3z3gN6pRpBU5RMtp5so= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= diff --git a/main.go b/main.go index 460ca37a..67b0f921 100644 --- a/main.go +++ b/main.go @@ -28,7 +28,6 @@ import ( // 娱乐类 // _ "github.com/FloatTech/ZeroBot-Plugin/plugin_wtf" // 鬼东西 - _ "github.com/FloatTech/ZeroBot-Plugin-Gif" // 制图 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_ai_false" // 服务器监控 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_book_review" // 哀伤雪刃吧推书记录 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_cangtoushi" // 藏头诗 @@ -39,6 +38,7 @@ import ( _ "github.com/FloatTech/ZeroBot-Plugin/plugin_curse" // 骂人 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_fortune" // 运势 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_funny" // 笑话 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_gif" // 制图 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_hs" // 炉石 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_juejuezi" // 绝绝子生成器 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_minecraft" // MCSManager diff --git a/plugin_gif/README.md b/plugin_gif/README.md new file mode 100644 index 00000000..67590918 --- /dev/null +++ b/plugin_gif/README.md @@ -0,0 +1,31 @@ +# ZeroBot-Plugin-Gif +[ZeroBot QQ机器人](https://github.com/wdvxdr1123/ZeroBot)插件,可以制作各种沙雕gif图 +> 素材包地址: https://codechina.csdn.net/u011570312/imagematerials + +## 触发方式 +1. [指令词]+[qq号] 如:爬123456 +2. [指令词]+[图片] 如:爬[图片] +3. [指令词]+[艾特] 如:爬@小H + +## 指令列表 +- [x] 爬 +- [x] 冲 +- [x] 摸 +- [x] 搓 +- [x] 拍 +- [x] 丢 +- [x] 敲 +- [x] 吃 +- [x] 啃 +- [x] 撕 +- [x] 蹭 +- [x] 灰度 +- [x] 上翻 +- [x] 下翻 +- [x] 左翻 +- [x] 右翻 +- [x] 反色 +- [x] 倒放 +- [x] 浮雕 +- [x] 打码 +- [x] 负片 diff --git a/plugin_gif/context.go b/plugin_gif/context.go new file mode 100644 index 00000000..9ca66158 --- /dev/null +++ b/plugin_gif/context.go @@ -0,0 +1,91 @@ +package plugin_gif + +import ( + "bufio" + "io" + "net/http" + "os" + "strconv" + "strings" + + "github.com/sirupsen/logrus" +) + +type context struct { + usrdir string + headimgsdir []string +} + +func dlchan(name string, c *chan *string) { + target := datapath + `materials/` + name + _, err := os.Stat(target) + if err != nil { + download(`https://codechina.csdn.net/u011570312/imagematerials/-/raw/main/`+name, target) + } else { + logrus.Debugln("[gif] dl", name, "exists") + } + *c <- &target +} + +func dlblock(name string) string { + target := datapath + `materials/` + name + _, err := os.Stat(target) + if err != nil { + download(`https://codechina.csdn.net/u011570312/imagematerials/-/raw/main/`+name, target) + } + return target +} + +func dlrange(prefix string, suffix string, end int) *[]chan *string { + c := make([]chan *string, end) + for i := range c { + c[i] = make(chan *string) + go dlchan(prefix+strconv.Itoa(i)+suffix, &c[i]) + } + return &c +} + +// 新的上下文 +func newContext(user int64) *context { + c := new(context) + c.usrdir = datapath + "users/" + strconv.FormatInt(user, 10) + `/` + os.MkdirAll(c.usrdir, 0755) + c.headimgsdir = make([]string, 2) + c.headimgsdir[0] = c.usrdir + "0.gif" + c.headimgsdir[1] = c.usrdir + "1.gif" + return c +} + +// 下载图片 +func download(url, dlpath string) error { + // 创建目录 + var List = strings.Split(dlpath, `/`) + err := os.MkdirAll(strings.TrimSuffix(dlpath, List[len(List)-1]), 0755) + if err != nil { + logrus.Errorln("[gif] mkdir err:", err) + return err + } + res, err := http.Get(url) + if err != nil { + logrus.Errorln("[gif] http get err:", err) + return err + } + // 获得get请求响应的reader对象 + reader := bufio.NewReaderSize(res.Body, 32*1024) + // 创建文件 + file, err := os.Create(dlpath) + if err != nil { + logrus.Errorln("[gif] create file err:", err) + return err + } + // 获得文件的writer对象 + writer := bufio.NewWriter(file) + written, err := io.Copy(writer, reader) + if err != nil { + logrus.Errorln("[gif] copy err:", err) + return err + } + res.Body.Close() + logrus.Debugln("[gif] dl len:", written) + return nil +} diff --git a/plugin_gif/gif.go b/plugin_gif/gif.go new file mode 100644 index 00000000..a1914517 --- /dev/null +++ b/plugin_gif/gif.go @@ -0,0 +1,160 @@ +package plugin_gif + +import ( + "image" + + "github.com/FloatTech/zbputils/img" +) + +// 摸 +func (cc *context) mo() string { + name := cc.usrdir + `摸.gif` + c := dlrange(`mo/`, `.png`, 5) + tou := img.LoadFirstFrame(cc.headimgsdir[0], 0, 0).Circle(0).Im + mo := []*image.NRGBA{ + img.LoadFirstFrame(*<-(*c)[0], 0, 0).InsertBottom(tou, 80, 80, 32, 32).Im, + img.LoadFirstFrame(*<-(*c)[1], 0, 0).InsertBottom(tou, 70, 90, 42, 22).Im, + img.LoadFirstFrame(*<-(*c)[2], 0, 0).InsertBottom(tou, 75, 85, 37, 27).Im, + img.LoadFirstFrame(*<-(*c)[3], 0, 0).InsertBottom(tou, 85, 75, 27, 37).Im, + img.LoadFirstFrame(*<-(*c)[4], 0, 0).InsertBottom(tou, 90, 70, 22, 42).Im, + } + img.SaveGif(img.MergeGif(1, mo), name) + return "file:///" + name +} + +// 搓 +func (cc *context) cuo() string { + name := cc.usrdir + `搓.gif` + c := dlrange(`cuo/`, `.png`, 5) + tou := img.LoadFirstFrame(cc.headimgsdir[0], 110, 110).Circle(0).Im + m1 := img.Rotate(tou, 72, 0, 0) + m2 := img.Rotate(tou, 144, 0, 0) + m3 := img.Rotate(tou, 216, 0, 0) + m4 := img.Rotate(tou, 288, 0, 0) + cuo := []*image.NRGBA{ + img.LoadFirstFrame(*<-(*c)[0], 0, 0).InsertBottomC(tou, 0, 0, 75, 130).Im, + img.LoadFirstFrame(*<-(*c)[1], 0, 0).InsertBottomC(m1.Im, 0, 0, 75, 130).Im, + img.LoadFirstFrame(*<-(*c)[2], 0, 0).InsertBottomC(m2.Im, 0, 0, 75, 130).Im, + img.LoadFirstFrame(*<-(*c)[3], 0, 0).InsertBottomC(m3.Im, 0, 0, 75, 130).Im, + img.LoadFirstFrame(*<-(*c)[4], 0, 0).InsertBottomC(m4.Im, 0, 0, 75, 130).Im, + } + img.SaveGif(img.MergeGif(5, cuo), name) + return "file:///" + name +} + +// 敲 +func (cc *context) qiao() string { + name := cc.usrdir + `敲.gif` + c := dlrange(`qiao/`, `.png`, 2) + tou := img.LoadFirstFrame(cc.headimgsdir[0], 40, 40).Circle(0).Im + qiao := []*image.NRGBA{ + img.LoadFirstFrame(*<-(*c)[0], 0, 0).InsertUp(tou, 40, 33, 57, 52).Im, + img.LoadFirstFrame(*<-(*c)[1], 0, 0).InsertUp(tou, 38, 36, 58, 50).Im, + } + img.SaveGif(img.MergeGif(1, qiao), name) + return "file:///" + name +} + +// 吃 +func (cc *context) chi() string { + name := cc.usrdir + `吃.gif` + c := dlrange(`chi/`, `.png`, 3) + tou := img.LoadFirstFrame(cc.headimgsdir[0], 32, 32).Im + chi := []*image.NRGBA{ + img.LoadFirstFrame(*<-(*c)[0], 0, 0).InsertBottom(tou, 0, 0, 1, 38).Im, + img.LoadFirstFrame(*<-(*c)[1], 0, 0).InsertBottom(tou, 0, 0, 1, 38).Im, + img.LoadFirstFrame(*<-(*c)[2], 0, 0).InsertBottom(tou, 0, 0, 1, 38).Im, + } + img.SaveGif(img.MergeGif(1, chi), name) + return "file:///" + name +} + +// 蹭 +func (cc *context) ceng() string { + name := cc.usrdir + `蹭.gif` + c := dlrange(`ceng/`, `.png`, 6) + tou := img.LoadFirstFrame(cc.headimgsdir[0], 100, 100).Circle(0).Im + tou2 := img.LoadFirstFrame(cc.headimgsdir[1], 100, 100).Circle(0).Im + ceng := []*image.NRGBA{ + img.LoadFirstFrame(*<-(*c)[0], 0, 0).InsertUp(tou, 75, 77, 40, 88).InsertUp(tou2, 77, 103, 102, 81).Im, + img.LoadFirstFrame(*<-(*c)[1], 0, 0).InsertUp(tou, 75, 77, 46, 100).InsertUp(img.Rotate(tou2, 10, 62, 127).Im, 0, 0, 92, 40).Im, + img.LoadFirstFrame(*<-(*c)[2], 0, 0).InsertUp(tou, 75, 77, 67, 99).InsertUp(tou2, 76, 117, 90, 8).Im, + img.LoadFirstFrame(*<-(*c)[3], 0, 0).InsertUp(tou, 75, 77, 52, 83).InsertUp(img.Rotate(tou2, -40, 94, 94).Im, 0, 0, 53, -20).Im, + img.LoadFirstFrame(*<-(*c)[4], 0, 0).InsertUp(tou, 75, 77, 56, 110).InsertUp(img.Rotate(tou2, -66, 132, 80).Im, 0, 0, 78, 40).Im, + img.LoadFirstFrame(*<-(*c)[5], 0, 0).InsertUp(tou, 75, 77, 62, 102).InsertUp(tou2, 71, 100, 110, 94).Im, + } + img.SaveGif(img.MergeGif(8, ceng), name) + return "file:///" + name +} + +// 啃 +func (cc *context) ken() string { + name := cc.usrdir + `啃.gif` + c := dlrange(`ken/`, `.png`, 16) + tou := img.LoadFirstFrame(cc.headimgsdir[0], 100, 100).Im + ken := []*image.NRGBA{ + img.LoadFirstFrame(*<-(*c)[0], 0, 0).InsertBottom(tou, 90, 90, 105, 150).Im, + img.LoadFirstFrame(*<-(*c)[1], 0, 0).InsertBottom(tou, 90, 83, 96, 172).Im, + img.LoadFirstFrame(*<-(*c)[2], 0, 0).InsertBottom(tou, 90, 90, 106, 148).Im, + img.LoadFirstFrame(*<-(*c)[3], 0, 0).InsertBottom(tou, 88, 88, 97, 167).Im, + img.LoadFirstFrame(*<-(*c)[4], 0, 0).InsertBottom(tou, 90, 85, 89, 179).Im, + img.LoadFirstFrame(*<-(*c)[5], 0, 0).InsertBottom(tou, 90, 90, 106, 151).Im, + img.LoadFirstFrame(*<-(*c)[6], 0, 0).Im, + img.LoadFirstFrame(*<-(*c)[7], 0, 0).Im, + img.LoadFirstFrame(*<-(*c)[8], 0, 0).Im, + img.LoadFirstFrame(*<-(*c)[9], 0, 0).Im, + img.LoadFirstFrame(*<-(*c)[10], 0, 0).Im, + img.LoadFirstFrame(*<-(*c)[11], 0, 0).Im, + img.LoadFirstFrame(*<-(*c)[12], 0, 0).Im, + img.LoadFirstFrame(*<-(*c)[13], 0, 0).Im, + img.LoadFirstFrame(*<-(*c)[14], 0, 0).Im, + img.LoadFirstFrame(*<-(*c)[15], 0, 0).Im, + } + img.SaveGif(img.MergeGif(7, ken), name) + return "file:///" + name +} + +// 拍 +func (cc *context) pai() string { + name := cc.usrdir + `拍.gif` + c := dlrange(`pai/`, `.png`, 2) + tou := img.LoadFirstFrame(cc.headimgsdir[0], 30, 30).Circle(0).Im + pai := []*image.NRGBA{ + img.LoadFirstFrame(*<-(*c)[0], 0, 0).InsertUp(tou, 0, 0, 1, 47).Im, + img.LoadFirstFrame(*<-(*c)[1], 0, 0).InsertUp(tou, 0, 0, 1, 67).Im, + } + img.SaveGif(img.MergeGif(1, pai), name) + return "file:///" + name +} + +// 冲 +func (cc *context) chong() string { + name := cc.usrdir + `冲.gif` + c := dlrange(`xqe/`, `.png`, 2) + tou := img.LoadFirstFrame(cc.headimgsdir[0], 0, 0).Circle(0).Im + chong := []*image.NRGBA{ + img.LoadFirstFrame(*<-(*c)[0], 0, 0).InsertUp(tou, 30, 30, 15, 53).Im, + img.LoadFirstFrame(*<-(*c)[1], 0, 0).InsertUp(tou, 30, 30, 40, 53).Im, + } + img.SaveGif(img.MergeGif(1, chong), name) + return "file:///" + name +} + +// 丢 +func (cc *context) diu() string { + name := cc.usrdir + `丢.gif` + c := dlrange(`diu/`, `.png`, 8) + tou := img.LoadFirstFrame(cc.headimgsdir[0], 0, 0).Circle(0).Im + diu := []*image.NRGBA{ + img.LoadFirstFrame(*<-(*c)[0], 0, 0).InsertUp(tou, 32, 32, 108, 36).Im, + img.LoadFirstFrame(*<-(*c)[1], 0, 0).InsertUp(tou, 32, 32, 122, 36).Im, + img.LoadFirstFrame(*<-(*c)[2], 0, 0).Im, + img.LoadFirstFrame(*<-(*c)[3], 0, 0).InsertUp(tou, 123, 123, 19, 129).Im, + img.LoadFirstFrame(*<-(*c)[4], 0, 0).InsertUp(tou, 185, 185, -50, 200).InsertUp(tou, 33, 33, 289, 70).Im, + img.LoadFirstFrame(*<-(*c)[5], 0, 0).InsertUp(tou, 32, 32, 280, 73).Im, + img.LoadFirstFrame(*<-(*c)[6], 0, 0).InsertUp(tou, 35, 35, 259, 31).Im, + img.LoadFirstFrame(*<-(*c)[7], 0, 0).InsertUp(tou, 175, 175, -50, 220).Im, + } + img.SaveGif(img.MergeGif(7, diu), name) + return "file:///" + name +} diff --git a/plugin_gif/logo.go b/plugin_gif/logo.go new file mode 100644 index 00000000..57914a28 --- /dev/null +++ b/plugin_gif/logo.go @@ -0,0 +1,17 @@ +package plugin_gif + +import ( + "strconv" + "strings" +) + +func (c *context) prepareLogos(s ...string) { + for i, v := range s { + _, err := strconv.Atoi(v) + if err != nil { + download("https://gchat.qpic.cn/gchatpic_new//--"+strings.ToUpper(v)+"/0", c.usrdir+strconv.Itoa(i)+".gif") + } else { + download("http://q4.qlogo.cn/g?b=qq&nk="+v+"&s=640", c.usrdir+strconv.Itoa(i)+".gif") + } + } +} diff --git a/plugin_gif/png.go b/plugin_gif/png.go new file mode 100644 index 00000000..71f6154d --- /dev/null +++ b/plugin_gif/png.go @@ -0,0 +1,66 @@ +package plugin_gif + +import ( + "image" + "math/rand" + "strconv" + + "github.com/FloatTech/zbputils/img" +) + +// 爬 +func (cc *context) pa() string { + name := cc.usrdir + `爬.png` + tou := img.LoadFirstFrame(cc.headimgsdir[0], 0, 0).Circle(0).Im + // 随机爬图序号 + rand := rand.Intn(60) + 1 + dc := img.LoadFirstFrame(dlblock(`pa/`+strconv.Itoa(rand)+`.png`), 0, 0). + InsertBottom(tou, 100, 100, 0, 400).Im + img.SavePng(dc, name) + return "file:///" + name +} + +// 撕 +func (cc *context) si() string { + name := cc.usrdir + `撕.png` + tou := img.LoadFirstFrame(cc.headimgsdir[0], 0, 0).Im + im1 := img.Rotate(tou, 20, 380, 380) + im2 := img.Rotate(tou, -12, 380, 380) + dc := img.LoadFirstFrame(dlblock(`si/0.png`), 0, 0). + InsertBottom(im1.Im, im1.W, im1.H, -3, 370). + InsertBottom(im2.Im, im2.W, im2.H, 653, 310).Im + img.SavePng(dc, name) + return "file:///" + name +} + +// 简单 +func (cc *context) other(value ...string) string { + name := cc.usrdir + value[0] + `.png` + // 加载图片 + im := img.LoadFirstFrame(cc.headimgsdir[0], 0, 0) + var a *image.NRGBA + if value[0] == "上翻" || value[0] == "下翻" { + a = im.FlipV().Im + } else if value[0] == "左翻" || value[0] == "右翻" { + a = im.FlipH().Im + } else if value[0] == "反色" { + a = im.Invert().Im + } else if value[0] == "灰度" { + a = im.Grayscale().Im + } else if value[0] == "负片" { + a = im.Invert().Grayscale().Im + } else if value[0] == "浮雕" { + a = im.Convolve3x3().Im + } else if value[0] == "打码" { + a = im.Blur(10).Im + } else if value[0] == "旋转" { + r, _ := strconv.ParseFloat(value[1], 64) + a = img.Rotate(im.Im, r, 0, 0).Im + } else if value[0] == "变形" { + w, _ := strconv.Atoi(value[1]) + h, _ := strconv.Atoi(value[2]) + a = img.Size(im.Im, w, h).Im + } + img.SavePng(a, name) + return "file:///" + name +} diff --git a/plugin_gif/run.go b/plugin_gif/run.go new file mode 100644 index 00000000..9a418abf --- /dev/null +++ b/plugin_gif/run.go @@ -0,0 +1,63 @@ +// Package plugin_gif 制图 +package plugin_gif + +import ( + "math/rand" + "os" + "strconv" + "strings" + "time" + + control "github.com/FloatTech/zbpctrl" + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" +) + +var ( + cmds = []string{"搓", "冲", "摸", "拍", "丢", "吃", "敲", "啃", "蹭", "爬", "撕", + "灰度", "上翻", "下翻", "左翻", "右翻", "反色", "浮雕", "打码", "负片"} + botpath, _ = os.Getwd() + datapath = botpath + "/data/gif/" +) + +func init() { // 插件主体 + os.RemoveAll(datapath) // 清除缓存图片 + rand.Seed(time.Now().UnixNano()) // 设置种子 + control.Register("gif", &control.Options{ + DisableOnDefault: false, + Help: "制图\n- " + strings.Join(cmds, "\n- "), + }).OnRegex(`^(` + strings.Join(cmds, "|") + `)\D*?(\[CQ:(image\,file=([0-9a-zA-Z]{32}).*|at.+?(\d{5,11}))\].*|(\d+))$`). + SetBlock(true).SetPriority(20).Handle(func(ctx *zero.Ctx) { + c := newContext(ctx.Event.UserID) + list := ctx.State["regex_matched"].([]string) + c.prepareLogos(list[4]+list[5]+list[6], strconv.FormatInt(ctx.Event.UserID, 10)) + var picurl string + switch list[1] { + case "爬": + picurl = c.pa() + case "摸": + picurl = c.mo() + case "吃": + picurl = c.chi() + case "啃": + picurl = c.ken() + case "蹭": + picurl = c.ceng() + case "敲": + picurl = c.qiao() + case "搓": + picurl = c.cuo() + case "拍": + picurl = c.pai() + case "丢": + picurl = c.diu() + case "撕": + picurl = c.si() + case "冲": + picurl = c.chong() + default: + picurl = c.other(list[1]) // "灰度", "上翻", "下翻", "左翻", "右翻", "反色", "倒放", "浮雕", "打码", "负片" + } + ctx.SendChain(message.Image(picurl)) + }) +}