diff --git a/plugin/score/coin.go b/plugin/score/coin.go index 6c54c3b..46fd639 100644 --- a/plugin/score/coin.go +++ b/plugin/score/coin.go @@ -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 diff --git a/plugin/tools/main.go b/plugin/tools/main.go index f89b8a7..0cbf890 100644 --- a/plugin/tools/main.go +++ b/plugin/tools/main.go @@ -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" @@ -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", @@ -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 { diff --git a/utils/toolchain/toolchain.go b/utils/toolchain/toolchain.go index 3ea4eb9..31387a7 100644 --- a/utils/toolchain/toolchain.go +++ b/utils/toolchain/toolchain.go @@ -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 +}