示例#1
0
        public CachedMember AddMember(CachedGuild guild, MemberModel memberModel, UserModel usermodel, bool sync = false)
        {
            var member = new CachedMember(GetOrAddSharedUser(usermodel), guild, memberModel);

            guild.TryAddMember(usermodel.Id, member, sync);
            return(member);
        }
示例#2
0
 internal bool TryRemoveMember(Snowflake id, out CachedMember member)
 {
     var result = _members.TryRemove(id, out member);
     if (result)
         MemberCount--;
     return result;
 }
示例#3
0
 internal bool TryAddMember(Snowflake id, CachedMember member, bool sync = false)
 {
     var result = _members.TryAdd(id, member);
     if (result && !sync)
         MemberCount++;
     return result;
 }
示例#4
0
        internal bool TryRemoveMember(Snowflake id, out CachedMember member)
        {
            var result = _members.TryRemove(id, out member);

            if (result)
            {
                MemberCount--;
                member.SharedUser.References--;
            }
            return(result);
        }
示例#5
0
        internal void Update(WebSocketGuildModel model)
        {
            Update(model as GuildModel);

            _channels.Clear();
            for (var i = 0; i < model.Channels.Length; i++)
            {
                var channelModel = model.Channels[i];
                _channels.TryAdd(channelModel.Id, CachedGuildChannel.Create(Client, channelModel, this));
            }

            _members.Clear();
            for (var i = 0; i < model.Members.Length; i++)
            {
                var memberModel = model.Members[i];
                CachedMember member = null;
                if (Client.IsBot || !Client.IsBot && !_members.ContainsKey(memberModel.User.Id))
                    member = Client.GetOrCreateMember(this, memberModel, memberModel.User, true);

                if (member != null)
                {
                    var voiceState = Array.Find(model.VoiceStates, x => x.UserId == member.Id);
                    if (voiceState != null)
                        member.Update(voiceState);
                }
            }

            if (!Client.IsBot)
            {
                Update(model.Presences);
            }

            MemberCount = model.MemberCount;
            IsLarge = model.Large;
            IsUnavailable = !model.Unavailable.HasValue || model.Unavailable.Value;
        }