Exemplo n.º 1
0
 public override async Task <IEnumerable <IMessageBase> > GetReply(ChainEventArgs chat)
 {
     if (chat.Message.StartsWith("/解绑"))
     {
         Logger.Instance.AddLog(LogType.Debug, "接受到改名指令");
         var    sendMember = chat.Sender;
         string newname;
         var    qq = chat.MessageChain.Where(x => x is AtMessage);
         long   tag;
         if (qq.Count() < 1)
         {
             tag = chat.FromQQ;
         }
         else
         {
             tag = (qq.First() as AtMessage).Target;
         }
         if (chat.Message.Contains(BaseData.Instance.config["部落冲突"][chat.FromGroup.ToString()]))
         {
             return(new IMessageBase[] { new AtMessage(chat.FromQQ), new PlainMessage("你当我傻?拿部落标签给我查玩家?草你马的") });
         }
         if (tag == chat.FromQQ)
         {
             if (chat.Message.Contains('#'))
             {
                 newname = chat.Message.Split(' ').Where(x => x.Contains("#")).Last().Trim().ToUpper();
                 if (Member.ClanData.Any(x => x.ClanID == newname))
                 {
                     var selected = Member.ClanData.Where(x => x.ClanID == newname).FirstOrDefault();
                     if (selected == null)
                     {
                         return(new IMessageBase[] { new PlainMessage("找不到相关绑定,无法解绑!") });
                     }
                     Member.ClanData.Remove(selected);
                 }
                 else
                 {
                     return(new IMessageBase[] { new PlainMessage("找不到相关绑定,无法解绑!") });
                 }
                 ICocCorePlayers players = BaseData.Instance.container.Resolve <ICocCorePlayers>();
                 var             player  = players.GetPlayer(newname);
                 if (!string.IsNullOrEmpty(player.Reason))
                 {
                     return(new IMessageBase[] { new PlainMessage("找不到玩家资料或者玩家标签错误: " + player.Reason) });
                 }
                 if (Member.ClanData.Count == 1)
                 {
                     newname = BaseData.Instance.THLevels[player.TownHallLevel] + "本-" + player.Name;
                 }
                 else
                 {
                     List <string> names = new List <string>();
                     foreach (var clanData in Member.ClanData)
                     {
                         var name = players.GetPlayer(clanData.ClanID).Name;
                         if (names.Contains(name[Math.Max(0, 3)..]) && name.StartsWithChinese())
Exemplo n.º 2
0
 public override async Task <IEnumerable <IMessageBase> > GetReply(ChainEventArgs chat)
 {
     if (chat.Message.StartsWith("/绑定") && !chat.Message.Contains("群") && !chat.Message.Contains("查看"))
     {
         Logger.Instance.AddLog(LogType.Debug, "接受到改名指令");
         var    sendMember = chat.Sender;
         string newname;
         var    at  = chat.MessageChain.Where(x => x is AtMessage);
         long   tag = 0;
         if (at.Count() > 0)
         {
             tag = (at.First() as AtMessage).Target;
         }
         else
         {
             tag = chat.Sender.Id;
         }
         Logger.Instance.AddLog(LogType.Debug, "检测到艾特为" + tag);
         if (chat.Message.Contains(BaseData.Instance.config["部落冲突"][chat.FromGroup.ToString()]))
         {
             return(new IMessageBase[] { new AtMessage(chat.FromQQ), new PlainMessage("你当我傻?拿部落标签给我查玩家?草你马的") });
         }
         if (tag == chat.FromQQ)
         {
             if (chat.Message.Contains('#') && chat.Message.Where(x => x == '#').Count() == 1)
             {
                 newname = "#" + chat.Message.Split('#').Last().Trim().ToUpper();
                 ICocCorePlayers players = BaseData.Instance.container.Resolve <ICocCorePlayers>();
                 var             player  = players.GetPlayer(newname);
                 if (!string.IsNullOrEmpty(player.Reason))
                 {
                     return(new IMessageBase[] { new PlainMessage("找不到玩家资料或者玩家标签错误: " + player.Reason) });
                 }
                 if (!Member.ClanData.Any(x => x.ClanID == newname))
                 {
                     Member.ClanData.Add(new ClanData(newname));
                 }
                 if (Member.ClanData.Count == 1)
                 {
                     newname = BaseData.Instance.THLevels[player.TownHallLevel] + "本-" + player.Name;
                 }
                 else
                 {
                     List <string> names = new List <string>();
                     foreach (var clanData in Member.ClanData)
                     {
                         var name = players.GetPlayer(clanData.ClanID).Name;
                         if (name.Length < 3)
                         {
                             names.Add(name);
                         }
                         else
                         {
                             if (names.Contains(name[Math.Min(name.Length, 3)..]) && name.StartsWithChinese())
Exemplo n.º 3
0
        public void Get_Player()
        {
            var playerInfo = PlayersCore.GetPlayer("#C9LRG8VR");

            Assert.IsTrue(playerInfo != null);
            Assert.IsTrue(playerInfo.Name == "Kefirek");
        }
Exemplo n.º 4
0
        public static async Task ChangeNewMemberName(string id, ApplyEventArgs e)
        {
            //直接绑定
            GameAPI data = new GameAPI(e.EventArgs.FromGroup, e.EventArgs.FromQQ, e.Session);

            data.Member.ClanData = new List <ClanData>();
            ICocCorePlayers players = Instance.container.Resolve <ICocCorePlayers>();
            var             player  = players.GetPlayer(id);
            var             newname = Instance.THLevels[player.TownHallLevel] + "本-" + player.Name;
            var             cdata   = new ClanData()
            {
                ClanID = id, Name = player.Name
            };

            try
            {
                if (valuePairs(configType.部落冲突)[e.EventArgs.FromGroup.ToString()] == player.Clan.Tag)
                {
                    cdata.InClan         = true;
                    cdata.LastSeenInClan = DateTime.Now;
                }
            }
            catch
            {
                //Ignore if not found clan ID
            }
            data.Member.ClanData.Add(cdata);
            data.Dispose();
            await e.Session.ChangeGroupMemberInfoAsync(e.EventArgs.FromQQ, e.EventArgs.FromGroup, new GroupMemberCardInfo(newname, null));

            await e.Session.SendGroupMessageAsync(e.EventArgs.FromGroup, new AtMessage(e.EventArgs.FromQQ), new PlainMessage("新人看群文件部落规则,违反任何一条都将会被机票!已经自动绑定成功为" + newname));

            await e.Session.SendGroupMessageAsync(e.EventArgs.FromGroup, new PlainMessage(id));
        }
Exemplo n.º 5
0
 public override async Task <IEnumerable <IMessageBase> > GetReply(ChainEventArgs chat)
 {
     if (chat.Message.StartsWith("/多绑定") && chat.Message.Where(x => x == '#').Count() > 1)
     {
         Logger.Instance.AddLog(LogType.Info, "接受到改名指令");
         var           sendMember = chat.Sender;
         var           ats        = chat.MessageChain.Where(x => x is AtMessage);
         long          tag;
         List <string> ids = new List <string>();
         if (ats.Count() < 1)
         {
             tag = chat.FromQQ;
         }
         else
         {
             tag = (ats.First() as AtMessage).Target;
         }
         if (chat.Message.Contains(BaseData.Instance.config["部落冲突"][chat.FromGroup.ToString()]))
         {
             return(new IMessageBase[] { new AtMessage(chat.FromQQ), new PlainMessage("你当我傻?拿部落标签给我查玩家?草你马的") });
         }
         ICocCorePlayers players = BaseData.Instance.container.Resolve <ICocCorePlayers>();
         if (tag == chat.FromQQ)
         {
             ids.AddRange(chat.Message.Split(' ').Where(x => x.Contains("#")));
             foreach (var id in ids)
             {
                 if (!Member.ClanData.Any(x => x.ClanID == id.Trim().ToUpper()))
                 {
                     Member.ClanData.Add(new ClanData(id.Trim().ToUpper()));
                 }
             }
             string        newname = string.Empty;
             List <string> names   = new List <string>();
             foreach (var id in ids)
             {
                 var player = players.GetPlayer(id.Trim());
                 if (player == null)
                 {
                     var remove = Member.ClanData.First(x => x.ClanID == id.Trim().ToUpper());
                     Member.ClanData.Remove(remove);
                 }
                 if (!string.IsNullOrEmpty(player.Reason))
                 {
                     var remove = Member.ClanData.First(x => x.ClanID == id.Trim().ToUpper());
                     Member.ClanData.Remove(remove);
                 }
                 var name = player.Name;
                 if (names.Contains(name[Math.Max(0, 3)..]) && name.StartsWithChinese())
Exemplo n.º 6
0
        public void GetLootRecords()
        {
            SqlConnection con;                      // connection variables
            SqlCommand    com;
            DateTime      localDate = DateTime.Now; // date now for loot logging date

            try                                     // connect to clash API
            {
                Console.Write("Connecting to Clash API...");
                // set clash api connection token
                string          token       = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiIsImtpZCI6IjI4YTMxOGY3LTAwMDAtYTFlYi03ZmExLTJjNzQzM2M2Y2NhNSJ9.eyJpc3MiOiJzdXBlcmNlbGwiLCJhdWQiOiJzdXBlcmNlbGw6Z2FtZWFwaSIsImp0aSI6ImFlNjY2YzJmLWUyNGQtNGUwZS1hNzU5LTcyZjU4NjRjODY5NSIsImlhdCI6MTUzMDMxMTE3Niwic3ViIjoiZGV2ZWxvcGVyLzA5MGJlMzBlLWFhNjEtN2Y0YS1iMjY1LTk3Mjg1NmEzZDVhOSIsInNjb3BlcyI6WyJjbGFzaCJdLCJsaW1pdHMiOlt7InRpZXIiOiJkZXZlbG9wZXIvc2lsdmVyIiwidHlwZSI6InRocm90dGxpbmcifSx7ImNpZHJzIjpbIjE4LjE5MS4xMjcuODgiLCI3NS4xMzQuOTYuNDciXSwidHlwZSI6ImNsaWVudCJ9XX0.3-S8KOl2DjyO9dhPq4aNjfpyc3Mfei6a_YevQXV0btVU_-d6bJO1pBfuM-7LEtYN5ypXrjAyY5nDjtrHdbJBuQ";
                Funq.Container  container   = CocCore.Instance(token).Container;     // build new container with api token
                ICocCorePlayers playersCore = container.Resolve <ICocCorePlayers>(); // CoCNET interface config to players core
                Console.WriteLine(" Connection Established!");

                try  // fetch loot data
                {
                    Console.Write("Fetching loot data...");
                    var player = playersCore.GetPlayer("#98QGLCJCR");                               //get JSON data for player tag
                    totalGold   = player.Achievements.Find(x => x.Name == "Gold Grab").Value;       // fetch gold grab achievement
                    totalElixer = player.Achievements.Find(x => x.Name == "Elixir Escapade").Value; // fetch elixer escapade achievement
                    totalDark   = player.Achievements.Find(x => x.Name == "Heroic Heist").Value;    // fetch elixer escapade achievement
                    trophies    = player.Trophies;                                                  // fetch player trophies
                    Console.WriteLine(" Loot data fetched!");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine("Failed to fetch data");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Failed to connect to API");
            }


            Console.WriteLine();
            Console.WriteLine("Fetched Loot Data to be logged - " + localDate.ToString());
            Console.WriteLine("Total gold value: " + totalGold.ToString());
            Console.WriteLine("Total elixer value: " + totalElixer.ToString());
            Console.WriteLine("Total dark value: " + totalDark.ToString());
            Console.WriteLine("Total trophies value: " + trophies.ToString());
            Console.WriteLine();

            try
            {
                using (con = new SqlConnection(Properties.Settings.Default.newLootConStr)) // new sql connection using the db connection string
                {
                    Console.Write("Establishing db connection...");
                    con.Open();     // open db for use
                    Console.WriteLine(" Connected to db!");

                    Console.Write("Creating sql command...");
                    // build sql insert command with loot values
                    using (com = new SqlCommand("INSERT INTO LootRecords(dateNow, gold, elixer, dark, trophies) VALUES(" +
                                                "@dateNow, @gold, @elixer, @dark, @trophies)", con))
                    {
                        com.Parameters.AddWithValue("dateNow", localDate);  // add values to sql command
                        com.Parameters.AddWithValue("gold", totalGold);
                        com.Parameters.AddWithValue("elixer", totalElixer);
                        com.Parameters.AddWithValue("dark", totalDark);
                        com.Parameters.AddWithValue("trophies", trophies);
                        Console.WriteLine("Values added to sql command!");
                        try
                        {
                            Console.Write("Inserting data into db...");
                            com.ExecuteNonQuery();  // execute INSERT command
                            Console.WriteLine(" Loot data successfully inserted to db!");
                            con.Close();
                        }
                        catch (SqlException e)
                        {
                            Console.WriteLine(e.Message);
                            Console.WriteLine("Failed to insert data to db");
                        }
                    }
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Failed to connect to db");
            }

            Console.WriteLine();
            Console.WriteLine("Operation Complete");
        }
Exemplo n.º 7
0
 public override async Task <IEnumerable <IMessageBase> > GetReply(ChainEventArgs chat)
 {
     if (chat.Message.ToLower().StartsWith("/玩家资料"))
     {
         try
         {
             var cocid = chat.Message.Replace("/玩家资料", "").Trim();
             if (!BaseData.CheckIP())
             {
                 TokenApi.GetNewToken();
             }
             if (cocid == BaseData.Instance.config["部落冲突"][chat.FromGroup.ToString()])
             {
                 return(new IMessageBase[] { new AtMessage(chat.FromQQ), new PlainMessage("你当我傻?拿部落标签给我查玩家?草你马的") });
             }
             ICocCorePlayers players = BaseData.Instance.container.Resolve <ICocCorePlayers>();
             var             player  = players.GetPlayer(cocid);
             if (player != null)
             {
                 StringBuilder sb = new StringBuilder();
                 sb.AppendLine("大本营等级:" + player.TownHallLevel + ",名字:" + player.Name);
                 sb.AppendLine("进攻次数: " + player.AttackWins + ",防御次数: " + player.DefenseWins + ",战星: " + player.WarStars);
                 sb.AppendLine("==================================");
                 sb.AppendLine("兵力:");
                 foreach (var troop in player.Troops)
                 {
                     try
                     {
                         sb.AppendLine("* " + BaseData.Instance.config["兵种翻译"][troop.Name.Replace(" ", "_")] + " - " + troop.Level + "级");
                     }
                     catch
                     {
                         sb.AppendLine("* " + troop.Name + " - " + troop.Level + "级");
                     }
                 }
                 sb.AppendLine("==================================");
                 sb.AppendLine("药水:");
                 foreach (var spell in player.Spells)
                 {
                     try
                     {
                         sb.AppendLine("* " + BaseData.Instance.config["兵种翻译"][spell.Name.Replace(" ", "_")] + " - " + spell.Level + "级");
                     }
                     catch
                     {
                         sb.AppendLine("* " + spell.Name + " - " + spell.Level + "级");
                     }
                 }
                 sb.AppendLine("==================================");
                 sb.AppendLine("英雄:");
                 foreach (var hero in player.Heroes)
                 {
                     try
                     {
                         sb.AppendLine("* " + BaseData.Instance.config["兵种翻译"][hero.Name.Replace(" ", "_")] + " - " + hero.Level + "级");
                     }
                     catch
                     {
                         sb.AppendLine("* " + hero.Name + " - " + hero.Level + "级");
                     }
                 }
                 return(new IMessageBase[] { BaseData.TextToImg(sb.ToString(), chat.Session) });
             }
             else
             {
                 return(new IMessageBase[] { new PlainMessage("未知的部落冲突ID,无法搜索该玩家资料!") });
             }
         }
         catch (Exception ex)
         {
             return(new IMessageBase[] { new PlainMessage("请确保发送/PlayerAPI时是/PlayerAPI 玩家标签!错误资料:" + ex.Message) });
         }
     }
     return(await base.GetReply(chat));
 }
Exemplo n.º 8
0
        public static async Task <bool> NewMember(string id, ApplyEventArgs e)
        {
            if (Directory.GetFiles("com.coc.groupadmin\\Blacklist").Any(x => x.EndsWith(e.EventArgs.FromQQ.ToString())))
            {
                //在黑名单内,直接拒绝
                return(false);
            }
            Logger.Instance.AddLog(LogType.Info, "接受到新人申请");
            ICocCorePlayers players    = BaseData.Instance.container.Resolve <ICocCorePlayers>();
            List <int>      levels     = new List <int>();
            int             heroLvNeed = 0;
            Player          player     = players.GetPlayer(id);

            if (player != null)
            {
                StringBuilder sb = new StringBuilder();
                bool          troopFull = true, spellFull = true, heroFull = true;
                var           troopsLV = BaseData.GetTownhallTroopsLV(player.TownHallLevel - 1);
                sb.AppendLine("大本营等级:" + player.TownHallLevel + ",名字:" + player.Name);
                sb.AppendLine("兵力:");
                foreach (var troop in player.Troops)
                {
                    if (troop.Village == "home")
                    {
                        if (!troopsLV.Keys.Contains(troop.Name.Replace(" ", "_")))
                        {
                            for (int x = 1; x < BaseData.Instance.THLevels.Length; x++)
                            {
                                BaseData.Instance.thConfig[x.ToString() + "本"].AddKey(troop.Name.Replace(" ", "_"), troop.MaxLevel.ToString());
                            }
                            BaseData.Instance.config["兵种翻译"].AddKey(troop.Name.Replace(" ", "_"), troop.Name);
                            FileIniDataParser parser = new FileIniDataParser();
                            parser.WriteFile("Townhall.ini", BaseData.Instance.thConfig);
                            parser.WriteFile("config.ini", BaseData.Instance.config);
                            sb.AppendLine(troop.Name + " Townhall.ini 设置有错误,已自动生成");
                        }
                        else
                        {
                            if (troopsLV[troop.Name.Replace(" ", "_")] == 99)
                            {
                                BaseData.Instance.thConfig[player.TownHallLevel.ToString() + "本"][troop.Name.Replace(" ", "_")] = troop.MaxLevel.ToString();
                                FileIniDataParser parser = new FileIniDataParser();
                                parser.WriteFile("Townhall.ini", BaseData.Instance.thConfig);
                                troopsLV = BaseData.GetTownhallTroopsLV(player.TownHallLevel);
                            }
                            if (troopsLV[troop.Name.Replace(" ", "_")] > troop.Level)
                            {
                                troopFull = false;
                                try
                                {
                                    sb.AppendLine(BaseData.Instance.config["兵种翻译"][troop.Name.Replace(" ", "_")] + " 还缺" + (troopsLV[troop.Name.Replace(" ", "_")] - troop.Level) + "级");
                                    levels.Add(troopsLV[troop.Name.Replace(" ", "_")] - troop.Level);
                                }
                                catch
                                {
                                    sb.AppendLine(troop.Name + " 还缺" + (troopsLV[troop.Name.Replace(" ", "_")] - troop.Level) + "级");
                                }
                            }
                        }
                    }
                }
                if (troopFull)
                {
                    sb.AppendLine("已满级");
                }
                sb.AppendLine("药水:");
                foreach (var spell in player.Spells)
                {
                    if (!troopsLV.Keys.Contains(spell.Name.Replace(" ", "_")))
                    {
                        for (int x = 1; x < BaseData.Instance.THLevels.Length; x++)
                        {
                            BaseData.Instance.thConfig[x.ToString() + "本"].AddKey(spell.Name.Replace(" ", "_"), spell.MaxLevel.ToString());
                        }
                        BaseData.Instance.config["兵种翻译"].AddKey(spell.Name.Replace(" ", "_"), spell.Name);
                        FileIniDataParser parser = new FileIniDataParser();
                        parser.WriteFile("Townhall.ini", BaseData.Instance.thConfig);
                        parser.WriteFile("config.ini", BaseData.Instance.config);
                        sb.AppendLine(spell.Name + " Townhall.ini 设置有错误,已自动生成");
                    }
                    else
                    {
                        if (troopsLV[spell.Name.Replace(" ", "_")] == 99)
                        {
                            BaseData.Instance.thConfig[player.TownHallLevel + "本"][spell.Name.Replace(" ", "_")] = spell.MaxLevel.ToString();
                            FileIniDataParser parser = new FileIniDataParser();
                            parser.WriteFile("Townhall.ini", BaseData.Instance.thConfig);
                            troopsLV = BaseData.GetTownhallTroopsLV(player.TownHallLevel);
                        }
                        if (troopsLV[spell.Name.Replace(" ", "_")] > spell.Level)
                        {
                            spellFull = false;
                            try
                            {
                                sb.AppendLine(BaseData.Instance.config["兵种翻译"][spell.Name.Replace(" ", "_")] + " 还缺" + (troopsLV[spell.Name.Replace(" ", "_")] - spell.Level) + "级");
                                levels.Add(troopsLV[spell.Name.Replace(" ", "_")] - spell.Level);
                            }
                            catch
                            {
                                sb.AppendLine(spell.Name + " 还缺" + (troopsLV[spell.Name.Replace(" ", "_")] - spell.Level) + "级");
                            }
                        }
                    }
                }
                if (spellFull)
                {
                    sb.AppendLine("已满级");
                }
                if (player.Heroes.Count > 0)
                {
                    sb.AppendLine("英雄:");
                    foreach (var hero in player.Heroes)
                    {
                        if (hero.Village == "home")
                        {
                            if (!troopsLV.Keys.Contains(hero.Name.Replace(" ", "_")))
                            {
                                for (int x = 1; x < BaseData.Instance.THLevels.Length; x++)
                                {
                                    BaseData.Instance.thConfig[x.ToString() + "本"].AddKey(hero.Name.Replace(" ", "_"), hero.MaxLevel.ToString());
                                }
                                BaseData.Instance.config["兵种翻译"].AddKey(hero.Name.Replace(" ", "_"), hero.Name);
                                FileIniDataParser parser = new FileIniDataParser();
                                parser.WriteFile("Townhall.ini", BaseData.Instance.thConfig);
                                parser.WriteFile("config.ini", BaseData.Instance.config);
                                sb.AppendLine(hero.Name + " Townhall.ini 设置有错误,已自动生成");
                            }
                            else
                            {
                                if (troopsLV[hero.Name.Replace(" ", "_")] == 99)
                                {
                                    BaseData.Instance.thConfig[player.TownHallLevel + "本"][hero.Name.Replace(" ", "_")] = hero.MaxLevel.ToString();
                                    FileIniDataParser parser = new FileIniDataParser();
                                    parser.WriteFile("Townhall.ini", BaseData.Instance.thConfig);
                                    troopsLV = BaseData.GetTownhallTroopsLV(player.TownHallLevel);
                                }
                                if (troopsLV[hero.Name.Replace(" ", "_")] > hero.Level)
                                {
                                    heroFull    = false;
                                    heroLvNeed += (troopsLV[hero.Name.Replace(" ", "_")] - hero.Level);
                                    try
                                    {
                                        sb.AppendLine(BaseData.Instance.config["兵种翻译"][hero.Name.Replace(" ", "_")] + " 还缺" + (troopsLV[hero.Name.Replace(" ", "_")] - hero.Level) + "级");
                                    }
                                    catch
                                    {
                                        sb.AppendLine(hero.Name + " 还缺" + (troopsLV[hero.Name.Replace(" ", "_")] - hero.Level) + "级");
                                    }
                                }
                            }
                        }
                    }
                    if (heroFull)
                    {
                        sb.AppendLine("已满级");
                    }
                }
                bool allow;
                if (levels.Count(x => x >= 1) > 6 || heroLvNeed >= 30)
                {
                    sb.AppendLine("不批准!科技不足!");
                    allow = false;
                }
                else
                {
                    sb.AppendLine("批准!科技已足够!");
                    allow = true;
                }
                if (player.WarStars >= 500)
                {
                    sb.AppendLine("战星已超过500,强制批准!");
                    allow = true;
                }
                await e.Session.SendGroupMessageAsync(e.EventArgs.FromGroup, new PlainMessage("新人距离上一本的审核资料如下:\n" + sb.ToString()));

                return(allow);
            }
            else
            {
                //申请是来骂人的
                foreach (var keyvalue in valuePairs(configType.禁止词句))
                {
                    if (id == keyvalue.Key)
                    {
                        if (int.TryParse(keyvalue.Value, out int ticks))
                        {
                            if (ticks > 0)
                            {
                                return(false);
                            }
                        }
                    }
                }
                return(true);
            }
        }
Exemplo n.º 9
0
        public void CheckClanWar()
        {
            Logger.Instance.AddLog(LogType.Info, "部落战检测系统启动");
            DateTime lastBackup = DateTime.MinValue;

            computer.Open();
            computer.CPUEnabled = true;
            computer.RAMEnabled = true;
            do
            {
                try
                {
                    foreach (var hardware in computer.Hardware)
                    {
                        switch (hardware.HardwareType)
                        {
                        case HardwareType.CPU:
                            hardware.Update();
                            var value = GetLoad(hardware);
                            if (value != null)
                            {
                                BaseData.Instance.cpuUsage = value.Value;
                            }
                            BaseData.Instance.cpuName = hardware.Name;
                            break;

                        case HardwareType.RAM:
                            hardware.Update();
                            value = GetLoad(hardware);
                            if (value != null)
                            {
                                BaseData.Instance.ramUsage = value.Value;
                            }
                            break;
                        }
                    }
                    Thread.Sleep(1000);
                    if ((DateTime.Now.Minute == 0 || DateTime.Now.Minute == 30) && DateTime.Now.Second == 0)
                    {
                        ICocCoreClans   clan    = BaseData.Instance.container.Resolve <ICocCoreClans>();
                        ICocCorePlayers players = BaseData.Instance.container.Resolve <ICocCorePlayers>();
                        try
                        {
                            foreach (var clanID in BaseData.Instance.config["部落冲突"])
                            {
                                if (clanID.KeyName.All(char.IsDigit))
                                {
                                    if (lastBackup.Date != DateTime.Now.Date)
                                    {
                                        try
                                        {
                                            Logger.Instance.AddLog(LogType.Info, "正在备份资料...");
                                            //BackUp our game Data
                                            if (!Directory.Exists("com.coc.groupadmin\\BackUp\\" + clanID.KeyName))
                                            {
                                                Directory.CreateDirectory("com.coc.groupadmin\\BackUp\\" + clanID.KeyName);
                                            }
                                            foreach (var file in Directory.GetFiles("com.coc.groupadmin\\" + clanID.KeyName))
                                            {
                                                if (File.Exists(file.Replace("com.coc.groupadmin\\", "com.coc.groupadmin\\BackUp\\")))
                                                {
                                                    File.Delete(file.Replace("com.coc.groupadmin\\", "com.coc.groupadmin\\BackUp\\"));
                                                }
                                                File.Copy(file, file.Replace("com.coc.groupadmin\\", "com.coc.groupadmin\\BackUp\\"));
                                            }
                                            lastBackup = DateTime.Now;
                                        }
                                        catch
                                        {
                                        }
                                    }
                                    try
                                    {
                                        if (long.TryParse(clanID.KeyName, out long value))
                                        {
                                            if (DateTime.Now.Month == 1 && DateTime.Now.Day == 1 && DateTime.Now.Hour == 0 && DateTime.Now.Minute == 0 && DateTime.Now.Second == 0)
                                            {
                                                //新年快乐
                                                Session.SendGroupMessage(value, new AtAllMessage(), new PlainMessage("我tm祝各位tm的" + DateTime.Now.Year + "新年快乐"));
                                            }
                                            if (!War.ContainsKey(value) || War[value] == null)
                                            {
                                                var clanData = clan.GetCurrentWar(clanID.Value);
                                                if (clanData.State.ToLower() == "preparation")
                                                {
                                                    //New thread
                                                    Thread t = new Thread(() => {
                                                        Session.SendGroupMessage(Convert.ToInt64(clanID.KeyName), new AtAllMessage(), new PlainMessage("部落战已进入准备日!"));
                                                        var wait = clanData.EndTime.ToLocalTime() - DateTime.Now - new TimeSpan(23, 0, 0);
                                                        Logger.Instance.AddLog(LogType.Debug, "部落战当前准备日,还需要等待" + wait.Days + "天" + wait.Hours + "小时" + wait.Minutes + "分钟" + wait.Seconds + "秒");
                                                        if (wait.TotalSeconds > 0)
                                                        {
                                                            Thread.Sleep(wait);
                                                            Session.SendGroupMessage(Convert.ToInt64(clanID.KeyName), new AtAllMessage(), new PlainMessage("部落战已开始!"));
                                                        }
                                                        return;
                                                    });
                                                    t.IsBackground = true;
                                                    if (War.ContainsKey(value))
                                                    {
                                                        War[value] = t;
                                                    }
                                                    else
                                                    {
                                                        War.Add(value, t);
                                                    }
                                                    t.Start();
                                                }
                                                else if (clanData.State.ToLower() == "inwar")
                                                {
                                                    Thread t = new Thread(() => {
                                                        var wait = clanData.EndTime.ToLocalTime() - DateTime.Now;
                                                        Logger.Instance.AddLog(LogType.Debug, "部落战当前已开始,还需要等待" + wait.Days + "天" + wait.Hours + "小时" + wait.Minutes + "分钟" + wait.Seconds + "秒");
                                                        if (wait.TotalSeconds > 0)
                                                        {
                                                            Thread.Sleep(wait);
                                                            Session.SendGroupMessage(Convert.ToInt64(clanID.KeyName), new AtAllMessage(), new PlainMessage("部落战已结束!"));
                                                        }
                                                        return;
                                                    });
                                                    t.IsBackground = true;
                                                    if (War.ContainsKey(value))
                                                    {
                                                        War[value] = t;
                                                    }
                                                    else
                                                    {
                                                        War.Add(value, t);
                                                    }
                                                    t.Start();
                                                }
                                            }
                                            else if (War[value].ThreadState == ThreadState.Stopped || War[value].ThreadState == ThreadState.Aborted || War[value].ThreadState == ThreadState.Suspended)
                                            {
                                                War[value] = null;
                                                GC.Collect();
                                                var clanData = clan.GetCurrentWar(clanID.Value);
                                                if (clanData.State.ToLower() == "preparation")
                                                {
                                                    //New thread
                                                    Thread t = new Thread(() => {
                                                        Session.SendGroupMessage(Convert.ToInt64(clanID.KeyName), new AtAllMessage(), new PlainMessage("部落战已进入准备日!"));
                                                        //Weird error which always more 12 hours
                                                        var wait = clanData.EndTime.ToLocalTime() - DateTime.Now - new TimeSpan(12, 0, 0);
                                                        Logger.Instance.AddLog(LogType.Debug, "部落战当前准备日,还需要等待" + wait.Days + "天" + wait.Hours + "小时" + wait.Minutes + "分钟" + wait.Seconds + "秒");
                                                        if (wait.TotalSeconds > 0)
                                                        {
                                                            Thread.Sleep(wait);
                                                            Session.SendGroupMessage(Convert.ToInt64(clanID.KeyName), new AtAllMessage(), new PlainMessage("部落战已开始!"));
                                                        }
                                                        return;
                                                    });
                                                    t.IsBackground = true;
                                                    War[value]     = t;
                                                    t.Start();
                                                }
                                                else if (clanData.State.ToLower() == "inwar")
                                                {
                                                    Thread t = new Thread(() => {
                                                        var wait = clanData.EndTime.ToLocalTime() - DateTime.Now;
                                                        Logger.Instance.AddLog(LogType.Debug, "部落战当前已开始,还需要等待" + wait.Days + "天" + wait.Hours + "小时" + wait.Minutes + "分钟" + wait.Seconds + "秒");
                                                        if (wait.TotalSeconds > 0)
                                                        {
                                                            Thread.Sleep(wait);
                                                            Session.SendGroupMessage(Convert.ToInt64(clanID.KeyName), new AtAllMessage(), new PlainMessage("部落战已结束!"));
                                                        }
                                                        return;
                                                    });
                                                    t.IsBackground = true;
                                                    War[value]     = t;
                                                    t.Start();
                                                }
                                            }
                                            var Members      = clan.GetClansMembers(clanID.Value);
                                            var GroupMembers = Session.GetGroupMemberListAsync(value).Result;
                                            foreach (var member in GroupMembers)
                                            {
                                                using var api = new GameAPI(value, member.Id, Session);
                                                foreach (var cd in api.Member.ClanData)
                                                {
                                                    var m = Members.Where(x => x.Tag == cd.ClanID || x.Tag.Replace("0", "O") == cd.ClanID || x.Tag.Replace("1", "I") == cd.ClanID || x.Tag.Replace("0", "O").Replace("1", "I") == cd.ClanID).FirstOrDefault();
                                                    if (m != null)
                                                    {
                                                        cd.InClan         = true;
                                                        cd.Name           = m.Name;
                                                        cd.LastSeenInClan = DateTime.Now;
                                                    }
                                                    else
                                                    {
                                                        cd.InClan = false;
                                                    }
                                                }
                                                if (api.Member.ClanData.Count == 1 && DateTime.Now.Hour == 0)
                                                {
                                                    Player player = players.GetPlayer(api.Member.ClanData.First().ClanID);
                                                    if (api.Member.Member.Card != BaseData.Instance.THLevels[player.TownHallLevel] + "本-" + player.Name)
                                                    {
                                                        Session.ChangeGroupMemberInfo(api.Member.Member.QQId, value, new GroupMemberCardInfo(BaseData.Instance.THLevels[player.TownHallLevel] + "本-" + player.Name, null));
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            Logger.Instance.AddLog(LogType.Error, "群号无法加载,资料出现错误");
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Logger.Instance.AddLog(LogType.Error, clanID.KeyName + ": " + ex.Message);
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.AddLog(LogType.Error, "部落战检测出现错误: " + ex.ToString());
                }
            }while (true);
        }
Exemplo n.º 10
0
        private static IMessageBase CheckMember(string id, MiraiHttpSession Session)
        {
            Logger.Instance.AddLog(LogType.Debug, "判断的部落ID为" + id);
            ICocCorePlayers players = BaseData.Instance.container.Resolve <ICocCorePlayers>();
            Player          player  = players.GetPlayer(id);

            if (player != null && string.IsNullOrEmpty(player.Reason))
            {
                StringBuilder sb = new StringBuilder();
                bool          troopFull = true, spellFull = true, heroFull = true;
                int           heroLvNeed = 0;
                var           troopsLV   = BaseData.GetTownhallTroopsLV(player.TownHallLevel - 1);
                sb.AppendLine("大本营等级:" + player.TownHallLevel + ",名字:" + player.Name);
                sb.AppendLine("兵力:");
                foreach (var troop in player.Troops)
                {
                    if (troop.Village != "home")
                    {
                        continue;
                    }
                    if (!troopsLV.Keys.Contains(troop.Name.Replace(" ", "_")))
                    {
                        for (int x = 1; x < BaseData.Instance.THLevels.Length; x++)
                        {
                            BaseData.Instance.thConfig[x.ToString() + "本"].AddKey(troop.Name.Replace(" ", "_"), troop.MaxLevel.ToString());
                        }
                        BaseData.Instance.config["兵种翻译"].AddKey(troop.Name.Replace(" ", "_"), troop.Name);
                        FileIniDataParser parser = new FileIniDataParser();
                        parser.WriteFile("Townhall.ini", BaseData.Instance.thConfig);
                        parser.WriteFile("config.ini", BaseData.Instance.config);
                        sb.AppendLine("* " + troop.Name + " 还缺" + (troop.MaxLevel - troop.Level) + "级 (Townhall.ini设置丢失,自动生成)");
                    }
                    else
                    {
                        if (troopsLV[troop.Name.Replace(" ", "_")] == 99)
                        {
                            BaseData.Instance.thConfig[player.TownHallLevel.ToString() + "本"][troop.Name.Replace(" ", "_")] = troop.MaxLevel.ToString();
                            FileIniDataParser parser = new FileIniDataParser();
                            parser.WriteFile("Townhall.ini", BaseData.Instance.thConfig);
                        }
                        if (troopsLV[troop.Name.Replace(" ", "_")] > troop.Level)
                        {
                            troopFull = false;
                            try
                            {
                                sb.AppendLine("* " + BaseData.Instance.config["兵种翻译"][troop.Name.Replace(" ", "_")] + " 还缺" + (troopsLV[troop.Name.Replace(" ", "_")] - troop.Level) + "级");
                            }
                            catch
                            {
                                sb.AppendLine("* " + troop.Name + " 还缺" + (troopsLV[troop.Name.Replace(" ", "_")] - troop.Level) + "级");
                            }
                        }
                    }
                }
                if (troopFull)
                {
                    sb.AppendLine("已满级");
                }
                sb.AppendLine("==================================");
                sb.AppendLine("药水:");
                foreach (var spell in player.Spells)
                {
                    if (!troopsLV.Keys.Contains(spell.Name.Replace(" ", "_")))
                    {
                        for (int x = 1; x < BaseData.Instance.THLevels.Length; x++)
                        {
                            BaseData.Instance.thConfig[x.ToString() + "本"].AddKey(spell.Name.Replace(" ", "_"), spell.MaxLevel.ToString());
                        }
                        BaseData.Instance.config["兵种翻译"].AddKey(spell.Name.Replace(" ", "_"), spell.Name);
                        FileIniDataParser parser = new FileIniDataParser();
                        parser.WriteFile("Townhall.ini", BaseData.Instance.thConfig);
                        parser.WriteFile("config.ini", BaseData.Instance.config);
                        sb.AppendLine("* " + spell.Name + " 还缺" + (spell.MaxLevel - spell.Level) + "级 (Townhall.ini设置丢失,自动生成)");
                    }
                    else
                    {
                        if (troopsLV[spell.Name.Replace(" ", "_")] == 99)
                        {
                            BaseData.Instance.thConfig[player.TownHallLevel + "本"][spell.Name.Replace(" ", "_")] = spell.MaxLevel.ToString();
                            FileIniDataParser parser = new FileIniDataParser();
                            parser.WriteFile("Townhall.ini", BaseData.Instance.thConfig);
                        }
                        if (troopsLV[spell.Name.Replace(" ", "_")] > spell.Level)
                        {
                            spellFull = false;
                            try
                            {
                                sb.AppendLine("* " + BaseData.Instance.config["兵种翻译"][spell.Name.Replace(" ", "_")] + " 还缺" + (troopsLV[spell.Name.Replace(" ", "_")] - spell.Level) + "级");
                            }
                            catch
                            {
                                sb.AppendLine("* " + spell.Name + " 还缺" + (troopsLV[spell.Name.Replace(" ", "_")] - spell.Level) + "级");
                            }
                        }
                    }
                }
                if (spellFull)
                {
                    sb.AppendLine("已满级");
                }
                if (player.Heroes.Count > 0)
                {
                    sb.AppendLine("==================================");
                    sb.AppendLine("英雄:");
                    foreach (var hero in player.Heroes)
                    {
                        if (hero.Village != "home")
                        {
                            continue;
                        }
                        if (!troopsLV.Keys.Contains(hero.Name.Replace(" ", "_")))
                        {
                            for (int x = 1; x < BaseData.Instance.THLevels.Length; x++)
                            {
                                BaseData.Instance.thConfig[x.ToString() + "本"].AddKey(hero.Name.Replace(" ", "_"), hero.MaxLevel.ToString());
                            }
                            BaseData.Instance.config["兵种翻译"].AddKey(hero.Name.Replace(" ", "_"), hero.Name);
                            FileIniDataParser parser = new FileIniDataParser();
                            parser.WriteFile("Townhall.ini", BaseData.Instance.thConfig);
                            parser.WriteFile("config.ini", BaseData.Instance.config);
                            sb.AppendLine("* " + hero.Name + " 还缺" + (hero.MaxLevel - hero.Level) + "级 (Townhall.ini设置丢失,自动生成)");
                        }
                        else
                        {
                            if (troopsLV[hero.Name.Replace(" ", "_")] == 99)
                            {
                                BaseData.Instance.thConfig[player.TownHallLevel + "本"][hero.Name.Replace(" ", "_")] = hero.MaxLevel.ToString();
                                FileIniDataParser parser = new FileIniDataParser();
                                parser.WriteFile("Townhall.ini", BaseData.Instance.thConfig);
                            }
                            if (troopsLV[hero.Name.Replace(" ", "_")] > hero.Level)
                            {
                                heroLvNeed += (troopsLV[hero.Name.Replace(" ", "_")] - hero.Level);
                                heroFull    = false;
                                try
                                {
                                    sb.AppendLine("* " + BaseData.Instance.config["兵种翻译"][hero.Name.Replace(" ", "_")] + " 还缺" + (troopsLV[hero.Name.Replace(" ", "_")] - hero.Level) + "级");
                                }
                                catch
                                {
                                    sb.AppendLine("* " + hero.Name + " 还缺" + (troopsLV[hero.Name.Replace(" ", "_")] - hero.Level) + "级");
                                }
                            }
                        }
                    }
                    if (heroFull)
                    {
                        sb.AppendLine("已满级");
                    }
                }
                if (sb.ToString().Split('\n').Length > 13 || heroLvNeed >= 10)
                {
                    sb.AppendLine("==================================");
                    sb.AppendLine("注意:严禁升本!否则将会被机票!");
                }
                if (!Directory.Exists("Buffer"))
                {
                    Directory.CreateDirectory("Buffer");
                }
                return(BaseData.TextToImg(sb.ToString(), Session));
            }
            else
            {
                if (player == null)
                {
                    return(new PlainMessage("未知的部落冲突ID,无法搜索该玩家资料!"));
                }
                else
                {
                    return(new PlainMessage("出现错误,请稍后再试!错误详情:" + player.Reason));
                }
            }
        }