internal CachedOverwrite(DiscordClient client, OverwriteModel model, CachedGuildChannel channel) : base(client, model.Id) { Channel = channel; TargetId = model.Id; Permissions = (model.Allow, model.Deny); TargetType = model.Type; }
internal void Update(WebSocketGuildModel model) { Update(model as GuildModel); for (var i = 0; i < model.Channels.Length; i++) { var channelModel = model.Channels[i]; _channels.AddOrUpdate(channelModel.Id, _ => CachedGuildChannel.Create(this, channelModel), (_, old) => { old.Update(channelModel); return(old); }); } Update(model.Members); for (var i = 0; i < model.VoiceStates.Length; i++) { var voiceState = model.VoiceStates[i]; _members[voiceState.UserId].Update(voiceState); } if (model.Presences != null) { Update(model.Presences); } MemberCount = model.MemberCount; IsLarge = model.Large; IsUnavailable = !model.Unavailable.HasValue || model.Unavailable.Value; }
public Task HandleChannelCreateAsync(PayloadModel payload) { var model = payload.D.ToType <ChannelModel>(); CachedChannel channel; if (model.GuildId != null) { var guild = GetGuild(model.GuildId.Value); channel = CachedGuildChannel.Create(guild, model); guild._channels.TryAdd(channel.Id, (CachedGuildChannel)channel); } else { channel = _privateChannels.GetOrAdd(model.Id, _ => CachedPrivateChannel.Create(_client, model)); } return(_client._channelCreated.InvokeAsync(new ChannelCreatedEventArgs(channel))); }
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; }