Skip to content

Commit

Permalink
增加签到3 (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
medicago087 authored Mar 27, 2023
1 parent 6ea50cf commit 864f92a
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,7 @@ print("run[CQ:image,file="+j["img"]+"]")

- [x] 签到
- [x] 获得签到背景[@xxx] | 获得签到背景
- [x] 设置[默认]签到预设(1~9)
- [x] 查看等级排名
- 注:跨群排行
- [x] 查看我的钱包
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/FloatTech/sqlite v1.5.7
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b
github.com/FloatTech/zbpctrl v1.5.3-0.20230316111343-dd078fa43fe3
github.com/FloatTech/zbputils v1.6.2-0.20230316111555-2d1ec958de04
github.com/FloatTech/zbputils v1.6.2-0.20230320041820-731f824ff8f4
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5
github.com/antchfx/htmlquery v1.2.5
Expand All @@ -24,7 +24,6 @@ require (
github.com/fumiama/go-base16384 v1.6.4
github.com/fumiama/go-registry v0.2.6
github.com/fumiama/gotracemoe v0.0.3
github.com/fumiama/imgsz v0.0.2
github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565
github.com/fumiama/unibase2n v0.0.0-20221020155353-02876e777430
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
Expand Down Expand Up @@ -52,6 +51,7 @@ require (
github.com/faiface/beep v1.1.0 // indirect
github.com/fumiama/go-simple-protobuf v0.1.0 // indirect
github.com/fumiama/gofastTEA v0.0.10 // indirect
github.com/fumiama/imgsz v0.0.2 // indirect
github.com/gabriel-vasile/mimetype v1.0.4 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ github.com/FloatTech/zbpctrl v1.5.3-0.20230316111343-dd078fa43fe3 h1:mCVrTvS2LMN
github.com/FloatTech/zbpctrl v1.5.3-0.20230316111343-dd078fa43fe3/go.mod h1:IagyEhY38VcbbQgVRzAM9f9mhaUn90rM5BTPfudtl1g=
github.com/FloatTech/zbputils v1.6.2-0.20230316111555-2d1ec958de04 h1:ovL+7SAPTBCXy6XNRSdJhNvHtbueWCwEb/jtztmizAc=
github.com/FloatTech/zbputils v1.6.2-0.20230316111555-2d1ec958de04/go.mod h1:jUmX4WBgGRcfjGeIobmVao10AHmXtL3gT00qLbx3/yo=
github.com/FloatTech/zbputils v1.6.2-0.20230320041820-731f824ff8f4 h1:OrqldcPSJWnPxZtmkOd9HJmFFD3rl0Qrob89rHHpoXw=
github.com/FloatTech/zbputils v1.6.2-0.20230320041820-731f824ff8f4/go.mod h1:jUmX4WBgGRcfjGeIobmVao10AHmXtL3gT00qLbx3/yo=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e h1:wR3MXQ3VbUlPKOOUwLOYgh/QaJThBTYtsl673O3lqSA=
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e/go.mod h1:vD7Ra3Q9onRtojoY5sMCLQ7JBgjUsrXDnDKyFxqpf9w=
Expand Down
96 changes: 95 additions & 1 deletion plugin/score/draw.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package score 签到,答题得分
// Package score 签到
package score

import (
Expand Down Expand Up @@ -175,3 +175,97 @@ func drawScore15(a *scdata) (image.Image, error) {
canvas.DrawString(fmt.Sprintf("%d/%d", a.level, nextrankScore), float64(back.Bounds().Size().X)*0.75, float64(back.Bounds().Size().Y)*1.62)
return canvas.Image(), nil
}

func drawScore17(a *scdata) (image.Image, error) {
getAvatar, err := initPic(a.picfile, a.uid)
if err != nil {
return nil, err
}
back, err := gg.LoadImage(a.picfile)
if err != nil {
return nil, err
}
// 避免图片过大,最大 1280*720
back = imgfactory.Limit(back, 1280, 720)
imgDX := back.Bounds().Dx()
imgDY := back.Bounds().Dy()
canvas := gg.NewContext(imgDX, imgDY)

// draw background
canvas.DrawImage(back, 0, 0)

// Create smaller Aero Style boxes
createAeroBox := func(x, y, width, height float64) {
aeroStyle := gg.NewContext(int(width), int(height))
aeroStyle.DrawRoundedRectangle(0, 0, width, height, 8)
aeroStyle.SetLineWidth(2)
aeroStyle.SetRGBA255(255, 255, 255, 100)
aeroStyle.StrokePreserve()
aeroStyle.SetRGBA255(255, 255, 255, 140)
aeroStyle.Fill()
canvas.DrawImage(aeroStyle.Image(), int(x), int(y))
}

// draw aero boxes for text
createAeroBox(20, float64(imgDY-120), 280, 100) // left bottom
createAeroBox(float64(imgDX-272), float64(imgDY-60), 252, 40) // right bottom

// draw info(name, coin, etc)
hourWord := getHourWord(time.Now())
canvas.SetRGB255(0, 0, 0)
data, err := file.GetLazyData(text.MaokenFontFile, control.Md5File, true)
if err != nil {
return nil, err
}
if err = canvas.ParseFontFace(data, 24); err != nil {
return nil, err
}
getNameLengthWidth, _ := canvas.MeasureString(a.nickname)
// draw aero box
if getNameLengthWidth > 140 {
createAeroBox(20, 40, 140+getNameLengthWidth, 100) // left top
} else {
createAeroBox(20, 40, 280, 100) // left top
}

// draw avatar
avatar, _, err := image.Decode(bytes.NewReader(getAvatar))
if err != nil {
return nil, err
}
avatarf := imgfactory.Size(avatar, 100, 100)
canvas.DrawImage(avatarf.Circle(0).Image(), 30, 20)

canvas.DrawString(a.nickname, 140, 80)
canvas.DrawStringAnchored(hourWord, 140, 120, 0, 0)

if err = canvas.ParseFontFace(data, 20); err != nil {
return nil, err
}
canvas.DrawStringAnchored("ATRI币 + "+strconv.Itoa(a.inc), 40, float64(imgDY-90), 0, 0)
canvas.DrawStringAnchored("当前ATRI币:"+strconv.Itoa(a.score), 40, float64(imgDY-60), 0, 0)
canvas.DrawStringAnchored("LEVEL: "+strconv.Itoa(getrank(a.level)), 40, float64(imgDY-30), 0, 0)

// Draw Info(Time, etc.)
getTime := time.Now().Format("2006-01-02 15:04:05")
canvas.DrawStringAnchored(getTime, float64(imgDX)-146, float64(imgDY)-40, 0.5, 0.5) // time
var nextrankScore int
if a.rank < 10 {
nextrankScore = rankArray[a.rank+1]
} else {
nextrankScore = SCOREMAX
}
nextLevelStyle := strconv.Itoa(a.level) + "/" + strconv.Itoa(nextrankScore)
canvas.DrawStringAnchored(nextLevelStyle, 190, float64(imgDY-30), 0, 0) // time

// Draw Zerobot-Plugin information
canvas.SetRGB255(255, 255, 255)
if err = canvas.ParseFontFace(data, 20); err != nil {
return nil, err
}
canvas.DrawStringAnchored("Created By Zerobot-Plugin "+banner.Version, float64(imgDX)/2, float64(imgDY)-20, 0.5, 0.5) // zbp
canvas.SetRGB255(0, 0, 0)
canvas.DrawStringAnchored("Created By Zerobot-Plugin "+banner.Version, float64(imgDX)/2-3, float64(imgDY)-19, 0.5, 0.5) // zbp
canvas.SetRGB255(255, 255, 255)
return canvas.Image(), nil
}
27 changes: 24 additions & 3 deletions plugin/score/sign_in.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package score 签到,答题得分
// Package score 签到
package score

import (
Expand Down Expand Up @@ -40,7 +40,7 @@ var (
engine = control.Register("score", &ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Brief: "签到",
Help: "- 签到\n- 获得签到背景[@xxx] | 获得签到背景\n- 查看等级排名\n注:为跨群排名\n- 查看我的钱包\n- 查看钱包排名\n注:为本群排行,若群人数太多不建议使用该功能!!!",
Help: "- 签到\n- 获得签到背景[@xxx] | 获得签到背景\n- 设置[默认]签到预设(1~9)\n- 查看等级排名\n注:为跨群排名\n- 查看我的钱包\n- 查看钱包排名\n注:为本群排行,若群人数太多不建议使用该功能!!!",
PrivateDataFolder: "score",
})
initDef = fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
Expand Down Expand Up @@ -83,6 +83,10 @@ func init() {
_ = m.Manager.GetExtra(defKeyID, &key)
}
}
if !isExist(key) {
ctx.SendChain(message.Text("未找到签到设定:", key)) // 避免签到配置错误造成无图发送,但是已经签到的情况
return
}
uid := ctx.Event.UserID
today := time.Now().Format("20060102")
// 签到图片
Expand Down Expand Up @@ -156,8 +160,14 @@ func init() {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
case "3":
drawimage, err = drawScore17(&alldata)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
default:
ctx.SendChain(message.Text("未找到签到设定:", key))
ctx.SendChain(message.Text("未添加签到设定:", key))
return
}
// done.
Expand Down Expand Up @@ -274,6 +284,10 @@ func init() {
} else {
s := ctx.State["regex_matched"].([]string)[1]
key := ctx.State["regex_matched"].([]string)[2]
if !isExist(key) {
ctx.SendChain(message.Text("未找到签到设定:", key)) // 避免签到配置错误
return
}
gid := ctx.Event.GroupID
if gid == 0 {
gid = -ctx.Event.UserID
Expand Down Expand Up @@ -339,3 +353,10 @@ func initPic(picFile string, uid int64) (avatar []byte, err error) {
}
return avatar, os.WriteFile(picFile, data, 0644)
}

func isExist(key string) bool {
if key != "1" && key != "2" && key != "3" {
return false
}
return true
}

0 comments on commit 864f92a

Please sign in to comment.