Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Commit

Permalink
add kiss模块
Browse files Browse the repository at this point in the history
  • Loading branch information
mcoo committed Aug 5, 2021
1 parent c124cc8 commit 511aab6
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 9 deletions.
21 changes: 12 additions & 9 deletions draw/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ func GetAvatar(avatar string) (image.Image, error) {
}
return img, nil
}

func DrawCircle(img image.Image, r int) image.Image {
ava := imaging.Resize(img, r, r, imaging.Lanczos)
c := gg.NewContext(r, r)
// 画圆形
c.DrawCircle(float64(r/2), float64(r/2), float64(r/2))
// 对画布进行裁剪
c.Clip()
c.DrawImage(ava, 0, 0)
return c.Image()
}
func DrawGroupInfo(GroupInfo QunInfo.GroupInfoResult, GroupMemberInfo QunInfo.GroupMembersResult) ([]byte, error) {
bgimg, err := png.Decode(bytes.NewReader(bg))
if err != nil {
Expand All @@ -65,14 +74,8 @@ func DrawGroupInfo(GroupInfo QunInfo.GroupInfoResult, GroupMemberInfo QunInfo.Gr
log.Error()
continue
}
ava = imaging.Resize(ava, 64, 64, imaging.Lanczos)
c := gg.NewContext(64, 64)
// 画圆形
c.DrawCircle(32, 32, 32)
// 对画布进行裁剪
c.Clip()
c.DrawImage(ava, 0, 0)
dc.DrawImage(c.Image(), 16, 136+101*a)

dc.DrawImage(DrawCircle(ava, 64), 16, 136+101*a)

text := TruncateText(dc, fmt.Sprintf("%s (%s)", i.Nickname, i.Uin), 252)
dc.DrawString(text, 96, float64(158+101*a))
Expand Down
177 changes: 177 additions & 0 deletions kiss/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package kiss

import (
"OPQBot-QQGroupManager/Core"
mydraw "OPQBot-QQGroupManager/draw"
"bytes"
"embed"
"encoding/json"
"github.com/mcoo/OPQBot"
"github.com/mcoo/gg"
"github.com/sirupsen/logrus"
"image"
"image/color"
"image/color/palette"
"image/draw"
"image/gif"
"image/png"
"strconv"
"strings"
)

type Module struct {
}

var (
log *logrus.Entry
)

//go:embed static
var static embed.FS
var (
OPERATOR_X = []int{92, 135, 84, 80, 155, 60, 50, 98, 35, 38, 70, 84, 75}
OPERATOR_Y = []int{64, 40, 105, 110, 82, 96, 80, 55, 65, 100, 80, 65, 65}
TARGET_X = []int{58, 62, 42, 50, 56, 18, 28, 54, 46, 60, 35, 20, 40}
TARGET_Y = []int{90, 95, 100, 100, 100, 120, 110, 100, 100, 100, 115, 120, 96}
)

func (m *Module) ModuleInfo() Core.ModuleInfo {
return Core.ModuleInfo{
Name: "Kiss",
Author: "enjoy",
Description: "嘿嘿嘿",
Version: 0,
}
}

type AtMsg struct {
Content string `json:"Content"`
UserExt []struct {
QQNick string `json:"QQNick"`
QQUID int64 `json:"QQUid"`
} `json:"UserExt"`
UserID []int64 `json:"UserID"`
}

var pics []image.Image

func isInPalette(p color.Palette, c color.Color) int {
ret := -1
for i, v := range p {
if v == c {
return i
}
}
return ret
}
func getPalette(m image.Image) color.Palette {
p := color.Palette{color.RGBA{}}
p9 := color.Palette(palette.WebSafe)
b := m.Bounds()
black := false
for y := b.Min.Y; y < b.Max.Y; y++ {
for x := b.Min.X; x < b.Max.X; x++ {
c := m.At(x, y)
cc := p9.Convert(c)
if cc == p9[0] {
black = true
}
if isInPalette(p, cc) == -1 {
p = append(p, cc)
}
}
}
if len(p) < 256 && black == true {
p[0] = color.RGBA{} // transparent
p = append(p, p9[0])
}
return p
}
func DrawKiss(ava1, ava2 image.Image) []byte {
var disposals []byte
var images []*image.Paletted
var delays []int

for i, v := range pics {
bg := gg.NewContextForImage(v)
bg.DrawImage(ava2, TARGET_X[i], TARGET_Y[i])
bg.DrawImage(ava1, OPERATOR_X[i], OPERATOR_Y[i])
img := bg.Image()
cp := getPalette(img)
disposals = append(disposals, gif.DisposalNone) //透明图片需要设置
p := image.NewPaletted(image.Rect(0, 0, bg.Height(), bg.Width()), cp)
draw.Draw(p, p.Bounds(), img, image.Point{}, draw.Src)
images = append(images, p)
delays = append(delays, 0)

}
g := &gif.GIF{
Image: images,
Delay: delays,
LoopCount: 0,
Disposal: disposals,
}
buf := new(bytes.Buffer)
err := gif.EncodeAll(buf, g)
if err != nil {
log.Error(err)
}
return buf.Bytes()
}
func (m *Module) ModuleInit(b *Core.Bot, l *logrus.Entry) error {
log = l
for i := 1; i <= 13; i++ {
picBytes, err := static.ReadFile("static/" + strconv.Itoa(i) + ".png")
if err != nil {
continue
}
pic, err := png.Decode(bytes.NewBuffer(picBytes))
if err != nil {
continue
}
pics = append(pics, pic)
}
_, err := b.AddEvent(OPQBot.EventNameOnGroupMessage, func(qq int64, packet *OPQBot.GroupMsgPack) {
if packet.FromUserID != b.QQ {
if packet.MsgType == "AtMsg" && strings.Contains(packet.Content, "kiss") {
var atInfo AtMsg
if json.Unmarshal([]byte(packet.Content), &atInfo) == nil {
if len(atInfo.UserID) == 1 {
avaTmp1, err := mydraw.GetAvatar("http://q1.qlogo.cn/g?b=qq&s=640&nk=" + strconv.FormatInt(packet.FromUserID, 10))
if err != nil {
log.Error(err)
return
}
avaTmp2, err := mydraw.GetAvatar("http://q1.qlogo.cn/g?b=qq&s=640&nk=" + strconv.FormatInt(atInfo.UserID[0], 10))
if err != nil {
log.Error(err)
return
}
gifPic := DrawKiss(mydraw.DrawCircle(avaTmp1, 40), mydraw.DrawCircle(avaTmp2, 50))
b.SendGroupPicMsg(packet.FromGroupID, "", gifPic)
} else if len(atInfo.UserID) >= 2 {
avaTmp1, err := mydraw.GetAvatar("http://q1.qlogo.cn/g?b=qq&s=640&nk=" + strconv.FormatInt(atInfo.UserID[0], 10))
if err != nil {
log.Error(err)
return
}
avaTmp2, err := mydraw.GetAvatar("http://q1.qlogo.cn/g?b=qq&s=640&nk=" + strconv.FormatInt(atInfo.UserID[1], 10))
if err != nil {
log.Error(err)
return
}
gifPic := DrawKiss(mydraw.DrawCircle(avaTmp1, 40), mydraw.DrawCircle(avaTmp2, 50))
b.SendGroupPicMsg(packet.FromGroupID, "", gifPic)
}
}
}
}
})
if err != nil {
return err
}
return nil
}
func init() {
Core.RegisterModule(&Module{})
}
Binary file added kiss/static/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added kiss/static/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added kiss/static/11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added kiss/static/12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added kiss/static/13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added kiss/static/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added kiss/static/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added kiss/static/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added kiss/static/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added kiss/static/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added kiss/static/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added kiss/static/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added kiss/static/9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"OPQBot-QQGroupManager/androidDns"
_ "OPQBot-QQGroupManager/genAndYiqin"
_ "OPQBot-QQGroupManager/githubManager"
_ "OPQBot-QQGroupManager/kiss"
_ "OPQBot-QQGroupManager/setu"
_ "OPQBot-QQGroupManager/taobao"
_ "OPQBot-QQGroupManager/wordCloud"
Expand Down

0 comments on commit 511aab6

Please sign in to comment.