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); }
internal bool TryRemoveMember(Snowflake id, out CachedMember member) { var result = _members.TryRemove(id, out member); if (result) MemberCount--; return result; }
internal bool TryAddMember(Snowflake id, CachedMember member, bool sync = false) { var result = _members.TryAdd(id, member); if (result && !sync) MemberCount++; return result; }
internal bool TryRemoveMember(Snowflake id, out CachedMember member) { var result = _members.TryRemove(id, out member); if (result) { MemberCount--; member.SharedUser.References--; } return(result); }
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; }