예제 #1
0
        public async Task <IReadOnlyList <DiscordMember> > ListGuildMembersAsync(ulong guild_id, int?limit, ulong?after)
        {
            var recmbr = new List <DiscordMember>();

            var recd = 1000;
            var last = 0ul;

            while (recd == 1000)
            {
                var tms = await ApiClient.ListGuildMembersAsync(guild_id, 1000, last == 0?null : (ulong?)last).ConfigureAwait(false);

                recd = tms.Count;

                foreach (var xtm in tms)
                {
                    if (UserCache.ContainsKey(xtm.User.Id))
                    {
                        continue;
                    }

                    var usr = new DiscordUser(xtm.User)
                    {
                        Discord = this
                    };
                    UserCache.AddOrUpdate(xtm.User.Id, usr, (id, old) =>
                    {
                        old.Username   = usr.Username;
                        old.Discord    = usr.Discord;
                        old.AvatarHash = usr.AvatarHash;

                        return(old);
                    });
                }

                var tm = tms.LastOrDefault();
                last = tm?.User.Id ?? 0;

                recmbr.AddRange(tms.Select(xtm => new DiscordMember(xtm)
                {
                    Discord = this, _guild_id = guild_id
                }));
            }

            return(new ReadOnlyCollection <DiscordMember>(recmbr));
        }
예제 #2
0
        /// <summary>
        /// Initializes this client. This method fetches information about current user, application, and voice regions.
        /// </summary>
        /// <returns></returns>
        public virtual async Task InitializeAsync()
        {
            if (CurrentUser == null)
            {
                CurrentUser = await ApiClient.GetCurrentUserAsync().ConfigureAwait(false);

                UserCache.AddOrUpdate(CurrentUser.Id, CurrentUser, (id, xu) => CurrentUser);
            }

            if (Configuration.TokenType != TokenType.User && CurrentApplication == null)
            {
                CurrentApplication = await GetCurrentApplicationAsync().ConfigureAwait(false);
            }

            if (InternalVoiceRegions.Count == 0)
            {
                var vrs = await ListVoiceRegionsAsync().ConfigureAwait(false);

                foreach (var xvr in vrs)
                {
                    InternalVoiceRegions.TryAdd(xvr.Id, xvr);
                }
            }
        }
예제 #3
0
        public void AddOrUpdate_DoesNotContainItem_AddsItem()
        {
            // Act
            _uut.AddOrUpdate(UserOne, UserOnePassword);

            // Assert
            Assert.That(_uut.ExpirationStamps.Count == 1);
            Assert.That(_uut.ExpirationStamps.ContainsKey(UserOne));
        }