public Task RemoveGroupRecipientAsync(Snowflake channelId, Snowflake userId, RestRequestOptions options = null)
 => ApiClient.GroupDmRecipientRemoveAsync(channelId, userId, options);
        public async Task <IReadOnlyList <RestVoiceRegion> > GetVoiceRegionsAsync(RestRequestOptions options = null)
        {
            var models = await ApiClient.ListVoiceRegionsAsync(options).ConfigureAwait(false);

            return(models.ToReadOnlyList(this, (x, @this) => new RestVoiceRegion(@this, x)));
        }
Example #3
0
        public async ValueTask <IReadOnlyList <T> > FlattenAsync(CancellationToken cancellationToken, RestRequestOptions options = null)
        {
            if (_isDisposed)
            {
                throw new ObjectDisposedException(null);
            }

            if (cancellationToken.IsCancellationRequested || _cts.IsCancellationRequested)
            {
                return(ImmutableArray <T> .Empty);
            }

            var builder = ImmutableArray.CreateBuilder <T>();

            while (!cancellationToken.IsCancellationRequested && !_cts.IsCancellationRequested &&
                   await MoveNextAsync(options).ConfigureAwait(false))
            {
                builder.AddRange(Current);
            }

            return(builder.ToImmutable());
        }
 public Task DeleteRelationshipAsync(Snowflake userId, RestRequestOptions options = null)
 => ApiClient.DeleteRelationshipAsync(userId, options);
 public Task SendOrAcceptFriendRequestAsync(Snowflake userId, RestRequestOptions options = null)
 => ApiClient.CreateRelationshipAsync(userId, null, options);
 public Task DeleteGuildEmojiAsync(Snowflake guildId, Snowflake emojiId, RestRequestOptions options = null)
 => ApiClient.DeleteGuildEmojiAsync(guildId, emojiId, options);
 public Task SendOrAcceptFriendRequestAsync(string name, string discriminator, RestRequestOptions options = null)
 => ApiClient.SendFriendRequestAsync(name, discriminator, options);
        public async Task <RestWebhook> GetWebhookAsync(Snowflake webhookId, string webhookToken, RestRequestOptions options = null)
        {
            try
            {
                var model = await ApiClient.GetWebhookWithTokenAsync(webhookId, webhookToken, options).ConfigureAwait(false);

                return(new RestWebhook(this, model));
            }
            catch (DiscordHttpException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound)
            {
                return(null);
            }
        }
        public async Task <RestWebhook> ModifyWebhookAsync(Snowflake webhookId, string webhookToken, Action <ModifyWebhookProperties> action, RestRequestOptions options = null)
        {
            var model = await InternalModifyWebhookAsync(webhookId, webhookToken, action, options).ConfigureAwait(false);

            return(new RestWebhook(this, model));
        }
        public async Task <RestWebhook> CreateWebhookAsync(Snowflake channelId, string name, Stream avatar = null, RestRequestOptions options = null)
        {
            var model = await ApiClient.CreateWebhookAsync(channelId, name, avatar, options).ConfigureAwait(false);

            return(new RestWebhook(this, model));
        }
        public async Task <IReadOnlyList <RestWebhook> > GetGuildWebhooksAsync(Snowflake guildId, RestRequestOptions options = null)
        {
            var models = await ApiClient.GetGuildWebhooksAsync(guildId, options).ConfigureAwait(false);

            return(models.ToReadOnlyList(this, (x, @this) => new RestWebhook(@this, x)));
        }
 public Task DeleteOrCloseChannelAsync(Snowflake channelId, RestRequestOptions options = null)
 => ApiClient.DeleteOrCloseChannelAsync(channelId, options);
        internal async Task <ChannelModel> InternalModifyChannelAsync <T>(Snowflake channelId, Action <T> action, RestRequestOptions options = null)
            where T : ModifyChannelProperties
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            // Can't use the new() generic constraint because the constructors are internal.
            // Can't use the generic CreateInstance either *because*.
            var properties = (T)Activator.CreateInstance(typeof(T), true);

            action(properties);
            return(await ApiClient.ModifyChannelAsync(channelId, properties, options).ConfigureAwait(false));
        }
        public async Task <RestCategoryChannel> ModifyCategoryChannelAsync(Snowflake channelId, Action <ModifyCategoryChannelProperties> action, RestRequestOptions options = null)
        {
            var model = await InternalModifyChannelAsync(channelId, action, options).ConfigureAwait(false);

            return(new RestCategoryChannel(this, model));
        }
