Ejemplo n.º 1
0
        public static void GlobalDataInit()
        {
            //获取数据库路径
            string DBPath = SugarUtils.GetDataDBPath(SugarUtils.GlobalResDBName);

            Log.Debug("IO", $"获取数据路径{DBPath}");
            //检擦文件是否存在
            IOUtils.CheckFileExists(DBPath);
            //创建数据库链接
            SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath);

            try
            {
                if (!SugarUtils.TableExists <RediveDBVersion>(dbClient))
                {
                    Log.Warning("数据库初始化", "未找到版本记录表 - 创建一个新表");
                    SugarUtils.CreateTable <RediveDBVersion>(dbClient);
                }

                if (!SugarUtils.TableExists <PCRChara>(dbClient))
                {
                    Log.Warning("数据库初始化", "未找到角色资源表 - 创建一个新表");
                    SugarUtils.CreateTable <PCRChara>(dbClient);
                }
            }
            catch (Exception e)
            {
                Log.Fatal("数据库初始化错误", Log.ErrorLogBuilder(e));
                Thread.Sleep(5000);
                Environment.Exit(-1);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 进入下一个boss
 /// </summary>
 /// <param name="guildInfo">公会信息</param>
 /// <returns>
 /// <para><see langword="true"/> 写入成功</para>
 /// <para><see langword="false"/> 数据库错误</para>
 /// </returns>
 public bool GotoNextBoss(GuildInfo guildInfo)
 {
     try
     {
         using SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         //获取下一个boss的信息
         GuildBattleBoss nextBossData = dbClient.Queryable <GuildBattleBoss>()
                                        .Where(i => i.ServerId == guildInfo.ServerId &&
                                               i.Phase == guildInfo.BossPhase &&
                                               i.Order == guildInfo.Order + 1)
                                        .First();
         GuildInfo updateBossData =
             new GuildInfo()
         {
             Order   = guildInfo.Order + 1,
             HP      = nextBossData.HP,
             TotalHP = nextBossData.HP
         };
         return(dbClient.Updateable(updateBossData)
                .UpdateColumns(i => new { i.Order, i.HP, i.TotalHP })
                .Where(i => i.Gid == GuildEventArgs.SourceGroup.Id)
                .ExecuteCommandHasChange());
     }
     catch (Exception e)
     {
         ConsoleLog.Error("Database error", ConsoleLog.ErrorLogBuilder(e));
         return(false);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 设置成员SL
 /// 同时自动下树
 /// 如果只清空则不会修改状态
 /// </summary>
 /// <param name="uid">成员UID</param>
 /// <param name="cleanSL">是否清空SL</param>
 /// <returns>
 /// <para><see langword="true"/> 写入成功</para>
 /// <para><see langword="false"/> 数据库错误</para>
 /// </returns>
 public bool SetMemberSL(long uid, bool cleanSL = false)
 {
     try
     {
         using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         if (cleanSL) //清空SL
         {
             return(dbClient
                    .Updateable <MemberInfo>()
                    .SetColumns(i => new MemberInfo
             {
                 SL = 0
             })
                    .Where(i => i.Gid == GuildEventArgs.SourceGroup.Id && i.Uid == uid)
                    .ExecuteCommandHasChange());
         }
         else //设置新的SL
         {
             return(dbClient
                    .Updateable <MemberInfo>()
                    .SetColumns(i => new MemberInfo
             {
                 Flag = FlagType.IDLE, SL = TimeStamp.GetNowTimeStamp(),
                 Time = TimeStamp.GetNowTimeStamp(), Info = null
             })
                    .Where(i => i.Gid == GuildEventArgs.SourceGroup.Id && i.Uid == uid)
                    .ExecuteCommandHasChange());
         }
     }
     catch (Exception e)
     {
         Log.Error("Database error", Log.ErrorLogBuilder(e));
         return(false);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 更新当前的好感度
 /// </summary>
 public void FavorRateUp()
 {
     try
     {
         //更新好感度数据
         this.CurrentFavorRate++;
         UserData.FavorRate = CurrentFavorRate;  //更新好感度
         using SqlSugarClient SQLiteClient = SugarUtils.CreateSqlSugarClient(DBPath);
         //判断用户记录是否已经存在
         if (IsExists)                        //已存在则更新数据
         {
             UserData.ChatDate = TriggerTime; //更新触发时间
             SQLiteClient.Updateable(UserData).ExecuteCommand();
         }
         else //不存在插入新行
         {
             SQLiteClient.Insertable(UserData).ExecuteCommand(); //向数据库写入新数据
         }
     }
     catch (Exception e)
     {
         SuiseiGroupMessageEventArgs.FromGroup.SendGroupMessage($"数据库出现错误\n请向管理员反馈此错误\n{e}");
         ConsoleLog.Error("suisei签到", $"数据库出现错误\n{e}");
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 向数据库插入一刀数据
 /// </summary>
 /// <param name="uid">出刀者UID</param>
 /// <param name="guildInfo">公会信息</param>
 /// <param name="dmg">伤害</param>
 /// <param name="attackType">出刀类型</param>
 /// <returns>
 /// <para>本次出刀刀号</para>
 /// <para><see langword="-1"/> 数据库错误</para>
 /// </returns>
 public int NewAttack(long uid, GuildInfo guildInfo, long dmg, AttackType attackType)
 {
     try
     {
         using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         //插入一刀数据
         var insertData = new GuildBattle()
         {
             Uid    = uid,
             Time   = TimeStamp.GetNowTimeStamp(),
             Order  = guildInfo.Order,
             Round  = guildInfo.Round,
             Damage = dmg,
             Attack = attackType
         };
         return(dbClient.Insertable(insertData)
                .AS(BattleTableName)
                .ExecuteReturnIdentity());
     }
     catch (Exception e)
     {
         Log.Error("Database error", Log.ErrorLogBuilder(e));
         return(-1);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 更新直播状态
 /// </summary>
 /// <param name="groupId">群号</param>
 /// <param name="biliUserId">B站用户ID</param>
 /// <param name="newStatus">新状态</param>
 public bool UpdateLiveStatus(long groupId, long biliUserId, LiveStatusType newStatus)
 {
     using SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
     //查找是否有历史记录
     if (!dbClient.Queryable <BiliLiveSubscription>()
         .Where(biliLive => biliLive.SubscriptionId == biliUserId &&
                biliLive.Gid == groupId)
         .Any())
     {
         //没有记录插入新行
         return(dbClient.Insertable(new BiliLiveSubscription()
         {
             Gid = groupId,
             SubscriptionId = biliUserId,
             LiveStatus = newStatus
         }).ExecuteCommand() > 0);
     }
     else
     {
         //有记录更新时间
         return(dbClient.Updateable <BiliLiveSubscription>(biliLive =>
                                                           biliLive.LiveStatus == newStatus)
                .Where(biliDynamic => biliDynamic.SubscriptionId == biliUserId &&
                       biliDynamic.Gid == groupId)
                .ExecuteCommandHasChange());
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 修改当前boss血量
 /// </summary>
 /// <param name="guildInfo">公会信息</param>
 /// <param name="curBossHP">更新的HP值</param>
 /// <returns>
 /// <para><see langword="true"/> 写入成功</para>
 /// <para><see langword="false"/> 数据库错误</para>
 /// </returns>
 public bool ModifyBossHP(GuildInfo guildInfo, long curBossHP)
 {
     if (guildInfo == null)
     {
         throw new ArgumentNullException(nameof(guildInfo));
     }
     try
     {
         if (curBossHP > guildInfo.TotalHP)
         {
             throw new ArgumentOutOfRangeException(nameof(curBossHP));
         }
         using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         return(dbClient.Updateable <GuildInfo>()
                .SetColumns(i => new GuildInfo {
             HP = curBossHP
         })
                .Where(guild => guild.Gid == guildInfo.Gid)
                .ExecuteCommandHasChange());
     }
     catch (Exception e)
     {
         Log.Error("Database error", Log.ErrorLogBuilder(e));
         return(false);
     }
 }
Ejemplo n.º 8
0
 public int Update(long groupId, long biliUserId, DateTime updateTime)
 {
     using SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
     //查找是否有历史记录
     if (!dbClient.Queryable <BiliSubscription>()
         .Where(biliDynamic => biliDynamic.SubscriptionId == biliUserId &&
                biliDynamic.Gid == groupId)
         .Any())
     {
         //没有记录插入新行
         return
             (dbClient.Insertable(new BiliSubscription()
         {
             Gid = groupId,
             SubscriptionId = biliUserId,
             UpdateTime = Utils.DateTimeToTimeStamp(updateTime)
         }).ExecuteCommand());
     }
     else
     {
         //有记录更新时间
         return
             (dbClient.Updateable <BiliSubscription>(newBiliDynamic =>
                                                     newBiliDynamic.UpdateTime ==
                                                     Utils.DateTimeToTimeStamp(updateTime))
              .Where(biliDynamic => biliDynamic.SubscriptionId == biliUserId &&
                     biliDynamic.Gid == groupId)
              .ExecuteCommand());
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 获取今天的出刀列表
 /// </summary>
 /// <returns>
 /// <para>出刀表</para>
 /// <para><see langword="null"/> 数据库错误</para>
 /// </returns>
 public List <GuildBattle> GetTodayAttacks(long?uid = null)
 {
     try
     {
         using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         if (uid == null)
         {
             //查询所有人的出刀表
             return(dbClient.Queryable <GuildBattle>()
                    .AS(BattleTableName)
                    .Where(i => i.Time >= BotUtils.GetUpdateStamp())
                    .OrderBy(i => i.Aid)
                    .ToList());
         }
         else
         {
             //查询单独成员的出刀表
             return(dbClient.Queryable <GuildBattle>()
                    .AS(BattleTableName)
                    .Where(i => i.Time >= BotUtils.GetUpdateStamp() && i.Uid == uid)
                    .OrderBy(i => i.Aid)
                    .ToList());
         }
     }
     catch (Exception e)
     {
         Log.Error("Database error", Log.ErrorLogBuilder(e));
         return(null);
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 进入下一个boss
 /// </summary>
 /// <param name="guildInfo">公会信息</param>
 /// <returns>
 /// <para><see langword="true"/> 写入成功</para>
 /// <para><see langword="false"/> 数据库错误</para>
 /// </returns>
 public bool GotoNextBoss(GuildInfo guildInfo)
 {
     try
     {
         using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         //获取下一个boss的信息
         var nextBossData = dbClient.Queryable <GuildBattleBoss>()
                            .Where(i => i.ServerId == guildInfo.ServerId &&
                                   i.Phase == guildInfo.BossPhase &&
                                   i.Order == guildInfo.Order + 1)
                            .First();
         return(dbClient.Updateable <GuildInfo>()
                .SetColumns(i => new GuildInfo()
         {
             Order = guildInfo.Order + 1,
             HP = nextBossData.HP,
             TotalHP = nextBossData.HP
         })
                .Where(i => i.Gid == guildInfo.Gid)
                .ExecuteCommandHasChange());
     }
     catch (Exception e)
     {
         Log.Error("Database error", Log.ErrorLogBuilder(e));
         return(false);
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// 修改会战进度(无视当前出刀进度和历史出刀)
        /// </summary>
        /// <returns>
        /// <para><see langword="true"/> 修改成功</para>
        /// <para><see langword="false"/> 修改失败</para>
        /// </returns>
        public bool ModifyProgress(int round, int bossOrder, long hp, long totalHP, int phase)
        {
            try
            {
                using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);

                //更新数据
                return(dbClient.Updateable <GuildInfo>()
                       .Where(guild => guild.Gid == GuildEventArgs.SourceGroup.Id)
                       .SetColumns(info => new GuildInfo
                {
                    HP = hp,
                    TotalHP = totalHP,
                    Round = round,
                    Order = bossOrder,
                    BossPhase = phase,
                })
                       .ExecuteCommandHasChange());
            }
            catch (Exception e)
            {
                Log.Error("Database error", Log.ErrorLogBuilder(e));
                return(false);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 进入下一个周目
        /// </summary>
        /// <param name="guildInfo">公会信息</param>
        /// <returns>
        /// <para><see langword="true"/> 写入成功</para>
        /// <para><see langword="false"/> 数据库错误</para>
        /// </returns>
        public bool GotoNextRound(GuildInfo guildInfo)
        {
            try
            {
                using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);

                int nextPhase = GetRoundPhase(guildInfo.ServerId, guildInfo.Round + 1);
                //获取下一个周目boss的信息
                GuildBattleBoss nextBossData = dbClient.Queryable <GuildBattleBoss>()
                                               .Where(i => i.ServerId == guildInfo.ServerId &&
                                                      i.Phase == nextPhase &&
                                                      i.Order == 1)
                                               .First();
                return(dbClient.Updateable <GuildInfo>()
                       .SetColumns(i => new GuildInfo()
                {
                    BossPhase = nextBossData.Phase,
                    Order = 1,
                    Round = guildInfo.Round + 1,
                    HP = nextBossData.HP,
                    TotalHP = nextBossData.HP
                })
                       .Where(i => i.Gid == GuildEventArgs.SourceGroup.Id)
                       .ExecuteCommandHasChange());
            }
            catch (Exception e)
            {
                Log.Error("Database error", Log.ErrorLogBuilder(e));
                return(false);
            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// 触发后查找数据库返回读取到的值
 /// </summary>
 /// <returns>状态值
 /// 包含当前好感度和调用数据的Dictionary
 /// "favor_rate":当前的好感度[int]
 /// "use_date":上次调用时间戳[long]
 /// </returns>
 public void SignIn()
 {
     try
     {
         using SqlSugarClient SQLiteClient = SugarUtils.CreateSqlSugarClient(DBPath);
         if (Convert.ToBoolean(
                 SQLiteClient.Queryable <SuiseiData>().Where(user => user.Uid == QQID && user.Gid == GroupId).Count()
                 ))              //查找是否有记录
         {
             //查询数据库数据
             UserData = SQLiteClient.Queryable <SuiseiData>()
                        .Where(userInfo => userInfo.Uid == QQID && userInfo.Gid == GroupId)
                        .First();
             IsExists         = true;
             CurrentFavorRate = UserData.FavorRate; //更新当前好感值
         }
         else //未找到签到记录
         {
             UserData = new SuiseiData   //创建用户初始化数据
             {
                 Uid       = QQID,       //用户QQ
                 Gid       = GroupId,    //用户所在群号
                 FavorRate = 0,          //好感度
                 ChatDate  = TriggerTime //签到时间
             };
             IsExists         = false;
             CurrentFavorRate = 0;
         }
     }
     catch (Exception e)
     {
         SuiseiGroupMessageEventArgs.FromGroup.SendGroupMessage($"数据库出现错误\n请向管理员反馈此错误\n{e}");
         ConsoleLog.Error("suisei签到", $"数据库出现错误\n{e}");
     }
 }
Ejemplo n.º 14
0
 /// <summary>
 /// 结束会战
 /// </summary>
 /// <returns>
 /// <para><see langword="1"/> 成功结束统计</para>
 /// <para><see langword="0"/> 未开始会战</para>
 /// <para><see langword="-1"/> 数据库错误</para>
 /// </returns>
 public int EndBattle()
 {
     try
     {
         using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         if (SugarUtils.TableExists <GuildBattle>(dbClient, BattleTableName))
         {
             Log.Warning("会战管理数据库", "结束一期会战统计删除旧表");
             SugarUtils.DeletTable <GuildBattle>(dbClient, BattleTableName);
             return(dbClient.Updateable <GuildInfo>()
                    .Where(guild => guild.Gid == GuildEventArgs.SourceGroup.Id)
                    .SetColumns(i => new GuildInfo {
                 InBattle = false
             })
                    .ExecuteCommandHasChange()
                 ? 1
                 : -1);
         }
         else
         {
             Log.Info("会战管理数据库", "会战表为空,请确认是否已经开始会战统计");
             return(0);
         }
     }
     catch (Exception e)
     {
         Log.Error("Database error", Log.ErrorLogBuilder(e));
         return(-1);
     }
 }
Ejemplo n.º 15
0
 /// <summary>
 /// 查询今日余刀
 /// 用于查刀和催刀
 /// </summary>
 /// <returns>余刀表</returns>
 public Dictionary <long, int> GetTodayAtkCount()
 {
     try
     {
         using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         return(dbClient.Queryable <GuildBattle>()
                .AS(BattleTableName)
                .Where(attack => attack.Time > BotUtils.GetUpdateStamp() &&
                       attack.Attack != AttackType.Compensate &&
                       attack.Attack != AttackType.CompensateKill)
                .GroupBy(member => member.Uid)
                .Select(member => new
         {
             member.Uid,
             times = SqlFunc.AggregateCount(member.Uid)
         })
                .ToList()
                .ToDictionary(member => member.Uid,
                              member => member.times));
     }
     catch (Exception e)
     {
         Log.Error("Database error", Log.ErrorLogBuilder(e));
         return(null);
     }
 }
Ejemplo n.º 16
0
 /// <summary>
 /// 在接受到群消息时使用
 /// </summary>
 /// <param name="sender">sender object</param>
 /// <param name="eventArgs">CQAppEnableEventArgs类</param>
 public SuiseiDBHelper(object sender, CQGroupMessageEventArgs eventArgs)
 {
     this.QQID    = eventArgs.FromQQ.Id;
     this.GroupId = eventArgs.FromGroup.Id;
     this.Sender  = sender;
     this.SuiseiGroupMessageEventArgs = eventArgs;
     this.TriggerTime = Utils.GetTodayStamp();//触发日期
     DBPath           = SugarUtils.GetDBPath(eventArgs.CQApi.GetLoginQQ().Id.ToString());
 }
Ejemplo n.º 17
0
        /// <summary>
        /// 初始化数据库
        /// </summary>
        /// <param name="eventArgs">CQAppEnableEventArgs</param>
        public static void Init(ConnectEventArgs eventArgs)
        {
            string DBPath = SugarUtils.GetDBPath(eventArgs.LoginUid.ToString());

            ConsoleLog.Debug("IO", $"获取数据路径{DBPath}");
            if (!File.Exists(DBPath))//查找数据文件
            {
                //数据库文件不存在,新建数据库
                ConsoleLog.Warning("数据库初始化", "未找到数据库文件,创建新的数据库");
                Directory.CreateDirectory(Path.GetPathRoot(DBPath) ?? String.Empty);
                File.Create(DBPath).Close();
            }
            SqlSugarClient dbClient = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString      = $"DATA SOURCE={DBPath}",
                DbType                = DbType.Sqlite,
                IsAutoCloseConnection = true,
                InitKeyType           = InitKeyType.Attribute
            });

            try
            {
                if (!SugarUtils.TableExists <SuiseiData>(dbClient)) //彗酱数据库初始化
                {
                    ConsoleLog.Warning("数据库初始化", "未找到慧酱数据表 - 创建一个新表");
                    SugarUtils.CreateTable <SuiseiData>(dbClient);
                }
                if (!SugarUtils.TableExists <MemberInfo>(dbClient)) //成员状态表的初始化
                {
                    ConsoleLog.Warning("数据库初始化", "未找到成员状态表 - 创建一个新表");
                    SugarUtils.CreateTable <MemberInfo>(dbClient);
                }
                if (!SugarUtils.TableExists <BiliSubscription>(dbClient)) //动态记录表的初始化
                {
                    ConsoleLog.Warning("数据库初始化", "未找到动态记录表 - 创建一个新表");
                    SugarUtils.CreateTable <BiliSubscription>(dbClient);
                }
                if (!SugarUtils.TableExists <GuildBattleBoss>(dbClient)) //会战数据表的初始化
                {
                    ConsoleLog.Warning("数据库初始化", "未找到会战数据表 - 创建一个新表");
                    SugarUtils.CreateTable <GuildBattleBoss>(dbClient);
                    //写入初始化数据
                    dbClient.Insertable(GuildBattleBoss.GetInitBossInfos()).ExecuteCommand();
                }
                if (!SugarUtils.TableExists <GuildInfo>(dbClient)) //会战状态表的初始化
                {
                    ConsoleLog.Warning("数据库初始化", "未找到会战状态表 - 创建一个新表");
                    SugarUtils.CreateTable <GuildInfo>(dbClient);
                }
            }
            catch (Exception exception)
            {
                ConsoleLog.Fatal("数据库初始化错误", ConsoleLog.ErrorLogBuilder(exception));
                Thread.Sleep(5000);
                throw;
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 /// 获取对应区服的boss初始化HP
 /// </summary>
 /// <param name="server">区服</param>
 private long GetInitBossHP(Server server)
 {
     using SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
     return(dbClient.Queryable <GuildBattleBoss>()
            .Where(i => i.ServerId == server &&
                   i.Phase == 1 &&
                   i.Order == 1)
            .Select(i => i.HP)
            .First());
 }
Ejemplo n.º 19
0
 /// <summary>
 /// 检查记录的动态是否为最新的
 /// </summary>
 /// <returns></returns>
 public bool IsLatest(long groupId, long biliUserId, DateTime updateTime)
 {
     using SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
     //查询是否存在相同记录subscriptionId
     return(dbClient.Queryable <BiliSubscription>()
            .Where(currDynamic => currDynamic.SubscriptionId == biliUserId &&
                   currDynamic.Gid == groupId &&
                   currDynamic.UpdateTime == Utils.DateTimeToTimeStamp(updateTime))
            .Any());
 }
Ejemplo n.º 20
0
        // public BossDBHelper(object sender, CQGroupMessageEventArgs eventArgs)
        // {
        //     this.Sender = sender;
        //     this.EventArgs = eventArgs;
        //     this.GroupId = eventArgs.FromGroup.Id;
        //     BinPath = LocalDataIO.GetBinFilePath("BrotliParser.exe");
        //     DBPath = SugarUtils.GetDBPath(eventArgs.CQApi);
        //     CacheDBPath = SugarUtils.GetCacheDBPath(eventArgs.CQApi, "redive_cn.db");
        //     CacheDBConfigPath = LocalDataIO.GetGlobalConfigPath(eventArgs.CQApi) + "last_version_cn.json";
        // }
        #endregion

        #region 工具函数(DEBUG)
        public bool GuildExists()
        {
            bool isExists, isExists2;

            using (SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath))
            {
                isExists  = dbClient.Queryable <GuildData>().Where(guild => guild.Gid == 883740678).Any();
                isExists2 = dbClient.Queryable <GuildData>().Where(guild => guild.Gid == 1146619912).Any();
            }
            return(isExists || isExists2);
        }
Ejemplo n.º 21
0
 /// <summary>
 /// 获取指定周目的boss对应阶段
 /// </summary>
 /// <param name="server">区服</param>
 /// <param name="round">指定周目</param>
 /// <returns>
 /// <para>指定周目boss的阶段值</para>
 /// <para>如果没有查询刀则为0</para>
 /// </returns>
 public int GetRoundPhase(Server server, int round)
 {
     using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
     //查找阶段数据
     return(dbClient.Queryable <GuildBattleBoss>()
            .Where(area => area.ServerId == server &&
                   area.RoundFrom <= round && area.RoundTo >= round ||
                   area.RoundFrom <= round && area.RoundTo == -1)
            .Select(phase => phase.Phase)
            .First());
 }
Ejemplo n.º 22
0
        /// <summary>
        /// 初次创建公会
        /// </summary>
        /// <param name="gArea">公会所在区域</param>
        /// <param name="gName">公会名称</param>
        /// <returns>状态值
        /// 0:正常创建
        /// 1:该群公会已存在,更新信息
        /// </returns>
        public int createGuild(string gArea, string gName, long gId)
        {
            try
            {
                int retCode = -1;
                using SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
                var data = new GuildData()
                {
                    GuildName  = gName,
                    ServerArea = gArea,
                    Gid        = gId
                };
                if (dbClient.Queryable <GuildData>().Where(i => i.Gid == gId).Any())
                {
                    retCode = 1;
                    dbClient.Updateable <GuildData>(data).Where(i => i.Gid == gId).ExecuteCommand();
                }
                else
                {
                    retCode = 0;
                    dbClient.Insertable <GuildData>(data).ExecuteCommand();
                }

                //TODO 改用ORM
                // SQLiteHelper dbHelper = new SQLiteHelper(DBPath);
                // dbHelper.OpenDB();
                // if (Convert.ToBoolean(dbHelper.GetCount(GuildTableName, GPrimaryColName, GuildId))) //查找是否有记录
                // {
                //     //已存在,则更新信息
                //     dbHelper.UpdateData(GuildTableName, "name", gName, GPrimaryColName, GuildId);
                //     dbHelper.UpdateData(GuildTableName, "server", gArea, GPrimaryColName, GuildId);
                //     dbHelper.CloseDB();
                //     return 1;
                // }
                // else //未找到,初次创建
                // {
                //     string[] GuildInitData = //创建用户初始化数据数组
                //     {
                //         GroupId.ToString(), //所在群号
                //         gName,              //公会名
                //         gArea               //所在区服
                //     };
                //     dbHelper.InsertRow(GuildTableName, GColName, GuildInitData); //向数据库写入新数据
                //     dbHelper.CloseDB();
                //     return 0;
                // }
                return(retCode);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 23
0
        private static string DBPath;                                              //数据库路径

        #endregion

        #region 构造函数

        /// <summary>
        /// 在接受到群消息时使用
        /// </summary>
        /// <param name="sender">sender object</param>
        /// <param name="eventArgs">CQAppEnableEventArgs类</param>
        /// <param name="time">触发时间</param>
        public GuildManagerDBHelper(object sender, CQGroupMessageEventArgs eventArgs)
        {
            this.QQID      = eventArgs.FromQQ.Id;
            this.GroupId   = eventArgs.FromGroup.Id;
            this.Sender    = sender;
            this.EventArgs = eventArgs;
            GuildId        = new string[] //公会信息
            {
                GroupId.ToString(),       //公会所在群号
            };
            DBPath = SugarUtils.GetDBPath(eventArgs.CQApi.GetLoginQQ().Id.ToString());
        }
Ejemplo n.º 24
0
 /// <summary>
 /// 获取公会成员数
 /// </summary>
 /// <param name="gid">公会群号</param>
 /// <returns>
 /// <para>成员数</para>
 /// <para><see langword="-1"/> 数据库错误</para>
 /// </returns>
 public int GetMemberCount(long gid)
 {
     try
     {
         using SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         return(dbClient.Queryable <MemberInfo>().Where(guild => guild.Gid == gid).Count());
     }
     catch (Exception e)
     {
         ConsoleLog.Error("Database error", ConsoleLog.ErrorLogBuilder(e));
         return(-1);
     }
 }
Ejemplo n.º 25
0
 /// <summary>
 /// 检查是否已进入会战
 /// </summary>
 /// <returns>
 /// <para><see langword="1"/> 已经入</para>
 /// <para><see langword="0"/> 未进入</para>
 /// <para><see langword="-1"/> 数据库错误</para>
 /// </returns>
 public int CheckInBattle()
 {
     try
     {
         using var dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         return(dbClient.Queryable <GuildInfo>().InSingle(GuildEventArgs.SourceGroup.Id).InBattle ? 1 : 0);
     }
     catch (Exception e)
     {
         Log.Error("Database error", Log.ErrorLogBuilder(e));
         return(-1);
     }
 }
Ejemplo n.º 26
0
 /// <summary>
 /// 更新数据库版本信息
 /// </summary>
 /// <param name="newVersion">新版本信息</param>
 internal bool UpdateVersionInfo(RediveDBVersion newVersion)
 {
     using SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(ResDBPath);
     //查找版本信息是否存在
     if (dbClient.Queryable <RediveDBVersion>().Where(ver => ver.Server == newVersion.Server).Any())
     {
         return(dbClient.Updateable(newVersion).ExecuteCommandHasChange());
     }
     else
     {
         return(dbClient.Insertable(newVersion).ExecuteCommand() > 0);
     }
 }
Ejemplo n.º 27
0
 /// <summary>
 /// 由角色ID查找角色信息
 /// </summary>
 /// <param name="charaId">角色ID</param>
 internal PCRChara FindChara(int charaId)
 {
     try
     {
         using SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         return(dbClient.Queryable <PCRChara>().InSingle(charaId));
     }
     catch (Exception e)
     {
         Log.Error("数据库错误", Log.ErrorLogBuilder(e));
         return(null);
     }
 }
Ejemplo n.º 28
0
        /// <summary>
        /// 初始化数据库
        /// </summary>
        /// <param name="e">CQAppEnableEventArgs</param>
        public static void Init(CQAppEnableEventArgs e)
        {
            string DBPath = SugarUtils.GetDBPath(e.CQApi.GetLoginQQ().Id.ToString());

            ConsoleLog.Info("IO", $"获取数据路径{DBPath}");
            if (!File.Exists(DBPath))//查找数据文件
            {
                //数据库文件不存在,新建数据库
                ConsoleLog.Warning("数据库初始化", "未找到数据库文件,创建新的数据库");
                Directory.CreateDirectory(Path.GetPathRoot(DBPath));
                File.Create(DBPath).Close();
            }
            SqlSugarClient dbClient = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString      = $"DATA SOURCE={DBPath}",
                DbType                = DbType.Sqlite,
                IsAutoCloseConnection = true,
                InitKeyType           = InitKeyType.Attribute
            });

            if (!SugarUtils.TableExists <SuiseiData>(dbClient)) //彗酱数据库初始化
            {
                ConsoleLog.Warning("数据库初始化", "未找到慧酱数据表 - 创建一个新表");
                SugarUtils.CreateTable <SuiseiData>(dbClient);
            }
            if (!SugarUtils.TableExists <GuildData>(dbClient)) //公会数据库初始化
            {
                ConsoleLog.Warning("数据库初始化", "未找到公会表数据表 - 创建一个新表");
                SugarUtils.CreateTable <GuildData>(dbClient);
            }
            if (!SugarUtils.TableExists <MemberData>(dbClient)) //公会成员数据库初始化
            {
                ConsoleLog.Warning("数据库初始化", "未找到成员表数据表 - 创建一个新表");
                SugarUtils.CreateTable <MemberData>(dbClient);
            }
            if (!SugarUtils.TableExists <MemberStatus>(dbClient))//成员状态表的初始化
            {
                ConsoleLog.Warning("数据库初始化", "未找到成员状态表 - 创建一个新表");
                SugarUtils.CreateTable <MemberStatus>(dbClient);
            }
            if (!SugarUtils.TableExists <BossInfo>(dbClient))//Boss信息表的初始化
            {
                ConsoleLog.Warning("数据库初始化", "未找到Boss信息表 - 创建一个新表");
                SugarUtils.CreateTable <BossInfo>(dbClient);
            }
            if (!SugarUtils.TableExists <BiliSubscription>(dbClient)) //动态记录表的初始化
            {
                ConsoleLog.Warning("数据库初始化", "未找到动态记录表 - 创建一个新表");
                SugarUtils.CreateTable <BiliSubscription>(dbClient);
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// 初次创建公会
        /// </summary>
        /// <param name="gArea">公会所在区域</param>
        /// <param name="gName">公会名称</param>
        /// <param name="gId">公会所在群号</param>
        /// <returns>状态值
        /// 0:正常创建
        /// 1:该群公会已存在,更新信息
        /// -1:数据库出错
        /// </returns>
        public int CreateGuild(Server gArea, string gName, long gId)
        {
            try
            {
                int  retCode;
                long initHP = GetInitBossHP(gArea);
                using SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
                //更新信息时不需要更新公会战信息
                if (dbClient.Queryable <GuildInfo>().Where(i => i.Gid == gId).Any())
                {
                    var data = new GuildInfo()
                    {
                        GuildName = gName,
                        ServerId  = gArea,
                        Gid       = gId
                    };
                    retCode = dbClient.Updateable(data)
                              .UpdateColumns(guildInfo =>
                                             new { guildInfo.GuildName, guildInfo.ServerId, guildInfo.Gid })
                              .Where(i => i.Gid == gId)
                              .ExecuteCommandHasChange()
                        ? 1
                        : -1;
                }
                else
                {
                    //会战进度表
                    var bossStatusData = new GuildInfo
                    {
                        BossPhase = 1,
                        Gid       = gId,
                        HP        = initHP,
                        InBattle  = false,
                        Order     = 1,
                        Round     = 1,
                        TotalHP   = initHP,
                        GuildName = gName,
                        ServerId  = gArea
                    };
                    retCode = dbClient.Insertable(bossStatusData).ExecuteCommand() > 0 ? 0 : -1;
                }

                return(retCode);
            }
            catch (Exception e)
            {
                ConsoleLog.Error("Database", ConsoleLog.ErrorLogBuilder(e));
                return(-1);
            }
        }
Ejemplo n.º 30
0
 /// <summary>
 /// 获取公会信息
 /// </summary>
 /// <param name="gid"></param>
 /// <returns>
 /// <para>成员信息</para>
 /// <para><see langword="null"/> 数据库错误</para>
 /// </returns>
 public GuildInfo GetGuildInfo(long gid)
 {
     try
     {
         using SqlSugarClient dbClient = SugarUtils.CreateSqlSugarClient(DBPath);
         return(dbClient.Queryable <GuildInfo>()
                .InSingle(GuildEventArgs.SourceGroup.Id));        //单主键查询
     }
     catch (Exception e)
     {
         ConsoleLog.Error("Database error", ConsoleLog.ErrorLogBuilder(e));
         return(null);
     }
 }