Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加签到预设切换 #634

Merged
merged 47 commits into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ee96e9b
readme
lianhong2758 Feb 6, 2023
eb5a98d
1
lianhong2758 Feb 6, 2023
8747f61
1
lianhong2758 Feb 6, 2023
836722d
kokomi插件
lianhong2758 Feb 6, 2023
e0606ca
change
lianhong2758 Feb 6, 2023
6815399
1
lianhong2758 Feb 6, 2023
982e3ce
1
lianhong2758 Feb 6, 2023
bb9c6b8
change
lianhong2758 Feb 6, 2023
512b4de
change
lianhong2758 Feb 6, 2023
7bb1050
Merge branch 'master' of github.com:lianhong2758/ZeroBot-Plugin
lianhong2758 Feb 7, 2023
aab4372
修复api失效
lianhong2758 Feb 7, 2023
0186e6a
改了,
lianhong2758 Feb 7, 2023
551f00f
1
lianhong2758 Feb 7, 2023
abf1b72
0
lianhong2758 Feb 7, 2023
4f08fda
Merge branch 'master' of github.com:lianhong2758/ZeroBot-Plugin
lianhong2758 Feb 19, 2023
b073ce0
加快自检速度
lianhong2758 Feb 19, 2023
1a337ba
1
lianhong2758 Feb 19, 2023
a6df63b
2
lianhong2758 Feb 19, 2023
03b6cf4
3
lianhong2758 Feb 19, 2023
1dd8631
4
lianhong2758 Feb 19, 2023
856a5f5
Merge branch 'master' of github.com:lianhong2758/ZeroBot-Plugin
lianhong2758 Feb 19, 2023
92959c4
1
lianhong2758 Feb 19, 2023
9480c88
1
lianhong2758 Feb 19, 2023
74ea439
Merge branch 'master' of github.com:lianhong2758/ZeroBot-Plugin
lianhong2758 Feb 28, 2023
6a6c364
Merge branch 'master' of github.com:lianhong2758/ZeroBot-Plugin
lianhong2758 Feb 28, 2023
84846b0
Merge branch 'master' of github.com:lianhong2758/ZeroBot-Plugin
lianhong2758 Mar 2, 2023
e1c2c0d
Merge branch 'master' of github.com:lianhong2758/ZeroBot-Plugin
lianhong2758 Mar 17, 2023
a287850
fix jiami
lianhong2758 Mar 17, 2023
c8c6060
1
lianhong2758 Mar 17, 2023
201c6f2
百度百科
lianhong2758 Mar 18, 2023
83ae8b5
1
lianhong2758 Mar 18, 2023
4b373be
fix
lianhong2758 Mar 18, 2023
aff23f6
Merge branch 'FloatTech:master' into master
lianhong2758 Mar 18, 2023
f8a71e0
fix
lianhong2758 Mar 18, 2023
f4c45f2
Merge branch 'master' of github.com:lianhong2758/ZeroBot-Plugin
lianhong2758 Mar 18, 2023
eacab9a
fix many bad goods
lianhong2758 Mar 20, 2023
acb7cca
Merge branch 'FloatTech:master' into master
lianhong2758 Mar 22, 2023
ec99949
111
lianhong2758 Mar 22, 2023
705ad61
fix
lianhong2758 Mar 22, 2023
a7beb34
fix
lianhong2758 Mar 22, 2023
c0b7e0c
删除多余注释
lianhong2758 Mar 22, 2023
0f06418
fix
lianhong2758 Mar 22, 2023
dac66ae
add_>inc
lianhong2758 Mar 22, 2023
378053c
fix驼峰
lianhong2758 Mar 22, 2023
e6d8c5d
fix name
lianhong2758 Mar 23, 2023
cdbd4b1
Merge branch 'master' into master
lianhong2758 Mar 24, 2023
4018c2b
不听话的坏坏莲宝😠
fumiama Mar 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 176 additions & 0 deletions plugin/score/draw.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
// Package score 签到,答题得分
package score

import (
"bytes"
"fmt"
"image"
"image/color"
"strconv"
"time"

"github.com/FloatTech/ZeroBot-Plugin/kanban/banner"
"github.com/FloatTech/floatbox/file"
"github.com/FloatTech/gg"
"github.com/FloatTech/imgfactory"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/img/text"
"github.com/disintegration/imaging"
)

