增加签到3 (#644)

This commit is contained in:
苜蓿紫
2023-03-27 22:43:19 +08:00
committed by GitHub
parent 6ea50cf8b7
commit 864f92a728
5 changed files with 124 additions and 6 deletions

View File

@@ -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
}