Skip to content

Commit

Permalink
🚚 🎉 📝 合并 gif
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Jan 11, 2022
1 parent 7f0f211 commit 606aec4
Show file tree
Hide file tree
Showing 10 changed files with 436 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 4 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" // 藏头诗
Expand All @@ -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
Expand Down
31 changes: 31 additions & 0 deletions plugin_gif/README.md
Original file line number Diff line number Diff line change
@@ -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] 负片
91 changes: 91 additions & 0 deletions plugin_gif/context.go
Original file line number Diff line number Diff line change
@@ -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
}
160 changes: 160 additions & 0 deletions plugin_gif/gif.go
Original file line number Diff line number Diff line change
@@ -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
}
17 changes: 17 additions & 0 deletions plugin_gif/logo.go
Original file line number Diff line number Diff line change
@@ -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")
}
}
}
Loading

0 comments on commit 606aec4

Please sign in to comment.