mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-06 07:19:37 +00:00
增加签到3 (#644)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Package score 签到,答题得分
|
||||
// Package score 签到
|
||||
package score
|
||||
|
||||
import (
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Package score 签到,答题得分
|
||||
// Package score 签到
|
||||
package score
|
||||
|
||||
import (
|
||||
@@ -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 {
|
||||
@@ -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")
|
||||
// 签到图片
|
||||
@@ -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.
|
||||
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user