public async Task FaceitDetails(CommandContext ctx, [RemainingText, Description("The username of the Faceit account to get details for")] string username) { faceitClient = new FaceitClient(SettingsFile.faceitapikey); PlayerDetails stats = null; int attemptnumber = 1; RetrySearch: stats = await faceitClient.GetPlayerDetailsFromNickname(username); if (faceitClient.GetStatusCode() == HttpStatusCode.ServiceUnavailable) { if (attemptnumber == 6) { await ctx.RespondAsync($"Attempt #5 failed. Retry command later"); return; } await ctx.RespondAsync($"Attempt #{attemptnumber} failed"); await Task.Delay(100); goto RetrySearch; } if (faceitClient.GetStatusCode() != HttpStatusCode.OK) { await ctx.RespondAsync("Player could not be found"); return; } var embed = new DiscordEmbedBuilder { Color = new DiscordColor(0xFF5500), Description = $"Faceit ID: `{stats.PlayerID}`", Title = $"{stats.Nickname}", Timestamp = DateTime.UtcNow, Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail { Url = stats.Avatar }, Url = stats.FaceitURL, }; embed.AddField("Membership Type", stats.MembershipType); embed.AddField("Steam ID", stats.SteamID64); embed.AddField("Country", $":flag_{stats.Country}:"); embed.AddField("CSGO Skill Level", $"{stats.Games.CSGO.SkillLevel}"); await ctx.RespondAsync(embed : embed); }
/// <summary> /// Gets matches from all hubs inside the database. /// </summary> /// <param name="startTime">Start date to get demos from</param> /// <param name="endTime">End time to get demos to</param> /// <returns>Task Complete</returns> private async Task GetMatches(DateTime startTime, DateTime endTime) { var faceit = new FaceitClient(_dataService.RSettings.ProgramSettings.FaceitAPIKey); _gameInfo = new List <FaceItGameInfo>(); //Status for each hub call _statusCodes = new Dictionary <FaceItHub, HttpStatusCode>(); foreach (var hub in DatabaseUtil.GetHubs()) { await _log.LogMessage($"Calling Faceit Endpoint: `{hub.HubName}`", color : LOG_COLOR); var callResult = new List <MatchesListObject>(); //hub if (hub.Endpoint == 0) { callResult = await faceit.GetMatchesFromHubBetweenDates(hub.HubGUID, startTime, endTime); } //Championships else if (hub.Endpoint == 1) { callResult = await faceit.GetMatchesFromChampionshipBetweenDates(hub.HubGUID, startTime, endTime); } var callStatus = faceit.GetStatusCode(); //Store the status code for later, used for logging purposes. _statusCodes.Add(hub, callStatus); //If status wasn't OK, go to the next hub. if (callStatus != HttpStatusCode.OK) { continue; } //Add each individual game into a list representing a single game foreach (var match in callResult) { if (match.DemoURL == null) { _matchesWithNullDemoUrls.Add(match.MatchID); continue; } if (match.Voting == null) { _matchesWithNullVoting.Add(match.MatchID); continue; } for (var i = 0; i < match.DemoURL.Count; i++) { _gameInfo.Add(new FaceItGameInfo(match, hub, _dataService.RSettings.ProgramSettings.FaceItDemoPath, i, _tempPath)); } } //Apply the hub tags onto each game foreach (var game in _gameInfo) { SetHubTagOnGame(game); } } }
public async Task <List <FaceItHubTag> > GetFaceHubTags() { var faceit = new FaceitClient(_dataService.RSettings.ProgramSettings.FaceitAPIKey); List <FaceItHubTag> tags = new List <FaceItHubTag>(); foreach (var hub in DatabaseUtil.GetHubs()) { GenericContainer <LeaderboardListObject> containerResponse = null; //hub if (hub.Endpoint == 0) { containerResponse = await faceit.GetHubLeaderboards(hub.HubGUID); } //Championships else if (hub.Endpoint == 1) { containerResponse = await faceit.GetChampionshipLeaderboards(hub.HubGUID); } foreach (var item in containerResponse.Items.Where(x => x.CompetitionID.Equals(hub.HubGUID, StringComparison.OrdinalIgnoreCase) && !x.LeaderboardType.Equals("hub_general", StringComparison.OrdinalIgnoreCase)).ToList()) { //For championships this is all we use string tagName = hub.HubType; var startDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); var endDate = new DateTime(2100, 1, 1, 0, 0, 0, DateTimeKind.Utc); if (hub.Endpoint == 0) { //Modify data for normal hubs if (item.LeaderboardType.Equals("event", StringComparison.OrdinalIgnoreCase)) { tagName += $"_{item.LeaderboardName}"; } else { string season = Regex.Match(item.LeaderboardName, @"\d+").Value; if (string.IsNullOrEmpty(season)) { season = "0"; } tagName += $"-{item.LeaderboardType}{season}"; } startDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(item.StartDate); endDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(item.EndDate); } tags.Add(new FaceItHubTag { TagName = GeneralUtil.RemoveInvalidChars(tagName).Replace(" ", "-").Replace("_", "-"), StartDate = startDate, EndDate = endDate, HubGuid = hub.HubGUID }); } } return(tags); }