private void btnGetData_Click(object sender, EventArgs e) { string token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiIsImtpZCI6IjI4YTMxOGY3LTAwMDAtYTFlYi03ZmExLTJjNzQzM2M2Y2NhNSJ9.eyJpc3MiOiJzdXBlcmNlbGwiLCJhdWQiOiJzdXBlcmNlbGw6Z2FtZWFwaSIsImp0aSI6IjMwMzc4M2ViLWIyNWYtNDU5MC05M2NmLTFhNmZjMzQ5Yjk1OSIsImlhdCI6MTU5MTMxNTIyMCwic3ViIjoiZGV2ZWxvcGVyLzcyODgzMmI1LTI4NzgtYTJlZi01MTQ0LTUyNTM5N2U3YzI4NiIsInNjb3BlcyI6WyJjbGFzaCJdLCJsaW1pdHMiOlt7InRpZXIiOiJkZXZlbG9wZXIvc2lsdmVyIiwidHlwZSI6InRocm90dGxpbmcifSx7ImNpZHJzIjpbIjk0LjIxLjM0LjEwOSJdLCJ0eXBlIjoiY2xpZW50In1dfQ.OgBZEinxO9LZ51E8mgPZKT_UiWsNt6IvZgr-1wNfZZINkv-vQvtN6vNFaTHXIecCao5RwAh3QHOAWjQS_fhulg"; Funq.Container container = CocCore.Instance(token).Container; ICocCoreClans clansCore = container.Resolve <ICocCoreClans>(); var clan = clansCore.GetClans(txtTag.Text); txtName.Text = clan.Name; txtLocation.Text = clan.Location.Name; txtType.Text = clan.Type; txtClanLevel.Text = clan.ClanLevel.ToString(); txtClanPoints.Text = clan.ClanPoints.ToString(); txtWarWins.Text = clan.WarWins.ToString(); }
public override async Task <IEnumerable <IMessageBase> > GetReply(ChainEventArgs chat) { if (chat.Message == "/部落平均") { ICocCoreClans clan = BaseData.Instance.container.Resolve <ICocCoreClans>(); var clanData = clan.GetClans(BaseData.Instance.config["部落冲突"][chat.FromGroup.ToString()]); if (!string.IsNullOrEmpty(clanData.Reason)) { return(new IMessageBase[] { new PlainMessage("无法获取部落资料!" + clanData.Reason) }); } StringBuilder sb = new StringBuilder(); long donated = 0, donationsReceived = 0; foreach (var member in clanData.MemberList) { donated += member.Donations; donationsReceived += member.DonationsReceived; } sb.AppendLine("部落平均胜率: " + ((double)(((double)clanData.WarWins / ((double)clanData.WarWins + (double)clanData.WarLosses + (double)clanData.WarTies)) * 100)).ToString("0.00") + "%"); sb.AppendLine("部落平均捐兵: " + donated / clanData.MemberList.Count); sb.Append("部落平均收兵: " + donationsReceived / clanData.MemberList.Count); return(new IMessageBase[] { new PlainMessage(sb.ToString()) }); } return(await base.GetReply(chat)); }
public void Get_Clan() { var myClan = ClansCore.GetClans(CLAN_TAG); Assert.IsTrue(myClan.Name == "Pandemia"); }
public void GetMemberList() { SqlConnection con; // connection variables SqlCommand com; DateTime localDate = DateTime.Now; // date now for loot logging date try // connect to clash API { Console.WriteLine(); 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 ICocCoreClans clansCore = container.Resolve <ICocCoreClans>(); // CoCNET interface config to clans Console.WriteLine(" Connection Established!"); try // fetch loot data { Console.WriteLine(); Console.Write("Fetching member details..."); var clan = clansCore.GetClans("#99L9R088"); //get JSON data for clan tag foreach (var obj in clan.MemberList) // loop through each members details { Member member = new Member(); member.Tag = obj.Tag; member.Name = obj.Name; member.ExpLevel = obj.ExpLevel; member.LeagueID = obj.League.Id; member.LeagueName = obj.League.Name; member.LeagueIcon = obj.League.IconUrls["small"]; member.Trophies = obj.Trophies; member.Role = obj.Role; member.ClanRank = obj.ClanRank; member.Donations = obj.Donations; member.DonationsReceived = obj.DonationsReceived; member.LocalDate = localDate; myMemberList.Add(member); } //Console.WriteLine(); Console.WriteLine(" Member details fetched!"); } catch (Exception e) { Console.WriteLine(); 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(); /* * foreach (var member in myMemberList) * { * Console.WriteLine(member.Name); * } */ 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!"); foreach (var member in myMemberList) { //Console.WriteLine(); Console.Write("Creating sql command..."); // build sql insert command with loot values using (com = new SqlCommand("AddMemberDetails", con)) { com.CommandType = CommandType.StoredProcedure; com.Parameters.AddWithValue("@tag", member.Tag); // add values to sql command com.Parameters.AddWithValue("@name", member.Name); // add values to sql command com.Parameters.AddWithValue("@expLevel", member.ExpLevel); // add values to sql command com.Parameters.AddWithValue("@leagueID", member.LeagueID); // add values to sql command com.Parameters.AddWithValue("@leagueName", member.LeagueName); // add values to sql command com.Parameters.AddWithValue("@leagueIcon", member.LeagueIcon); // add values to sql command com.Parameters.AddWithValue("@trophies", member.Trophies); // add values to sql command com.Parameters.AddWithValue("@role", member.Role); // add values to sql command com.Parameters.AddWithValue("@clanRank", member.ClanRank); // add values to sql command com.Parameters.AddWithValue("@donations", member.Donations); // add values to sql command com.Parameters.AddWithValue("@donationsReceived", member.DonationsReceived); // add values to sql command com.Parameters.AddWithValue("@dateNow", member.LocalDate); // add values to sql command Console.WriteLine(" Values added to sql command!"); try { //Console.WriteLine(); Console.Write("Inserting " + member.Name + " member into db..."); com.ExecuteNonQuery(); // execute INSERT command Console.WriteLine(" " + member.Name + " successfully inserted to db!"); } catch (SqlException e) { Console.WriteLine(); Console.WriteLine(e.Message); Console.WriteLine("Failed to insert data to db"); } } } con.Close(); } } catch (SqlException e) { Console.WriteLine(e.Message); Console.WriteLine("Failed to connect to db"); } Console.WriteLine(); Console.WriteLine("Operation Complete"); }
public void GetClanDetails() { 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 ICocCoreClans clansCore = container.Resolve <ICocCoreClans>(); // CoCNET interface config to clans Console.WriteLine(" Connection Established!"); try // fetch loot data { Console.Write("Fetching clan details..."); var clan = clansCore.GetClans("#99L9R088"); //get JSON data for clan tag tag = clan.Tag; name = clan.Name; badgeUrls = clan.BadgeUrls["large"]; clanLevel = clan.ClanLevel; clanPoints = clan.ClanPoints; members = clan.Members; warWinStreak = clan.WarWinStreak; warWins = clan.WarWins; description = clan.Decsription; type = clan.Type; requiredTrophies = clan.RequiredTrophies; warFrequency = clan.WarFrequency; Console.WriteLine("Clan details 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"); } 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("AddClanDetails", con)) { com.CommandType = CommandType.StoredProcedure; com.Parameters.AddWithValue("@tag", tag); // add values to sql command com.Parameters.AddWithValue("@name", name); com.Parameters.AddWithValue("@badgeUrls", badgeUrls); com.Parameters.AddWithValue("@clanLevel", clanLevel); com.Parameters.AddWithValue("@clanPoints", clanPoints); com.Parameters.AddWithValue("@members", members); com.Parameters.AddWithValue("@warWinStreak", warWinStreak); com.Parameters.AddWithValue("@warWins", warWins); com.Parameters.AddWithValue("@description", description); com.Parameters.AddWithValue("@type", type); com.Parameters.AddWithValue("@requiredTrophies", requiredTrophies); com.Parameters.AddWithValue("@warFrequency", warFrequency); com.Parameters.AddWithValue("@dateNow", localDate); 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"); }