Skip to content

Commit

Permalink
fix: plugin score&wordle (#5)
Browse files Browse the repository at this point in the history
* Update sign_in.go

* fix

* fix
  • Loading branch information
Jiang-Red authored Oct 19, 2023
1 parent 849d793 commit 36ca8e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
18 changes: 9 additions & 9 deletions plugin/score/sign_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var (
func init() {
cachePath := engine.DataFolder() + "cache/"
go func() {
sdb = initialize(engine.DataFolder() + "score.db")
ok := file.IsExist(cachePath)
if !ok {
err := os.MkdirAll(cachePath, 0777)
Expand All @@ -60,21 +61,20 @@ func init() {
}
}
}
sdb = initialize(engine.DataFolder() + "score.db")
}()
engine.OnMessageFullMatch("签到").Limit(ctxext.LimitByUser).SetBlock(true).Handle(func(ctx *nano.Ctx) {
uid := ctx.Message.Author.ID
if uid == "" {
_, _ = ctx.SendPlainMessage(false, "ERROR: 未获取到用户uid")
return
}
uidint, _ := strconv.ParseInt(uid, 10, 64)
uidint, _ := strconv.ParseUint(uid, 10, 64)
today := time.Now().Format("20060102")
// 签到图片
drawedFile := cachePath + uid + today + "signin.png"
picFile := cachePath + uid + today + ".png"
// 获取签到时间
si := sdb.GetSignInByUID(uidint)
si := sdb.GetSignInByUID(int64(uidint))
siUpdateTimeStr := si.UpdatedAt.Format("20060102")
switch {
case si.Count >= signinMax && siUpdateTimeStr == today:
Expand All @@ -92,28 +92,28 @@ func init() {
return
case siUpdateTimeStr != today:
// 如果是跨天签到就清数据
err := sdb.InsertOrUpdateSignInCountByUID(uidint, 0)
err := sdb.InsertOrUpdateSignInCountByUID(int64(uidint), 0)
if err != nil {
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
return
}
}
// 更新签到次数
err := sdb.InsertOrUpdateSignInCountByUID(uidint, si.Count+1)
err := sdb.InsertOrUpdateSignInCountByUID(int64(uidint), si.Count+1)
if err != nil {
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
return
}
// 更新经验
level := sdb.GetScoreByUID(uidint).Score + 1
level := sdb.GetScoreByUID(int64(uidint)).Score + 1
if level > SCOREMAX {
level = SCOREMAX
_, err := ctx.SendPlainMessage(true, "你的等级已经达到上限")
if err != nil {
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
}
}
err = sdb.InsertOrUpdateScoreByUID(uidint, level)
err = sdb.InsertOrUpdateScoreByUID(int64(uidint), level)
if err != nil {
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
return
Expand All @@ -123,7 +123,7 @@ func init() {
add := 1 + rand.Intn(10) + rank*5 // 等级越高获得的钱越高

go func() {
err = wallet.InsertWalletOf(uidint, add)
err = wallet.InsertWalletOf(int64(uidint), add)
if err != nil {
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
return
Expand All @@ -135,7 +135,7 @@ func init() {
avatarurl: ctx.Message.Author.Avatar,
nickname: ctx.Message.Author.Username,
inc: add,
score: wallet.GetWalletOf(uidint),
score: wallet.GetWalletOf(int64(uidint)),
level: level,
rank: rank,
}
Expand Down
10 changes: 5 additions & 5 deletions plugin/wordle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ func init() {
for {
select {
case <-tick.C:
_, err := ctx.SendPlainMessage(true, "猜单词, 你还有15s作答时间")
_, err := ctx.SendPlainMessage(false, "猜单词, 你还有15s作答时间")
if err != nil {
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
return
}
case <-after.C:
_, err := ctx.SendPlainMessage(true, "猜单词超时,游戏结束...答案是: ", target, "(", tt, ")")
_, err := ctx.SendPlainMessage(false, "猜单词超时,游戏结束...答案是: ", target, "(", tt, ")")
if err != nil {
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
}
Expand All @@ -180,19 +180,19 @@ func init() {
case err == errTimesRunOut:
tick.Stop()
after.Stop()
_, err := ctx.SendPlainMessage(true, "游戏结束...答案是: ", target, "(", tt, ")")
_, err := ctx.SendPlainMessage(false, "游戏结束...答案是: ", target, "(", tt, ")")
if err != nil {
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
}
return
case err == errLengthNotEnough:
_, err := ctx.SendPlainMessage(true, "单词长度错误")
_, err := ctx.SendChain(nano.ReplyTo(c.Message.ID), nano.Text("单词长度错误"))
if err != nil {
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
return
}
case err == errUnknownWord:
_, err := ctx.SendPlainMessage(true, "你确定存在这样的单词吗?")
_, err := ctx.SendChain(nano.ReplyTo(c.Message.ID), nano.Text("你确定存在这样的单词吗?"))
if err != nil {
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
return
Expand Down

0 comments on commit 36ca8e8

Please sign in to comment.