Example #1
0
        public static async Task CheckForRejoiners(Clan clan)
        {
            await SpreadsheetTools.Read(clan);

            List <SpreadsheetTools.User> rejoiners = new List <SpreadsheetTools.User>();
            var ClanMembers = await GetClanInfoCards(clan);

            //SpreadsheetTools.savedUsers.ToList().ForEach(member => {
            //    if (!ClanMembers.Select(t => t.membershipId).Contains(Convert.ToInt64(member.bungieID)))
            //    {
            //        if (!oldLeavers.Select(t => t.bungieID).Contains(member.bungieID))
            //        {
            //            if (member.bungieID != null) leavers.Add(member);
            //        }
            //    }
            //});
            //clan.Leavers.ForEach(member =>
            //{

            //});;
            foreach (var member in clan.members.ClanLeavers)
            {
                if (!ClanMembers.validMembers.Select(t => t.membershipId).Contains(Convert.ToInt64(member.BungieID)))
                {
                    rejoiners.Add(member);
                }
            }
            clan.members.ClanLeavers = rejoiners;
            Clans.SaveClanMembers(clan, UserType.Leaver);
        }
Example #2
0
        public static async Task SelectiveUpdate(Clan clan)
        {
            await Read(clan);

            var workingList = clan.members.BungieUsers;

            workingList.RemoveAll(t => string.IsNullOrEmpty(t.BungieProfile));
            workingList = workingList.DistinctBy(t => t.BungieProfile).ToList();
            workingList = workingList.OrderBy(t => t.SteamName).ToList();
            clan.members.BungieUsers = workingList;
            Write(clan);
            Clans.SaveClanMembers(clan);
        }
Example #3
0
        public static async Task <List <SpreadsheetTools.User> > CheckForLeaves(Clan clan, bool DontWrite = false)
        {
            if (clan.members.ClanLeavers != null)
            {
                await CheckForRejoiners(clan);
            }
            if (!DontWrite)
            {
                if (clan.members.ClanLeavers != null)
                {
                    List <SpreadsheetTools.User> oldLeavers = clan.members.ClanLeavers;
                    List <SpreadsheetTools.User> leavers    = new List <SpreadsheetTools.User>();
                    var ClanMembers = await GetClanInfoCards(clan);

                    foreach (var member in clan.members.BungieUsers)
                    {
                        if (!ClanMembers.validMembers.Select(t => t.membershipId).Contains(Convert.ToInt64(member.BungieID)))
                        {
                            if (!oldLeavers.Select(t => t.BungieID).Contains(member.BungieID))
                            {
                                if (member.BungieID != null)
                                {
                                    leavers.Add(member);
                                }
                            }
                        }
                    }
                    //clan.Users.ForEach(member =>
                    //{


                    //});
                    foreach (var member in leavers)
                    {
                        var workingMember = member;
                        var _             = clan.members.BungieUsers.FindIndex(t => t.BungieProfile == workingMember.BungieProfile);
                        workingMember.UserStatus    = UserStatus.StatusEnum.leftClan;
                        clan.members.BungieUsers[_] = workingMember;
                    }
                    oldLeavers.AddRange(leavers);
                    clan.members.ClanLeavers = oldLeavers;
                    Clans.SaveClanMembers(clan);
                    SpreadsheetTools.Write(clan);

                    return(leavers);
                }
                else
                {
                    List <SpreadsheetTools.User> leavers = new List <SpreadsheetTools.User>();
                    var ClanMembers = await GetClanInfoCards(clan);

                    clan.members.BungieUsers.ForEach(member =>
                    {
                        if (!ClanMembers.validMembers.Select(t => t.membershipId).Contains(Convert.ToInt64(member.BungieID)))
                        {
                            if (member.BungieID != null)
                            {
                                leavers.Add(member);
                            }
                        }
                    });
                    foreach (var member in leavers)
                    {
                        var workingMember = member;
                        var _             = clan.members.BungieUsers.FindIndex(t => t.BungieProfile == workingMember.BungieProfile);
                        workingMember.UserStatus    = UserStatus.StatusEnum.leftClan;
                        clan.members.BungieUsers[_] = workingMember;
                    }
                    clan.members.ClanLeavers = leavers;
                    Clans.SaveClanMembers(clan);
                    SpreadsheetTools.Write(clan);

                    return(leavers);
                }
            }
            else
            {
                await SpreadsheetTools.Read(clan);

                List <SpreadsheetTools.User> leavers = new List <SpreadsheetTools.User>();
                var ClanMembers = await GetClanInfoCards(clan);

                clan.members.BungieUsers.ForEach(member => {
                    if (!ClanMembers.validMembers.Select(t => t.membershipId).Contains(Convert.ToInt64(member.BungieID)))
                    {
                        if (member.BungieID != null)
                        {
                            leavers.Add(member);
                        }
                    }
                });
                //foreach (var member in leavers)
                //{
                //    var workingMember = member;
                //    var _ = clan.members.BungieUsers.FindIndex(t => t.bungieProfile == workingMember.bungieProfile);
                //    workingMember.UserStatus = SpreadsheetTools.UserStatus.leftclan;
                //    clan.members.BungieUsers[_] = workingMember;
                //}
                //SpreadsheetTools.Write(clan);
                return(leavers);
            }
        }
