示例#1
0
        public override ValueTask <ChannelUpdatedEventArgs> HandleDispatchAsync(IGatewayApiClient shard, ChannelJsonModel model)
        {
            if (!model.GuildId.HasValue)
            {
                return(new(result : null));
            }

            CachedGuildChannel oldChannel;
            IGuildChannel      newChannel;

            if (CacheProvider.TryGetChannels(model.GuildId.Value, out var cache) && cache.TryGetValue(model.Id, out var channel))
            {
                newChannel = channel;
                oldChannel = channel.Clone() as CachedGuildChannel;
                newChannel.Update(model);
            }
            else
            {
                oldChannel = null;
                newChannel = TransientGuildChannel.Create(Client, model);
            }

            var e = new ChannelUpdatedEventArgs(oldChannel, newChannel);

            return(new(e));
        }
示例#2
0
        public override ValueTask <ChannelDeletedEventArgs> HandleDispatchAsync(IGatewayApiClient shard, ChannelJsonModel model)
        {
            if (!model.GuildId.HasValue)
            {
                return(new(result : null));
            }

            IGuildChannel channel;

            if (CacheProvider.TryGetChannels(model.GuildId.Value, out var cache) && cache.TryRemove(model.Id, out var cachedChannel))
            {
                channel = cachedChannel;
            }
            else
            {
                channel = TransientGuildChannel.Create(Client, model);
            }

            //  TODO: Pass removed messages to e?
            CacheProvider.TryRemoveCache <CachedUserMessage>(model.Id, out _);

            var e = new ChannelDeletedEventArgs(channel);

            return(new(e));
        }
        public static async Task <IReadOnlyList <IGuildChannel> > FetchChannelsAsync(this IRestClient client,
                                                                                     Snowflake guildId,
                                                                                     IRestRequestOptions options = null, CancellationToken cancellationToken = default)
        {
            var models = await client.ApiClient.FetchGuildChannelsAsync(guildId, options, cancellationToken).ConfigureAwait(false);

            return(models.ToReadOnlyList(client, (x, client) => TransientGuildChannel.Create(client, x)));
        }
示例#4
0
        public override ValueTask <ChannelCreatedEventArgs> HandleDispatchAsync(IGatewayApiClient shard, ChannelJsonModel model)
        {
            if (!model.GuildId.HasValue)
            {
                return(new(result : null));
            }

            IGuildChannel channel;

            if (CacheProvider.TryGetChannels(model.GuildId.Value, out var cache))
            {
                channel = CachedGuildChannel.Create(Client, model);
                cache.Add(channel.Id, channel as CachedGuildChannel);
            }
            else
            {
                channel = TransientGuildChannel.Create(Client, model);
            }

            var e = new ChannelCreatedEventArgs(channel);

            return(new(e));
        }