Skip to content

Commit

Permalink
add data update feature
Browse files Browse the repository at this point in the history
  • Loading branch information
MoYoez committed Nov 21, 2023
1 parent eb3f1e1 commit 5ea40ea
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
1 change: 0 additions & 1 deletion plugin/score/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ func init() {
si := coins.GetSignInByUID(sdb, uid)
ctx.SendPlainMessage(true, "你的柠檬片数量一共是: "+strconv.Itoa(si.Coins))
})

engine.OnMessageCommand("coinrob").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *rei.Ctx) {
_, getCommandSplitInt := toolchain.SplitCommandTo(ctx.Message.Text, 3)
// handler
Expand Down
43 changes: 28 additions & 15 deletions plugin/tools/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"time"

"github.com/FloatTech/ReiBot-Plugin/utils/CoreFactory"
"github.com/FloatTech/ReiBot-Plugin/utils/toolchain"
ctrl "github.com/FloatTech/zbpctrl"
rei "github.com/fumiama/ReiBot"
Expand All @@ -22,22 +23,21 @@ var engine = rei.Register("tools", &ctrl.Options[*rei.Ctx]{
})

func init() {
engine.OnMessageCommand("leave", rei.SuperUserPermission).SetBlock(true).
Handle(func(ctx *rei.Ctx) {
arg := strings.TrimSpace(ctx.State["args"].(string))
var gid int64
var err error
if arg != "" {
gid, err = strconv.ParseInt(arg, 10, 64)
if err != nil {
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
return
}
} else {
gid = ctx.Message.Chat.ID
engine.OnMessageCommand("leave", rei.SuperUserPermission).SetBlock(true).Handle(func(ctx *rei.Ctx) {
arg := strings.TrimSpace(ctx.State["args"].(string))
var gid int64
var err error
if arg != "" {
gid, err = strconv.ParseInt(arg, 10, 64)
if err != nil {
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
return
}
_, _ = ctx.Caller.Send(&tgba.LeaveChatConfig{ChatID: gid})
})
} else {
gid = ctx.Message.Chat.ID
}
_, _ = ctx.Caller.Send(&tgba.LeaveChatConfig{ChatID: gid})
})
engine.OnMessageCommand("status").SetBlock(true).Handle(func(ctx *rei.Ctx) {
ctx.SendPlainMessage(false, "* Hosted On Azure JP Cloud.\n",
"* CPU Usage: ", cpuPercent(), "%\n",
Expand All @@ -48,6 +48,19 @@ func init() {
engine.OnMessage().SetBlock(false).Handle(func(ctx *rei.Ctx) {
toolchain.FastSaveUserStatus(ctx)
})
engine.OnMessageCommand("dataupdate").SetBlock(true).Handle(func(ctx *rei.Ctx) {
if !toolchain.GetTheTargetIsNormalUser(ctx) {
return
}
getUserName := ctx.Message.From.UserName
getUserID := ctx.Message.From.ID
newUserName := CoreFactory.GetUserSampleUserinfobyid(getUserID).UserName
if newUserName == getUserName {
ctx.SendPlainMessage(true, "不需要更新的~用户名为最新w")
return
}
CoreFactory.StoreUserDataBase(getUserID, newUserName)
})
}

func cpuPercent() float64 {
Expand Down
13 changes: 13 additions & 0 deletions utils/toolchain/toolchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,16 @@ func ListEntitiesMention(ctx *rei.Ctx) []string {
}
return tempList
}

// GetUserIDFromUserName with @, only works when the data saved.
func GetUserIDFromUserName(ctx *rei.Ctx, userName string) int64 {
getUserData := CoreFactory.GetUserSampleUserinfo(strings.Replace(userName, "@", "", 1))
if getUserData.UserID == 0 {
return 0
}
// check the user is in group?
if !CheckIfthisUserInThisGroup(getUserData.UserID, ctx) {
return 0
}
return getUserData.UserID
}

0 comments on commit 5ea40ea

Please sign in to comment.