Example #4
0
        public static async Task SelectiveUpdate(Clan clan, Changes changes, List <DiscordMessage> modifyMessages, Action <List <DiscordMessage>, TimeSpan, Changes> modifyMethod)
        {
            await Read(clan);

            int size = (int)MathF.Ceiling((float)changes.addedUsers.Count / 5);

            TimeSpan[] durations   = new TimeSpan[size];
            var        workingList = clan.members.BungieUsers;
            int        index       = 0;

            foreach (User addedUser in changes.addedUsers)
            {
                var startTime   = DateTime.UtcNow;
                var workingUser = new User();
                if (!string.IsNullOrEmpty(addedUser.BungieProfile))
                {
                    var a = await BungieTools.GetBungieUserID(addedUser.BungieProfile);

                    workingUser.BungieID = a.ToString();
                    if (!string.IsNullOrEmpty(workingUser.BungieID))
                    {
                        string bungieProfile             = addedUser.BungieProfile;
                        string bungieID                  = workingUser.BungieID;
                        UserStatus.StatusEnum userStatus = addedUser.UserStatus;
                        GeneralUser           bungieUser = await BungieTools.GetBungieUser(Convert.ToInt64(bungieID));

                        string steamID      = SteamTools.GetSteamID(bungieProfile);
                        string steamProfile = "https://steamcommunity.com/profiles/" + steamID;
                        string bungieName   = bungieUser.displayName;
                        string steamName    = SteamTools.GetSteamUserName(steamID);
                        string discordID    = addedUser.DiscordID;
                        string userClanTag  = addedUser.ClanTag;
                        workingUser = new User(bungieProfile, bungieName, bungieID, steamProfile, steamID, steamName, discordID, userStatus, userClanTag);
                        workingList.Add(workingUser);
                    }
                    else
                    {
                        List <string> extraColumns  = new List <string>();
                        string        bungieProfile = addedUser.BungieProfile;
                        string        bungieID      = "N/A";
                        string        steamID       = "N/A";
                        string        steamProfile  = "N/A";
                        string        bungieName    = "N/A";
                        string        steamName     = "N/A";
                        string        discordID     = addedUser.DiscordID;
                        if (addedUser.BungieID != "N/A" || addedUser.BungieID != "")
                        {
                            bungieID = addedUser.BungieID;
                        }
                        if (addedUser.SteamID != "N/A" || addedUser.SteamID != "")
                        {
                            steamID = addedUser.SteamID;
                        }
                        if (addedUser.SteamProfile != "N/A" || addedUser.SteamProfile != "")
                        {
                            steamProfile = addedUser.SteamProfile;
                        }
                        if (addedUser.BungieName != "N/A" || addedUser.BungieName != "")
                        {
                            bungieName = addedUser.BungieName;
                        }
                        if (addedUser.SteamName != "N/A" || addedUser.SteamName != "")
                        {
                            steamName = addedUser.SteamName;
                        }

                        if (addedUser.ExtraColumns != null)
                        {
                            extraColumns = addedUser.ExtraColumns;
                        }
                        UserStatus.StatusEnum userStatus = addedUser.UserStatus;

                        if (addedUser.ExtraColumns != null)
                        {
                            extraColumns = addedUser.ExtraColumns;
                        }
                        workingList.Add(new User(bungieProfile, bungieName, bungieID, steamProfile, steamID, steamName, discordID, userStatus, clan.details.Tag, extraColumns));
                    }
                }
                durations[index % durations.Length] = DateTime.UtcNow - startTime;

                if (index > durations.Length - 1)
                {
                    var averageTime = TimeSpan.FromMilliseconds(durations.Average(t => t.TotalMilliseconds));
                    var usersLeft   = changes.addedUsers.Count - (index + 1);
                    if (modifyMessages != null && modifyMethod != null)
                    {
                        modifyMethod.Invoke(modifyMessages, averageTime * usersLeft, changes);
                    }
                }
                index++;
            }
            for (int i = 0; i < changes.updatedUsers.Count; i++)
            {
                index = workingList.FindIndex(t => t.BungieProfile == changes.updatedUsers[i].BungieProfile);
                workingList[index] = changes.updatedUsers[i];
            }
            changes.removedUsers.ForEach(removedUser =>
            {
                index = workingList.FindIndex(t => t.BungieProfile == removedUser.BungieProfile);
                workingList.RemoveAt(index);
            });
            workingList.RemoveAll(t => string.IsNullOrEmpty(t.BungieProfile));
            workingList = workingList.DistinctBy(t => t.BungieProfile).ToList();
            workingList = workingList.OrderBy(t => t.SteamName).ToList();
            clan.members.BungieUsers = workingList;
            Write(clan);
            Clans.SaveClanMembers(clan);
        }
