Beispiel #1
0
        public static async Task <List <GroupMember> > GetClanMembers(Clan clan)
        {
            SearchResultOfGroupMember group = await bungieApi.ApiEndpoints.GroupV2_GetMembersOfGroup(1, Convert.ToInt64(clan.details.ID));

            var groupList = group.results.ToList();

            return(groupList);
        }
Beispiel #2
0
        public static async Task <(List <UserInfoCard> validMembers, List <GroupUserInfoCard> invalidMembers)> GetClanInfoCards(Clan clan)
        {
            SearchResultOfGroupMember group = await bungieApi.ApiEndpoints.GroupV2_GetMembersOfGroup(1, Convert.ToInt64(clan.details.ID));

            var groupList = group.results.ToList();

            var validMembers   = groupList.Where(t => t.bungieNetUserInfo != null).Select(t => t.bungieNetUserInfo).ToList();
            var invalidMembers = groupList.Where(t => t.bungieNetUserInfo == null).Select(t => t.destinyUserInfo).ToList();

            return(validMembers, invalidMembers);
        }
Beispiel #3
0
        /// <summary>
        /// Gets all current activities for all characters for all clan members.
        /// Only gets the latest page of activies for ScoredNightfall activities.
        /// Scores then get inserted into the collection.
        /// </summary>
        /// <returns></returns>
        private async Task GetBungieScores(int count)
        {
            // Get Clan ID from Environment Variables
            long clanID = Convert.ToInt64(Environment.GetEnvironmentVariable("NFLBOT_CLANID"), CultureInfo.InvariantCulture);

            WriteLog(LogSeverity.Info, "Loading Clan Information..");
            // Get Members of Clan from Bungie
            SearchResultOfGroupMember clanResult = await bungieClient.GroupV2.GetMembersOfGroupAsync(
                groupId : clanID,
                currentpage : 0,
                memberType : RuntimeGroupMemberType.Member,
                nameSearch : string.Empty).ConfigureAwait(false);

            WriteLog(LogSeverity.Info, $"Clan Information loaded! {clanResult.Results.Length} members found.");

            // Loop through Members
            foreach (GroupMember clanMember in clanResult.Results)
            {
                // Get their Membership ID required for getting their Profile & Activity Information
                long membershipId = clanMember.DestinyUserInfo.MembershipId;

                // Get their Profile Information
                DestinyProfileResponse memberdata = await bungieClient.Destiny2.GetProfileAsync(
                    membershipType : clanMember.DestinyUserInfo.MembershipType,
                    destinyMembershipId : membershipId,
                    components : new BungieNet.Destiny.DestinyComponentType[] { BungieNet.Destiny.DestinyComponentType.Characters }).ConfigureAwait(false);

                WriteLog(LogSeverity.Debug, $"Found {memberdata.Characters.Data.Count} characters for {clanMember.DestinyUserInfo.DisplayName}");

                // Loop through Characters of Member
                foreach (var playerCharacter in memberdata.Characters.Data)
                {
                    // Hold Character ID in seperate Variable for convienence
                    long characterId = playerCharacter.Key;

                    // Get Activity History of Character
                    // Using a Try-Catch Block as players might opt-in to refuse API calls to their history
                    DestinyActivityHistoryResults activityData = null;
                    try
                    {
                        activityData = await bungieClient.Destiny2.GetActivityHistoryAsync(
                            membershipType : playerCharacter.Value.MembershipType,
                            destinyMembershipId : membershipId,
                            characterId : characterId,
                            count : count,
                            mode : BungieNet.Destiny.HistoricalStats.Definitions.DestinyActivityModeType.ScoredNightfall,
                            page : 0).ConfigureAwait(false);
                    }
                    catch (BungieException e) // Most likely to be privacy related exceptions. For now we just ignore those scores.
                    {
                        Console.WriteLine(e);
                        continue;
                    }

                    // If we didn't get any data, skip
                    if (activityData == null || activityData.Activities == null)
                    {
                        continue;
                    }

                    // Loop through Activities
                    foreach (var activity in activityData.Activities)
                    {
                        // If we already collected that Nightfall, skip it.
                        if (collection.Find(x => x.NightfallId == activity.ActivityDetails.InstanceId).Any())
                        {
                            continue;
                        }

                        // If the Activity is before the start of the ranking period (usually a Season), skip the Score.
                        var activityDate = activity.Period;
                        if (activityDate <= currentSeasonStart)
                        {
                            continue;
                        }

                        // API might return aborted Nightfalls, so their Score is 0. We want to ignore those.
                        var nightfallScore = activity.Values["teamScore"].Basic.Value;
                        if (nightfallScore <= 0)
                        {
                            continue;
                        }

                        // Get the Director Hash required for finding the Nightfall Name
                        uint directorHash = activity.ActivityDetails.DirectorActivityHash;

                        // Get the Nightfall Name
                        string activityName = GetNameFromHash(directorHash);
                        if (activityName.Equals("INVALID", StringComparison.InvariantCulture))
                        {
                            continue;
                        }

                        // Create new Score Entry
                        ScoreEntry entry = new ScoreEntry(
                            name: clanMember.DestinyUserInfo.DisplayName,
                            accountId: membershipId,
                            directorActivityHash: activity.ActivityDetails.DirectorActivityHash.ToString(),
                            nightfallId: activity.ActivityDetails.InstanceId,
                            activityName: activityName,
                            activityDate: activityDate,
                            score: nightfallScore);

                        // Insert into Collection
                        collection.InsertOne(entry);
                        WriteLog(LogSeverity.Info, $"Added Score {nightfallScore} for Player {clanMember.DestinyUserInfo.DisplayName} from {activityDate} in {activityName}");
                    }
                }
            }
        }