Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        /// <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);
                }
            }
        }