Example #15
0
        public async Task <RestGuildEmoji> ModifyGuildEmojiAsync(Snowflake guildId, Snowflake emojiId, Action <ModifyGuildEmojiProperties> action, RestRequestOptions options = null)
        {
            var model = await InternalModifyGuildEmojiAsync(guildId, emojiId, action, options).ConfigureAwait(false);

            return(new RestGuildEmoji(this, model, guildId));
        }
        internal async Task <WebhookModel> InternalModifyWebhookAsync(Snowflake webhookId, string webhookToken, Action <ModifyWebhookProperties> action, RestRequestOptions options = null)
        {
            var properties = new ModifyWebhookProperties();

            action(properties);
            return(await ApiClient.ModifyWebhookWithTokenAsync(webhookId, webhookToken, properties, options).ConfigureAwait(false));
        }
Example #17
0
        internal async Task <EmojiModel> InternalModifyGuildEmojiAsync(Snowflake guildId, Snowflake emojiId, Action <ModifyGuildEmojiProperties> action, RestRequestOptions options = null)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            var properties = new ModifyGuildEmojiProperties();

            action(properties);
            var model = await ApiClient.ModifyGuildEmojiAsync(guildId, emojiId, properties, options).ConfigureAwait(false);

            return(model);
        }
 public Task DeleteWebhookAsync(Snowflake webhookId, RestRequestOptions options = null)
 => ApiClient.DeleteWebhookAsync(webhookId, options);
Example #19
0
 public RestRequest(HttpMethod method, FormattableString url, IReadOnlyDictionary <string, object> queryStringParameters, IRequestContent content, RestRequestOptions options)
 {
     _tcs    = new TaskCompletionSource <HttpResponseMessage>();
     _url    = url;
     _method = method;
     _queryStringParameters = queryStringParameters;
     _content = content;
     Options  = options.Clone();
 }
 public Task DeleteWebhookAsync(Snowflake webhookId, string webhookToken, RestRequestOptions options = null)
 => ApiClient.DeleteWebhookWithTokenAsync(webhookId, webhookToken, options);
 public Task BlockUserAsync(Snowflake userId, RestRequestOptions options = null)
 => ApiClient.CreateRelationshipAsync(userId, RelationshipType.Blocked, options);
Example #22
0
        public static Task RemoveReactionAsync(IMessage message, Snowflake memberId, IEmoji emoji, RestRequestOptions options)
        {
            if (emoji == null)
            {
                throw new ArgumentNullException(nameof(emoji));
            }

            return(message.Client.RemoveMemberReactionAsync(message.ChannelId, message.Id, memberId, emoji, options));
        }
        public async Task <IReadOnlyList <RestUser> > GetMutualFriendsAsync(Snowflake userId, RestRequestOptions options = null)
        {
            var models = await ApiClient.GetMutualFriendsAsync(userId, options).ConfigureAwait(false);

            return(models.ToReadOnlyList(this, (x, @this) => new RestUser(@this, x)));
        }
Example #24
0
        public async Task <IReadOnlyList <RestGuildEmoji> > GetGuildEmojisAsync(Snowflake guildId, RestRequestOptions options = null)
        {
            var models = await ApiClient.ListGuildEmojisAsync(guildId, options).ConfigureAwait(false);

            return(models.Select(x => new RestGuildEmoji(this, x, guildId)).ToImmutableArray());
        }
Example #25
0
        public async Task ModifyAsync(Action <ModifyUserSettingsProperties> action, RestRequestOptions options = null)
        {
            var model = await Client.InternalModifyUserSettingsAsync(action, options).ConfigureAwait(false);

            Update(model);
        }
Example #26
0
        public async Task <RestGuildEmoji> GetGuildEmojiAsync(Snowflake guildId, Snowflake emojiId, RestRequestOptions options = null)
        {
            try
            {
                var model = await ApiClient.GetGuildEmojiAsync(guildId, emojiId, options).ConfigureAwait(false);

                return(new RestGuildEmoji(this, model, guildId));
            }
            catch (DiscordHttpException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound && ex.JsonErrorCode == JsonErrorCode.UnknownEmoji)
            {
                return(null);
            }
        }
Example #27
0
 public ValueTask <IReadOnlyList <T> > FlattenAsync(RestRequestOptions options = null)
 => FlattenAsync(CancellationToken.None, options);
Example #28
0
        public async Task <RestGuildEmoji> CreateGuildEmojiAsync(Snowflake guildId, string name, LocalAttachment image, IEnumerable <Snowflake> roleIds = null, RestRequestOptions options = null)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            name = name ?? Path.GetFileNameWithoutExtension(image.FileName);
            var model = await ApiClient.CreateGuildEmojiAsync(guildId, name, image, roleIds.Select(x => x.RawValue), options).ConfigureAwait(false);

            return(new RestGuildEmoji(this, model, guildId));
        }
Example #29
0
 public HttpContent Prepare(IJsonSerializer serializer, RestRequestOptions options)
 => JsonRequestContent.PrepareFor(Object, serializer, options);
 public Task AddGroupRecipientAsync(Snowflake channelId, Snowflake userId, string nick = null, string accessToken = null, RestRequestOptions options = null)
 => ApiClient.GroupDmRecipientAddAsync(channelId, userId, nick, accessToken, options);