diff --git a/src/Discord.Net.Rest/API/Rest/CreateWebhookMessageParams.cs b/src/Discord.Net.Rest/API/Rest/CreateWebhookMessageParams.cs index b9c77279f..970a30201 100644 --- a/src/Discord.Net.Rest/API/Rest/CreateWebhookMessageParams.cs +++ b/src/Discord.Net.Rest/API/Rest/CreateWebhookMessageParams.cs @@ -8,8 +8,6 @@ namespace Discord.API.Rest { [JsonProperty("content")] public string Content { get; } - [JsonProperty("wait")] - public bool ReturnCreatedMessage { get; set; } = true; [JsonProperty("nonce")] public Optional Nonce { get; set; } diff --git a/src/Discord.Net.Rest/API/Rest/ModifyWebhookParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyWebhookParams.cs index 1d385c328..0f2d6e33b 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyWebhookParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyWebhookParams.cs @@ -10,5 +10,7 @@ namespace Discord.API.Rest public Optional Name { get; set; } [JsonProperty("avatar")] public Optional Avatar { get; set; } + [JsonProperty("channel_id")] + public Optional ChannelId { get; set; } } } diff --git a/src/Discord.Net.Rest/API/Rest/UploadWebhookFileParams.cs b/src/Discord.Net.Rest/API/Rest/UploadWebhookFileParams.cs index f2c34c015..6d6eb29b2 100644 --- a/src/Discord.Net.Rest/API/Rest/UploadWebhookFileParams.cs +++ b/src/Discord.Net.Rest/API/Rest/UploadWebhookFileParams.cs @@ -1,7 +1,7 @@ #pragma warning disable CS1591 -using Discord.Net.Rest; using System.Collections.Generic; using System.IO; +using Discord.Net.Rest; namespace Discord.API.Rest { @@ -15,6 +15,7 @@ namespace Discord.API.Rest public Optional IsTTS { get; set; } public Optional Username { get; set; } public Optional AvatarUrl { get; set; } + public Optional Embeds { get; set; } public UploadWebhookFileParams(Stream file) { @@ -25,6 +26,7 @@ namespace Discord.API.Rest { var d = new Dictionary(); d["file"] = new MultipartFile(File, Filename.GetValueOrDefault("unknown.dat")); + if (Content.IsSpecified) d["content"] = Content.Value; if (IsTTS.IsSpecified) @@ -35,6 +37,8 @@ namespace Discord.API.Rest d["username"] = Username.Value; if (AvatarUrl.IsSpecified) d["avatar_url"] = AvatarUrl.Value; + if (Embeds.IsSpecified) + d["embeds"] = Embeds.Value; return d; } } diff --git a/src/Discord.Net.Rest/BaseDiscordClient.cs b/src/Discord.Net.Rest/BaseDiscordClient.cs index 621ca16d9..269dedd71 100644 --- a/src/Discord.Net.Rest/BaseDiscordClient.cs +++ b/src/Discord.Net.Rest/BaseDiscordClient.cs @@ -164,7 +164,7 @@ namespace Discord.Rest Task IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options) => Task.FromResult(null); - Task IDiscordClient.GetWebhookAsync(ulong id, string webhookToken, RequestOptions options) + Task IDiscordClient.GetWebhookAsync(ulong id, RequestOptions options) => Task.FromResult(null); Task IDiscordClient.StartAsync() diff --git a/src/Discord.Net.Rest/ClientHelper.cs b/src/Discord.Net.Rest/ClientHelper.cs index 12f2f95e6..26d8c720e 100644 --- a/src/Discord.Net.Rest/ClientHelper.cs +++ b/src/Discord.Net.Rest/ClientHelper.cs @@ -144,9 +144,9 @@ namespace Discord.Rest return null; } - public static async Task GetWebhookAsync(BaseDiscordClient client, ulong id, string webhookToken, RequestOptions options) + public static async Task GetWebhookAsync(BaseDiscordClient client, ulong id, RequestOptions options) { - var model = await client.ApiClient.GetWebhookAsync(id, webhookToken); + var model = await client.ApiClient.GetWebhookAsync(id); if (model != null) return RestWebhook.Create(client, (IGuild)null, model); return null; diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index b3d7c5d5a..df1ad49dd 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -486,12 +486,8 @@ namespace Discord.API if (args.Content.Length > DiscordConfig.MaxMessageSize) throw new ArgumentException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content)); options = RequestOptions.CreateOrClone(options); - - if (args.ReturnCreatedMessage) - return await SendJsonAsync("POST", () => $"webhooks/{webhookId}/{AuthToken}", args, new BucketIds(), clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); - - await SendJsonAsync("POST", () => $"webhooks/{webhookId}/{AuthToken}", args, new BucketIds(), clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); - return null; + + return await SendJsonAsync("POST", () => $"webhooks/{webhookId}/{AuthToken}?wait=true", args, new BucketIds(), clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); } public async Task UploadFileAsync(ulong channelId, UploadFileParams args, RequestOptions options = null) { @@ -507,7 +503,7 @@ namespace Discord.API var ids = new BucketIds(channelId: channelId); return await SendMultipartAsync("POST", () => $"channels/{channelId}/messages", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); } - public async Task UploadWebhookFileAsync(ulong webhookId, UploadWebhookFileParams args, RequestOptions options = null) + public async Task UploadWebhookFileAsync(ulong webhookId, UploadWebhookFileParams args, RequestOptions options = null) { if (AuthTokenType != TokenType.Webhook) throw new InvalidOperationException($"This operation may only be called with a {nameof(TokenType.Webhook)} token."); @@ -526,7 +522,7 @@ namespace Discord.API throw new ArgumentOutOfRangeException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content)); } - await SendMultipartAsync("POST", () => $"webhooks/{webhookId}/{AuthToken}", args.ToDictionary(), new BucketIds(), clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); + return await SendMultipartAsync("POST", () => $"webhooks/{webhookId}/{AuthToken}?wait=true", args.ToDictionary(), new BucketIds(), clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); } public async Task DeleteMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) { diff --git a/src/Discord.Net.Rest/DiscordRestClient.cs b/src/Discord.Net.Rest/DiscordRestClient.cs index 1169bca9e..3d90b6c00 100644 --- a/src/Discord.Net.Rest/DiscordRestClient.cs +++ b/src/Discord.Net.Rest/DiscordRestClient.cs @@ -92,8 +92,8 @@ namespace Discord.Rest public Task GetVoiceRegionAsync(string id, RequestOptions options = null) => ClientHelper.GetVoiceRegionAsync(this, id, options); /// - public Task GetWebhookAsync(ulong id, string webhookToken = null, RequestOptions options = null) - => ClientHelper.GetWebhookAsync(this, id, webhookToken, options); + public Task GetWebhookAsync(ulong id, RequestOptions options = null) + => ClientHelper.GetWebhookAsync(this, id, options); //IDiscordClient async Task IDiscordClient.GetApplicationInfoAsync(RequestOptions options) @@ -164,7 +164,7 @@ namespace Discord.Rest async Task IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options) => await GetVoiceRegionAsync(id, options).ConfigureAwait(false); - async Task IDiscordClient.GetWebhookAsync(ulong id, string webhookToken, RequestOptions options) - => await GetWebhookAsync(id, webhookToken, options); + async Task IDiscordClient.GetWebhookAsync(ulong id, RequestOptions options) + => await GetWebhookAsync(id, options); } } diff --git a/src/Discord.Net.Rest/Entities/Webhooks/RestWebhook.cs b/src/Discord.Net.Rest/Entities/Webhooks/RestWebhook.cs index 6fe277d23..47cc50a9c 100644 --- a/src/Discord.Net.Rest/Entities/Webhooks/RestWebhook.cs +++ b/src/Discord.Net.Rest/Entities/Webhooks/RestWebhook.cs @@ -10,41 +10,45 @@ namespace Discord.Rest { internal IGuild Guild { get; private set; } internal ITextChannel Channel { get; private set; } - public string Token { get; private set; } + + public ulong ChannelId { get; } + public string Token { get; } + public string Name { get; private set; } public string AvatarId { get; private set; } - public ulong ChannelId { get; private set; } - public ulong GuildId { get; private set; } + public ulong? GuildId { get; private set; } public IUser Creator { get; private set; } public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); - internal RestWebhook(BaseDiscordClient discord, IGuild guild, ulong id) + internal RestWebhook(BaseDiscordClient discord, IGuild guild, ulong id, string token, ulong channelId) : base(discord, id) { Guild = guild; + Token = token; + ChannelId = channelId; } - internal RestWebhook(BaseDiscordClient discord, ITextChannel channel, ulong id) - : this(discord, channel.Guild, id) + internal RestWebhook(BaseDiscordClient discord, ITextChannel channel, ulong id, string token, ulong channelId) + : this(discord, channel.Guild, id, token, channelId) { Channel = channel; } + internal static RestWebhook Create(BaseDiscordClient discord, IGuild guild, Model model) { - var entity = new RestWebhook(discord, guild, model.Id); + var entity = new RestWebhook(discord, guild, model.Id, model.Token, model.ChannelId); entity.Update(model); return entity; } internal static RestWebhook Create(BaseDiscordClient discord, ITextChannel channel, Model model) { - var entity = new RestWebhook(discord, channel, model.Id); + var entity = new RestWebhook(discord, channel, model.Id, model.Token, model.ChannelId); entity.Update(model); return entity; } + internal void Update(Model model) { - Token = model.Token; - ChannelId = model.ChannelId; if (model.Avatar.IsSpecified) AvatarId = model.Avatar.Value; if (model.Creator.IsSpecified) @@ -73,16 +77,8 @@ namespace Discord.Rest public Task DeleteAsync(RequestOptions options = null) => WebhookHelper.DeleteAsync(this, Discord, options); - public async Task GetChannelAsync(RequestOptions options = null) - { - Channel = await ClientHelper.GetChannelAsync(Discord, ChannelId, options) as RestTextChannel; - Guild = Channel.Guild; - - return Channel as RestTextChannel; - } - - public override string ToString() => Name; - private string DebuggerDisplay => $"{Name} ({Id})"; + public override string ToString() => $"Webhook: {Name}:{Id}"; + private string DebuggerDisplay => $"Webhook: {Name} ({Id})"; //IWebhook IGuild IWebhook.Guild diff --git a/src/Discord.Net.Rest/Entities/Webhooks/WebhookHelper.cs b/src/Discord.Net.Rest/Entities/Webhooks/WebhookHelper.cs index 1c1481661..50e9cab78 100644 --- a/src/Discord.Net.Rest/Entities/Webhooks/WebhookHelper.cs +++ b/src/Discord.Net.Rest/Entities/Webhooks/WebhookHelper.cs @@ -1,6 +1,6 @@ -using Discord.API.Rest; -using System; +using System; using System.Threading.Tasks; +using Discord.API.Rest; using ImageModel = Discord.API.Image; using Model = Discord.API.Webhook; @@ -22,6 +22,11 @@ namespace Discord.Rest if (!apiArgs.Avatar.IsSpecified && webhook.AvatarId != null) apiArgs.Avatar = new ImageModel(webhook.AvatarId); + if (args.Channel.IsSpecified) + apiArgs.ChannelId = args.Channel.Value.Id; + else if (args.ChannelId.IsSpecified) + apiArgs.ChannelId = args.ChannelId.Value; + return await client.ApiClient.ModifyWebhookAsync(webhook.Id, apiArgs, options).ConfigureAwait(false); } public static async Task DeleteAsync(IWebhook webhook, BaseDiscordClient client, RequestOptions options)