-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
436 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] 负片 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
} |
Oops, something went wrong.