func drawScore16(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 Aero Style
aeroStyle := gg.NewContext(imgDX-202, imgDY-202)
aeroStyle.DrawImage(imaging.Blur(back, 2.5), -100, -100)
// aero draw image.
aeroStyle.DrawRoundedRectangle(0, 0, float64(imgDX-200), float64(imgDY-200), 16)
// SideLine
aeroStyle.SetLineWidth(3)
aeroStyle.SetRGBA255(255, 255, 255, 100)
aeroStyle.StrokePreserve()
aeroStyle.SetRGBA255(255, 255, 255, 140)
// fill
aeroStyle.Fill()
// draw background
canvas.DrawImage(back, 0, 0)
// Aero style combine
canvas.DrawImage(aeroStyle.Image(), 100, 100)
canvas.Fill()
hourWord := getHourWord(time.Now())
avatar, _, err := image.Decode(bytes.NewReader(getAvatar))
if err != nil {
return nil, err
}
avatarf := imgfactory.Size(avatar, 200, 200)
canvas.DrawImage(avatarf.Circle(0).Image(), 120, 120)
// draw info(name,coin,etc)
canvas.SetRGB255(0, 0, 0)
data, err := file.GetLazyData(text.BoldFontFile, control.Md5File, true)
if err != nil {
return nil, err
}
if err = canvas.ParseFontFace(data, 50); err != nil {
return nil, err
}
// draw head
canvas.DrawStringWrapped(a.nickname, 350, 180, 0.5, 0.5, 0.5, 0.5, gg.AlignLeft)
canvas.Fill()
// main draw
data, err = file.GetLazyData(text.FontFile, control.Md5File, true)
if err != nil {
return nil, err
}
if err = canvas.ParseFontFace(data, 30); err != nil {
return nil, err
}
canvas.DrawStringAnchored(hourWord, 350, 280, 0, 0)
canvas.DrawStringAnchored("ATRI币 + "+strconv.Itoa(a.inc), 350, 350, 0, 0)
canvas.DrawStringAnchored("当前ATRI币:"+strconv.Itoa(a.score), 350, 400, 0, 0)
canvas.DrawStringAnchored("LEVEL: "+strconv.Itoa(getrank(a.level)), 350, 450, 0, 0)
// draw Info(Time,etc.)
getTime := time.Now().Format("2006-01-02 15:04:05")
getTimeLengthWidth, getTimeLengthHight := canvas.MeasureString(getTime)
canvas.DrawStringAnchored(getTime, float64(imgDX)-100-20-getTimeLengthWidth/2, float64(imgDY)-100-getTimeLengthHight, 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)
getLevelLength, _ := canvas.MeasureString(nextLevelStyle)
canvas.DrawStringAnchored(nextLevelStyle, 100+getLevelLength, float64(imgDY)-100-getTimeLengthHight, 0.5, 0.5) // time
canvas.Fill()
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)
// Gradient
grad := gg.NewLinearGradient(20, 320, 400, 20)
grad.AddColorStop(0, color.RGBA{G: 255, A: 255})
grad.AddColorStop(1, color.RGBA{B: 255, A: 255})
grad.AddColorStop(0.5, color.RGBA{R: 255, A: 255})
canvas.SetStrokeStyle(grad)
canvas.SetLineWidth(4)
// level array with rectangle work.
gradLineLength := float64(imgDX-120) - 120
renderLine := (float64(a.level) / float64(nextrankScore)) * gradLineLength
canvas.MoveTo(120, float64(imgDY)-102)
canvas.LineTo(120+renderLine, float64(imgDY)-102)
canvas.ClosePath()
canvas.Stroke()
return canvas.Image(), nil
}

func drawScore15(a *scdata) (image.Image, error) {
// 绘图
_, 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)
canvas := gg.NewContext(back.Bounds().Size().X, int(float64(back.Bounds().Size().Y)*1.7))
canvas.SetRGB(1, 1, 1)
canvas.Clear()
canvas.DrawImage(back, 0, 0)
monthWord := time.Now().Format("01/02")
hourWord := getHourWord(time.Now())
_, err = file.GetLazyData(text.BoldFontFile, control.Md5File, true)
if err != nil {
return nil, err
}
if err = canvas.LoadFontFace(text.BoldFontFile, float64(back.Bounds().Size().X)*0.1); err != nil {
return nil, err
}
canvas.SetRGB(0, 0, 0)
canvas.DrawString(hourWord, float64(back.Bounds().Size().X)*0.1, float64(back.Bounds().Size().Y)*1.2)
canvas.DrawString(monthWord, float64(back.Bounds().Size().X)*0.6, float64(back.Bounds().Size().Y)*1.2)
_, err = file.GetLazyData(text.FontFile, control.Md5File, true)
if err != nil {
return nil, err
}
if err = canvas.LoadFontFace(text.FontFile, float64(back.Bounds().Size().X)*0.04); err != nil {
return nil, err
}
canvas.DrawString(a.nickname+fmt.Sprintf(" ATRI币+%d", a.inc), float64(back.Bounds().Size().X)*0.1, float64(back.Bounds().Size().Y)*1.3)
canvas.DrawString("当前ATRI币:"+strconv.FormatInt(int64(a.score), 10), float64(back.Bounds().Size().X)*0.1, float64(back.Bounds().Size().Y)*1.4)
canvas.DrawString("LEVEL:"+strconv.FormatInt(int64(a.rank), 10), float64(back.Bounds().Size().X)*0.1, float64(back.Bounds().Size().Y)*1.5)
canvas.DrawRectangle(float64(back.Bounds().Size().X)*0.1, float64(back.Bounds().Size().Y)*1.55, float64(back.Bounds().Size().X)*0.6, float64(back.Bounds().Size().Y)*0.1)
canvas.SetRGB255(150, 150, 150)
canvas.Fill()
var nextrankScore int
if a.rank < 10 {
nextrankScore = rankArray[a.rank+1]
} else {
nextrankScore = SCOREMAX
}
canvas.SetRGB255(0, 0, 0)
canvas.DrawRectangle(float64(back.Bounds().Size().X)*0.1, float64(back.Bounds().Size().Y)*1.55, float64(back.Bounds().Size().X)*0.6*float64(a.level)/float64(nextrankScore), float64(back.Bounds().Size().Y)*0.1)
canvas.SetRGB255(102, 102, 102)
canvas.Fill()
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
}
11 changes: 11 additions & 0 deletions plugin/score/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,14 @@ func (sdb *scoredb) GetScoreRankByTopN(n int) (st []scoretable, err error) {
err = db.Model(&scoretable{}).Order("score desc").Limit(n).Find(&st).Error
return
}

type scdata struct {
lianhong2758 marked this conversation as resolved.
Show resolved Hide resolved
drawedfile string
picfile string
uid int64
nickname string
inc int //增加币
score int //钱包
level int
rank int
}
Loading