Example #5
0
        public static async Task BulkUpdate(Clan clan, List <DiscordMessage> modifyMessages, Action <List <DiscordMessage>, TimeSpan> modifyMethod, bool skipRead = false)
        {
            TimeSpan[] durations = new TimeSpan[5];
            if (!skipRead)
            {
                await Read(clan);
            }
            //ShowLoading("processing...");
            var         _           = clan.members.SpreadsheetUsers;
            List <User> workingList = new List <User>();
            int         index       = 0;

            foreach (User user in _)
            {
                var startTime   = DateTime.UtcNow;
                var workingUser = new User();
                if (!string.IsNullOrEmpty(user.BungieProfile))
                {
                    long?a = await BungieTools.GetBungieUserID(user.BungieProfile);

                    workingUser.BungieID = a.ToString();
                    if (!string.IsNullOrEmpty(workingUser.BungieID))
                    {
                        List <string> extraColumns  = new List <string>();
                        string        bungieProfile = user.BungieProfile;
                        string        bungieID      = workingUser.BungieID;
                        GeneralUser   bungieUser    = await BungieTools.GetBungieUser(Convert.ToInt64(bungieID));

                        string steamID      = SteamTools.GetSteamID(bungieProfile);
                        string steamName    = SteamTools.GetSteamUserName(steamID);
                        string steamProfile = "https://steamcommunity.com/profiles/" + steamID;
                        string bungieName   = bungieUser.displayName;
                        string discordID    = user.DiscordID;
                        UserStatus.StatusEnum userStatus = user.UserStatus;

                        if (user.ExtraColumns != null)
                        {
                            extraColumns = user.ExtraColumns;
                        }
                        if (steamName == null || steamID == null)
                        {
                            steamName = "N/A"; steamProfile = "N/A";
                        }
                        workingList.Add(new User(bungieProfile, bungieName, bungieID, steamProfile, steamID, steamName, discordID, userStatus, clan.details.Tag, extraColumns));
                    }
                    else
                    {
                        List <string>         extraColumns  = new List <string>();
                        string                bungieProfile = user.BungieProfile;
                        string                bungieID      = "N/A";
                        string                steamID       = "N/A";
                        string                steamProfile  = "N/A";
                        string                bungieName    = "N/A";
                        string                steamName     = "N/A";
                        string                discordID     = user.DiscordID;
                        UserStatus.StatusEnum userStatus    = user.UserStatus;
                        if (user.BungieID != "N/A" || user.BungieID != null)
                        {
                            bungieID = user.BungieID;
                        }
                        if (user.SteamID != "N/A" || user.SteamID != null)
                        {
                            steamID = user.SteamID;
                        }
                        if (user.SteamProfile != "N/A" || user.SteamProfile != null)
                        {
                            steamProfile = user.SteamProfile;
                        }
                        if (user.BungieName != "N/A" || user.BungieName != null)
                        {
                            bungieName = user.BungieName;
                        }
                        if (user.SteamName != "N/A" || user.SteamName != null)
                        {
                            steamName = user.SteamName;
                        }

                        if (user.ExtraColumns != null)
                        {
                            extraColumns = user.ExtraColumns;
                        }
                        workingList.Add(new User(bungieProfile, bungieName, bungieID, steamProfile, steamID, steamName, discordID, userStatus, clan.details.Tag, extraColumns));
                    }
                }
                durations[index % durations.Length] = DateTime.UtcNow - startTime;

                if (index > durations.Length - 1)
                {
                    var averageTime = TimeSpan.FromMilliseconds(durations.Average(t => t.TotalMilliseconds));
                    var usersLeft   = _.Count - (index + 1);
                    if (modifyMessages != null && modifyMethod != null)
                    {
                        modifyMethod.Invoke(modifyMessages, averageTime * usersLeft);
                    }
                }
                index++;
            }
            workingList.RemoveAll(t => string.IsNullOrEmpty(t.BungieProfile));
            workingList = workingList.DistinctBy(t => t.BungieProfile).ToList();
            workingList = workingList.OrderBy(t => t.SteamName).ToList();
            clan.members.BungieUsers = workingList;
            Write(clan);
            Clans.SaveClanMembers(clan);
        }