diff --git a/common/cool/global.go b/common/cool/global.go index 1fc6682f0..929027b10 100644 --- a/common/cool/global.go +++ b/common/cool/global.go @@ -39,7 +39,7 @@ var DefaultGenerator = utils.NewGen(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC), func init() { // 创建 IdGeneratorOptions 对象,可在构造函数中输入 WorkerId: Logger.SetFlags(glog.F_TIME_STD | glog.F_FILE_LONG | glog.F_ASYNC) //设置flag - Logger.Print(ctx, "初始化日志") + // for i := 0; i < 600; i++ { // glog.Debug(context.Background(), i, "初始化雪花算法", DefaultGenerator.Get()) // } diff --git a/common/rpc/func.go b/common/rpc/func.go index a254e0f89..a5e3cce73 100644 --- a/common/rpc/func.go +++ b/common/rpc/func.go @@ -42,7 +42,6 @@ func ListenFunc(ctx g.Ctx) { time.Sleep(retryDelay) continue } - cool.Logger.Info(ctx, "成功获取 Redis 连接") // 2. 启动心跳保活协程,防止连接因空闲被断开 heartbeatCtx, heartbeatCancel := context.WithCancel(context.Background()) @@ -67,7 +66,7 @@ func ListenFunc(ctx g.Ctx) { _ = conn.Close(ctx) return } - cool.Logger.Debug(ctx, "Redis 心跳发送成功,连接正常") + } } }() @@ -170,7 +169,6 @@ func ListenFight(ctx g.Ctx) { time.Sleep(retryDelay) continue } - cool.Logger.Info(ctx, "成功获取 Redis 连接") // 2. 启动心跳保活协程(完全对齐 ListenFunc 逻辑) heartbeatCtx, heartbeatCancel := context.WithCancel(context.Background()) diff --git a/modules/base/service/base_sys_user.go b/modules/base/service/base_sys_user.go index ce5770f34..f1d77aac2 100644 --- a/modules/base/service/base_sys_user.go +++ b/modules/base/service/base_sys_user.go @@ -114,7 +114,7 @@ func (s *BaseSysUserService) UpdateFreeGold(userId uint32, gold int64) { func (s *BaseSysUserService) UpdateGold(userId uint32, gold int64) { if cool.Config.ServerInfo.IsVip != 0 { - cool.Logger.Info(context.TODO(), "测试服不操作金币") + return } m := cool.DBM(s.Model).Where("id", userId) @@ -141,6 +141,12 @@ func (s *BaseSysUserService) GetEamil(userId string) (res *model.BaseSysUser) { return } +func (s *BaseSysUserService) GetQQ(userId int64) (res *model.BaseSysUser) { + m := cool.DBM(s.Model) + m.Where("qq", userId).FieldsEx("password").Scan(&res) + + return +} func (s *BaseSysUserService) ModifyBefore(ctx context.Context, method string, param g.MapStrAny) (err error) { if method == "Delete" { // 禁止删除超级管理员 diff --git a/modules/config/controller/robot/boss.go b/modules/config/controller/robot/boss.go index 8593e9c70..bcc26017b 100644 --- a/modules/config/controller/robot/boss.go +++ b/modules/config/controller/robot/boss.go @@ -2,8 +2,10 @@ package robot import ( "blazing/common/data/xmlres" + "blazing/cool" "blazing/modules/config/service" "strings" + "time" "github.com/gogf/gf/v2/util/gconv" zero "github.com/wdvxdr1123/ZeroBot" @@ -21,7 +23,7 @@ func init() { var buf strings.Builder r := service.NewTower500Service().Boss(count) //获取第一个配置,因为塔只绑定一组boss,bossid也是0 if len(r) > 0 { - + for _, v := range service.NewBossService().Get(r[0].BossIds[0]) { buf.WriteString("【" + xmlres.PetMAP[int(v.MonID)].DefName + "】" + "\n") @@ -34,7 +36,10 @@ func init() { } } - ctx.Send(buf.String()) + msg := ctx.Send(buf.String()) + cool.Cron.AfterFunc(10*time.Second, func() { + ctx.DeleteMessage(msg) + }) } } diff --git a/modules/config/controller/robot/cdk.go b/modules/config/controller/robot/cdk.go index 71f9ce187..2a49a68fa 100644 --- a/modules/config/controller/robot/cdk.go +++ b/modules/config/controller/robot/cdk.go @@ -1,6 +1,7 @@ package robot import ( + "blazing/cool" "blazing/modules/config/service" "strings" "time" @@ -21,6 +22,9 @@ func init() { } - ctx.Send(strings.Join(cdks, "\n")) + msg := ctx.Send(strings.Join(cdks, "\n")) + cool.Cron.AfterFunc(10*time.Second, func() { + ctx.DeleteMessage(msg) + }) }) } diff --git a/modules/config/controller/robot/egg.go b/modules/config/controller/robot/egg.go index 71de88f88..e21d1df7f 100644 --- a/modules/config/controller/robot/egg.go +++ b/modules/config/controller/robot/egg.go @@ -2,8 +2,10 @@ package robot import ( "blazing/common/data/xmlres" + "blazing/cool" "blazing/modules/config/service" "strings" + "time" zero "github.com/wdvxdr1123/ZeroBot" ) @@ -31,6 +33,9 @@ func init() { } - ctx.Send(strings.Join(cdks, "\n")) + msg := ctx.Send(strings.Join(cdks, "\n")) + cool.Cron.AfterFunc(10*time.Second, func() { + ctx.DeleteMessage(msg) + }) }) } diff --git a/modules/config/controller/robot/eggitem.go b/modules/config/controller/robot/eggitem.go index 94eeabe04..83b92a631 100644 --- a/modules/config/controller/robot/eggitem.go +++ b/modules/config/controller/robot/eggitem.go @@ -2,10 +2,11 @@ package robot import ( "blazing/common/data/xmlres" + "blazing/cool" "blazing/modules/config/service" "strings" + "time" - "github.com/gogf/gf/v2/util/gconv" zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/message" ) @@ -14,27 +15,32 @@ func init() { zero.OnCommand("扭蛋物品"). Handle(func(ctx *zero.Ctx) { - msgs := strings.Fields(ctx.Event.Message.String()) - count := 1 - if len(msgs) > 1 { - count = gconv.Int(msgs[1]) + var buf strings.Builder - } - if count > 10 { - count = 10 - } - var rets []string - for _, v := range service.NewItemService().GetEgg(count) { - - var buf strings.Builder - buf.WriteString(xmlres.ItemsMAP[int(v.ItemId)].Name) - buf.WriteString(": " + gconv.String(v.ItemCnt)) - // 你想加什么格式自己加 - rets = append(rets, buf.String()) + for _, v := range service.NewItemService().AllEgg() { + + buf.WriteString(xmlres.ItemsMAP[int(v.ItemID)].Name + "\n") } - ctx.SendChain(message.At(ctx.Event.Sender.ID), message.Reply(ctx.Event.MessageID), message.Text(strings.Join(rets, "\n"))) + ctx.SendChain(message.At(ctx.Event.Sender.ID), message.Reply(ctx.Event.MessageID), message.Text(buf.String())) }) } +func init() { + zero.OnCommand("扭蛋精灵"). + Handle(func(ctx *zero.Ctx) { + + var cdks []string + for _, v := range service.NewPetRewardService().AllEgg() { + + cdks = append(cdks, xmlres.PetMAP[int(v.MonID)].DefName) + + } + + msg := ctx.Send(strings.Join(cdks, "\n")) + cool.Cron.AfterFunc(10*time.Second, func() { + ctx.DeleteMessage(msg) + }) + }) +} diff --git a/modules/config/controller/robot/eggpet.go b/modules/config/controller/robot/eggpet.go deleted file mode 100644 index ff7abf5ba..000000000 --- a/modules/config/controller/robot/eggpet.go +++ /dev/null @@ -1,24 +0,0 @@ -package robot - -import ( - "blazing/common/data/xmlres" - "blazing/modules/config/service" - "strings" - - zero "github.com/wdvxdr1123/ZeroBot" -) - -func init() { - zero.OnCommand("扭蛋精灵"). - Handle(func(ctx *zero.Ctx) { - - var cdks []string - for _, v := range service.NewPetRewardService().AllEgg() { - - cdks = append(cdks, xmlres.PetMAP[int(v.MonID)].DefName) - - } - - ctx.Send(strings.Join(cdks, "\n")) - }) -} diff --git a/modules/config/controller/robot/fusion.go b/modules/config/controller/robot/fusion.go index 8683948f2..2bdb81e44 100644 --- a/modules/config/controller/robot/fusion.go +++ b/modules/config/controller/robot/fusion.go @@ -2,8 +2,10 @@ package robot import ( "blazing/common/data/xmlres" + "blazing/cool" "blazing/modules/config/service" "strings" + "time" "github.com/gogf/gf/v2/util/gconv" zero "github.com/wdvxdr1123/ZeroBot" @@ -30,6 +32,9 @@ func init() { } - ctx.Send(strings.Join(cdks, "\n")) + msg := ctx.Send(strings.Join(cdks, "\n")) + cool.Cron.AfterFunc(10*time.Second, func() { + ctx.DeleteMessage(msg) + }) }) } diff --git a/modules/config/controller/robot/mappit.go b/modules/config/controller/robot/mappit.go index 883682464..c505faa29 100644 --- a/modules/config/controller/robot/mappit.go +++ b/modules/config/controller/robot/mappit.go @@ -1,9 +1,11 @@ package robot import ( + "blazing/cool" "blazing/modules/config/service" dict "blazing/modules/dict/service" "strings" + "time" "github.com/gogf/gf/v2/util/gconv" zero "github.com/wdvxdr1123/ZeroBot" @@ -32,7 +34,10 @@ func init() { } - ctx.Send(strings.Join(cdks, "\n")) + msg := ctx.Send(strings.Join(cdks, "\n")) + cool.Cron.AfterFunc(10*time.Second, func() { + ctx.DeleteMessage(msg) + }) } } diff --git a/modules/config/service/item.go b/modules/config/service/item.go index 8e7fe73e3..5fa45c03b 100644 --- a/modules/config/service/item.go +++ b/modules/config/service/item.go @@ -38,6 +38,13 @@ func (s *ItemService) GetItemCount(id uint32) data.ItemInfo { } return res } +func (s *ItemService) AllEgg( ) []model.ItemGift { + var item []model.ItemGift + dbm_notenable(s.Model).Where("is_egg", 1).Scan(&item) + + return item + +} func (s *ItemService) GetEgg(count int) []data.ItemInfo { var item []model.ItemGift dbm_notenable(s.Model).Where("is_egg", 1).Scan(&item) diff --git a/modules/player/controller/robot/egg.go b/modules/player/controller/robot/egg.go new file mode 100644 index 000000000..b3a0c6beb --- /dev/null +++ b/modules/player/controller/robot/egg.go @@ -0,0 +1,70 @@ +package robot + +import ( + "blazing/common/data/xmlres" + "blazing/cool" + base "blazing/modules/base/service" + config "blazing/modules/config/service" + "blazing/modules/player/model" + "blazing/modules/player/service" + "strings" + "time" + + "github.com/gogf/gf/v2/util/gconv" + "github.com/gogf/gf/v2/util/grand" + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" +) + +func init() { + zero.OnCommand("扭蛋"). + Handle(func(ctx *zero.Ctx) { + + msgs := strings.Fields(ctx.Event.Message.String()) + count := 1 + if len(msgs) > 1 { + count = gconv.Int(msgs[1]) + + } + if count > 10 { + count = 10 + } + user := base.NewBaseSysUserService().GetQQ(ctx.Event.Sender.ID) + if user == nil { + ctx.Send("未绑定") + return + } + itemservice := service.NewItemService(uint32(user.ID)) + if itemservice.CheakItem(400501) < int64(count) { + ctx.Send("扭蛋币不足") + return + } + var buf strings.Builder + if grand.Meet(int(count), 100) { + r := config.NewPetRewardService().GetEgg() + newPet := model.GenPetInfo(int(r.MonID), int(r.DV), int(r.Nature), int(r.Effect), int(r.Lv), nil, 0) + if grand.Meet(1, 500) { + newPet.RandomByWeightShiny() + } + service.NewPetService(uint32(user.ID)).PetAdd(newPet, 0) + buf.WriteString("恭喜你获得" + xmlres.PetMAP[int(newPet.ID)].DefName + "\n") + + } + + items := config.NewItemService().GetEgg(int(count)) + + for _, item := range items { + + itemservice.UPDATE(uint32(item.ItemId), int(item.ItemCnt)) + buf.WriteString("恭喜你获得" + xmlres.ItemsMAP[int(item.ItemId)].Name + ":" + gconv.String(item.ItemCnt) + "\n") + } + + itemservice.UPDATE(400501, int(-count)) + + msg := ctx.SendChain(message.At(ctx.Event.Sender.ID), message.Reply(ctx.Event.MessageID), message.Text(buf.String())) + cool.Cron.AfterFunc(10*time.Second, func() { + ctx.DeleteMessage(msg) + }) + + }) +} diff --git a/modules/player/controller/robot/gold_list.go b/modules/player/controller/robot/gold_list.go index 5515f9fde..bdd679d5a 100644 --- a/modules/player/controller/robot/gold_list.go +++ b/modules/player/controller/robot/gold_list.go @@ -1,9 +1,11 @@ package robot import ( + "blazing/cool" "blazing/modules/player/service" "bytes" "fmt" + "time" "github.com/fogleman/gg" zero "github.com/wdvxdr1123/ZeroBot" @@ -56,6 +58,9 @@ func init() { // ====================== // 发送图片(zeroBot 标准方式) // ====================== - ctx.Send(message.ImageBytes(buf.Bytes())) + msg := ctx.Send(message.ImageBytes(buf.Bytes())) + cool.Cron.AfterFunc(10*time.Second, func() { + ctx.DeleteMessage(msg) + }) }) }