From 6e8d1118ec0c2e47e2ef7a1e694a37dc046e1fba Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sat, 12 Nov 2016 23:04:08 -0500 Subject: [PATCH 1/7] Update API models to fully support rich embeds --- src/Discord.Net.Core/API/Common/Embed.cs | 8 ++++++++ src/Discord.Net.Core/API/Common/EmbedAuthor.cs | 16 ++++++++++++++++ src/Discord.Net.Core/API/Common/EmbedField.cs | 14 ++++++++++++++ src/Discord.Net.Core/API/Common/EmbedFooter.cs | 14 ++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 src/Discord.Net.Core/API/Common/EmbedAuthor.cs create mode 100644 src/Discord.Net.Core/API/Common/EmbedField.cs create mode 100644 src/Discord.Net.Core/API/Common/EmbedFooter.cs diff --git a/src/Discord.Net.Core/API/Common/Embed.cs b/src/Discord.Net.Core/API/Common/Embed.cs index 9cea24313..b19281d24 100644 --- a/src/Discord.Net.Core/API/Common/Embed.cs +++ b/src/Discord.Net.Core/API/Common/Embed.cs @@ -13,9 +13,17 @@ namespace Discord.API public string Description { get; set; } [JsonProperty("url")] public string Url { get; set; } + [JsonProperty("color")] + public uint Color { get; set; } + [JsonProperty("author")] + public Optional Author { get; set; } + [JsonProperty("footer")] + public Optional Footer { get; set; } [JsonProperty("thumbnail")] public Optional Thumbnail { get; set; } [JsonProperty("provider")] public Optional Provider { get; set; } + [JsonProperty("fields")] + public Optional Fields { get; set; } } } diff --git a/src/Discord.Net.Core/API/Common/EmbedAuthor.cs b/src/Discord.Net.Core/API/Common/EmbedAuthor.cs new file mode 100644 index 000000000..973f7d5ea --- /dev/null +++ b/src/Discord.Net.Core/API/Common/EmbedAuthor.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + public class EmbedAuthor + { + [JsonProperty("name")] + public string Name { get; set; } + [JsonProperty("url")] + public string Url { get; set; } + [JsonProperty("icon_url")] + public string IconUrl { get; set; } + [JsonProperty("proxy_icon_url")] + public string ProxyIconUrl { get; set; } + } +} diff --git a/src/Discord.Net.Core/API/Common/EmbedField.cs b/src/Discord.Net.Core/API/Common/EmbedField.cs new file mode 100644 index 000000000..12aa0137a --- /dev/null +++ b/src/Discord.Net.Core/API/Common/EmbedField.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + public class EmbedField + { + [JsonProperty("name")] + public string Name { get; set; } + [JsonProperty("value")] + public string Value { get; set; } + [JsonProperty("inline")] + public bool Inline { get; set; } + } +} diff --git a/src/Discord.Net.Core/API/Common/EmbedFooter.cs b/src/Discord.Net.Core/API/Common/EmbedFooter.cs new file mode 100644 index 000000000..2ad22cae7 --- /dev/null +++ b/src/Discord.Net.Core/API/Common/EmbedFooter.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; + +namespace Discord.API +{ + public class EmbedFooter + { + [JsonProperty("text")] + public string Text { get; set; } + [JsonProperty("icon_url")] + public string IconUrl { get; set; } + [JsonProperty("proxy_icon_url")] + public string ProxyIconUrl { get; set; } + } +} From 63b06ff4776dc10d0c3f9f9f63aa1a2c9c91d3ad Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sat, 12 Nov 2016 23:23:38 -0500 Subject: [PATCH 2/7] Support Rich Embeds on Entities --- src/Discord.Net.Core/API/Common/Embed.cs | 2 +- .../Entities/Messages/EmbedAuthor.cs | 29 +++++++++++++++++++ .../Entities/Messages/EmbedField.cs | 27 +++++++++++++++++ .../Entities/Messages/EmbedFooter.cs | 27 +++++++++++++++++ .../Entities/Messages/IEmbed.cs | 8 ++++- .../Entities/Messages/Embed.cs | 26 ++++++++++++++--- 6 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 src/Discord.Net.Core/Entities/Messages/EmbedAuthor.cs create mode 100644 src/Discord.Net.Core/Entities/Messages/EmbedField.cs create mode 100644 src/Discord.Net.Core/Entities/Messages/EmbedFooter.cs diff --git a/src/Discord.Net.Core/API/Common/Embed.cs b/src/Discord.Net.Core/API/Common/Embed.cs index b19281d24..ed4715237 100644 --- a/src/Discord.Net.Core/API/Common/Embed.cs +++ b/src/Discord.Net.Core/API/Common/Embed.cs @@ -14,7 +14,7 @@ namespace Discord.API [JsonProperty("url")] public string Url { get; set; } [JsonProperty("color")] - public uint Color { get; set; } + public uint? Color { get; set; } [JsonProperty("author")] public Optional Author { get; set; } [JsonProperty("footer")] diff --git a/src/Discord.Net.Core/Entities/Messages/EmbedAuthor.cs b/src/Discord.Net.Core/Entities/Messages/EmbedAuthor.cs new file mode 100644 index 000000000..b0ed0f08f --- /dev/null +++ b/src/Discord.Net.Core/Entities/Messages/EmbedAuthor.cs @@ -0,0 +1,29 @@ +using System.Diagnostics; +using Model = Discord.API.EmbedAuthor; + +namespace Discord +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public struct EmbedAuthor + { + public string Name { get; set; } + public string Url { get; set; } + public string IconUrl { get; set; } + public string ProxyIconUrl { get; set; } + + private EmbedAuthor(string name, string url, string iconUrl, string proxyIconUrl) + { + Name = name; + Url = url; + IconUrl = iconUrl; + ProxyIconUrl = proxyIconUrl; + } + internal static EmbedAuthor Create(Model model) + { + return new EmbedAuthor(model.Name, model.Url, model.IconUrl, model.ProxyIconUrl); + } + + private string DebuggerDisplay => $"{Name} ({Url})"; + public override string ToString() => Name; + } +} diff --git a/src/Discord.Net.Core/Entities/Messages/EmbedField.cs b/src/Discord.Net.Core/Entities/Messages/EmbedField.cs new file mode 100644 index 000000000..257074e41 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Messages/EmbedField.cs @@ -0,0 +1,27 @@ +using System.Diagnostics; +using Model = Discord.API.EmbedField; + +namespace Discord +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public struct EmbedField + { + public string Name { get; set; } + public string Value { get; set; } + public bool Inline { get; set; } + + private EmbedField(string name, string value, bool inline) + { + Name = name; + Value = value; + Inline = inline; + } + internal static EmbedField Create(Model model) + { + return new EmbedField(model.Name, model.Value, model.Inline); + } + + private string DebuggerDisplay => $"{Name} ({Value}"; + public override string ToString() => Name; + } +} diff --git a/src/Discord.Net.Core/Entities/Messages/EmbedFooter.cs b/src/Discord.Net.Core/Entities/Messages/EmbedFooter.cs new file mode 100644 index 000000000..a69e4b077 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Messages/EmbedFooter.cs @@ -0,0 +1,27 @@ +using System.Diagnostics; +using Model = Discord.API.EmbedFooter; + +namespace Discord +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public struct EmbedFooter + { + public string Text { get; set; } + public string IconUrl { get; set; } + public string ProxyUrl { get; set; } + + private EmbedFooter(string text, string iconUrl, string proxyUrl) + { + Text = text; + IconUrl = iconUrl; + ProxyUrl = proxyUrl; + } + internal static EmbedFooter Create(Model model) + { + return new EmbedFooter(model.Text, model.IconUrl, model.ProxyIconUrl); + } + + private string DebuggerDisplay => $"{Text} ({IconUrl})"; + public override string ToString() => Text; + } +} diff --git a/src/Discord.Net.Core/Entities/Messages/IEmbed.cs b/src/Discord.Net.Core/Entities/Messages/IEmbed.cs index 3bca85fd0..311fbff01 100644 --- a/src/Discord.Net.Core/Entities/Messages/IEmbed.cs +++ b/src/Discord.Net.Core/Entities/Messages/IEmbed.cs @@ -1,4 +1,6 @@ -namespace Discord +using System.Collections.Immutable; + +namespace Discord { public interface IEmbed { @@ -6,7 +8,11 @@ string Type { get; } string Title { get; } string Description { get; } + uint? Color { get; } + EmbedAuthor? Author { get; } + EmbedFooter? Footer { get; } EmbedProvider? Provider { get; } EmbedThumbnail? Thumbnail { get; } + ImmutableArray Fields { get; } } } diff --git a/src/Discord.Net.Rest/Entities/Messages/Embed.cs b/src/Discord.Net.Rest/Entities/Messages/Embed.cs index 20979534e..e85bf9cca 100644 --- a/src/Discord.Net.Rest/Entities/Messages/Embed.cs +++ b/src/Discord.Net.Rest/Entities/Messages/Embed.cs @@ -1,4 +1,6 @@ -using System.Diagnostics; +using System.Collections.Immutable; +using System.Diagnostics; +using System.Linq; using Model = Discord.API.Embed; namespace Discord @@ -10,10 +12,23 @@ namespace Discord public string Url { get; } public string Title { get; } public string Type { get; } + public uint? Color { get; } + public EmbedAuthor? Author { get; } + public EmbedFooter? Footer { get; } public EmbedProvider? Provider { get; } public EmbedThumbnail? Thumbnail { get; } + public ImmutableArray Fields { get; } - internal Embed(string type, string title, string description, string url, EmbedProvider? provider, EmbedThumbnail? thumbnail) + internal Embed(string type, + string title, + string description, + string url, + uint? color, + EmbedAuthor? author, + EmbedFooter? footer, + EmbedProvider? provider, + EmbedThumbnail? thumbnail, + ImmutableArray fields) { Type = type; Title = title; @@ -24,9 +39,12 @@ namespace Discord } internal static Embed Create(Model model) { - return new Embed(model.Type, model.Title, model.Description, model.Url, + return new Embed(model.Type, model.Title, model.Description, model.Url, model.Color, + model.Author.IsSpecified ? EmbedAuthor.Create(model.Author.Value) : (EmbedAuthor?)null, + model.Footer.IsSpecified ? EmbedFooter.Create(model.Footer.Value) : (EmbedFooter?)null, model.Provider.IsSpecified ? EmbedProvider.Create(model.Provider.Value) : (EmbedProvider?)null, - model.Thumbnail.IsSpecified ? EmbedThumbnail.Create(model.Thumbnail.Value) : (EmbedThumbnail?)null); + model.Thumbnail.IsSpecified ? EmbedThumbnail.Create(model.Thumbnail.Value) : (EmbedThumbnail?)null, + model.Fields.IsSpecified ? model.Fields.Value.Select(x => EmbedField.Create(x)).ToImmutableArray() : ImmutableArray.Create()); } public override string ToString() => Title; From 52f979ec8a19600872c0bb73b4f7c27f1d2b6027 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sun, 13 Nov 2016 00:35:46 -0500 Subject: [PATCH 3/7] Support sending rich embeds, add an Embed Builder --- .../API/Rest/CreateMessageParams.cs | 3 + .../Entities/Messages/IEmbed.cs | 2 +- src/Discord.Net.Core/Utils/EmbedBuilder.cs | 132 ++++++++++++++++++ .../Entities/Channels/ChannelHelper.cs | 7 + .../Entities/Messages/Embed.cs | 14 +- 5 files changed, 153 insertions(+), 5 deletions(-) create mode 100644 src/Discord.Net.Core/Utils/EmbedBuilder.cs diff --git a/src/Discord.Net.Core/API/Rest/CreateMessageParams.cs b/src/Discord.Net.Core/API/Rest/CreateMessageParams.cs index 9577ab579..a0dbb59dd 100644 --- a/src/Discord.Net.Core/API/Rest/CreateMessageParams.cs +++ b/src/Discord.Net.Core/API/Rest/CreateMessageParams.cs @@ -1,4 +1,5 @@ #pragma warning disable CS1591 +using System; using Newtonsoft.Json; namespace Discord.API.Rest @@ -13,6 +14,8 @@ namespace Discord.API.Rest public Optional Nonce { get; set; } [JsonProperty("tts")] public Optional IsTTS { get; set; } + [JsonProperty("embed")] + public Optional Embed { get; set; } public CreateMessageParams(string content) { diff --git a/src/Discord.Net.Core/Entities/Messages/IEmbed.cs b/src/Discord.Net.Core/Entities/Messages/IEmbed.cs index 311fbff01..c46b22d17 100644 --- a/src/Discord.Net.Core/Entities/Messages/IEmbed.cs +++ b/src/Discord.Net.Core/Entities/Messages/IEmbed.cs @@ -8,7 +8,7 @@ namespace Discord string Type { get; } string Title { get; } string Description { get; } - uint? Color { get; } + Color? Color { get; } EmbedAuthor? Author { get; } EmbedFooter? Footer { get; } EmbedProvider? Provider { get; } diff --git a/src/Discord.Net.Core/Utils/EmbedBuilder.cs b/src/Discord.Net.Core/Utils/EmbedBuilder.cs new file mode 100644 index 000000000..42861709f --- /dev/null +++ b/src/Discord.Net.Core/Utils/EmbedBuilder.cs @@ -0,0 +1,132 @@ +using System; +using System.Collections.Generic; +using Embed = Discord.API.Embed; +using Field = Discord.API.EmbedField; +using Author = Discord.API.EmbedAuthor; +using Footer = Discord.API.EmbedFooter; + +namespace Discord +{ + public class EmbedBuilder + { + private Embed embed = new Embed(); + List fields = new List(); + + public EmbedBuilder() + { + embed.Type = "rich"; + } + + public EmbedBuilder Title(string title) + { + embed.Title = title; + return this; + } + public EmbedBuilder Description(string description) + { + embed.Description = description; + return this; + } + public EmbedBuilder Url(string url) + { + embed.Url = url; + return this; + } + public EmbedBuilder Color(Color color) + { + embed.Color = color.RawValue; + return this; + } + public EmbedBuilder Field(Func builder) + { + fields.Add(builder(new EmbedFieldBuilder()).Build()); + return this; + } + public EmbedBuilder Author(Func builder) + { + embed.Author = builder(new EmbedAuthorBuilder()).Build(); + return this; + } + public EmbedBuilder Footer(Func builder) + { + embed.Footer = builder(new EmbedFooterBuilder()).Build(); + return this; + } + public Embed Build() + { + embed.Fields = fields.ToArray(); + return embed; + } + + } + + public class EmbedFieldBuilder + { + private Field embedField = new Field(); + + public EmbedFieldBuilder Name(string name) + { + embedField.Name = name; + return this; + } + public EmbedFieldBuilder Value(string value) + { + embedField.Value = value; + return this; + } + public EmbedFieldBuilder Inline(bool inline) + { + embedField.Inline = inline; + return this; + } + public Field Build() + { + return embedField; + } + } + + public class EmbedAuthorBuilder + { + private Author author = new Author(); + + public EmbedAuthorBuilder Name(string name) + { + author.Name = name; + return this; + } + public EmbedAuthorBuilder Url(string url) + { + author.Url = url; + return this; + } + public EmbedAuthorBuilder IconUrl(string iconUrl) + { + author.IconUrl = iconUrl; + return this; + } + public Author Build() + { + return author; + } + } + + public class EmbedFooterBuilder + { + private Footer footer = new Footer(); + + public EmbedFooterBuilder Text(string text) + { + footer.Text = text; + return this; + } + public EmbedFooterBuilder IconUrl(string iconUrl) + { + footer.IconUrl = iconUrl; + return this; + } + public Footer Build() + { + return footer; + } + } +} diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index 858269366..a27bf0493 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -116,6 +116,13 @@ namespace Discord.Rest var model = await client.ApiClient.CreateMessageAsync(channel.Id, args, options).ConfigureAwait(false); return RestUserMessage.Create(client, guild, model); } + public static async Task SendRichMessageAsync(IChannel channel, BaseDiscordClient client, + string text, bool isTTS, API.Embed embed, IGuild guild, RequestOptions options) + { + var args = new CreateMessageParams(text) { IsTTS = isTTS, Embed = embed }; + var model = await client.ApiClient.CreateMessageAsync(channel.Id, args, options).ConfigureAwait(false); + return RestUserMessage.Create(client, guild, model); + } public static async Task SendFileAsync(IChannel channel, BaseDiscordClient client, string filePath, string text, bool isTTS, IGuild guild, RequestOptions options) diff --git a/src/Discord.Net.Rest/Entities/Messages/Embed.cs b/src/Discord.Net.Rest/Entities/Messages/Embed.cs index e85bf9cca..540a39ea2 100644 --- a/src/Discord.Net.Rest/Entities/Messages/Embed.cs +++ b/src/Discord.Net.Rest/Entities/Messages/Embed.cs @@ -1,4 +1,5 @@ -using System.Collections.Immutable; +using System; +using System.Collections.Immutable; using System.Diagnostics; using System.Linq; using Model = Discord.API.Embed; @@ -12,7 +13,7 @@ namespace Discord public string Url { get; } public string Title { get; } public string Type { get; } - public uint? Color { get; } + public Color? Color { get; } public EmbedAuthor? Author { get; } public EmbedFooter? Footer { get; } public EmbedProvider? Provider { get; } @@ -23,7 +24,7 @@ namespace Discord string title, string description, string url, - uint? color, + Color? color, EmbedAuthor? author, EmbedFooter? footer, EmbedProvider? provider, @@ -34,12 +35,17 @@ namespace Discord Title = title; Description = description; Url = url; + Color = color; + Author = author; + Footer = footer; Provider = provider; Thumbnail = thumbnail; + Fields = fields; } internal static Embed Create(Model model) { - return new Embed(model.Type, model.Title, model.Description, model.Url, model.Color, + return new Embed(model.Type, model.Title, model.Description, model.Url, + model.Color.HasValue ? new Color(model.Color.Value) : (Color?)null, model.Author.IsSpecified ? EmbedAuthor.Create(model.Author.Value) : (EmbedAuthor?)null, model.Footer.IsSpecified ? EmbedFooter.Create(model.Footer.Value) : (EmbedFooter?)null, model.Provider.IsSpecified ? EmbedProvider.Create(model.Provider.Value) : (EmbedProvider?)null, From bad7d827c3a7ac98a07cca9f20afa422242bdc04 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sun, 13 Nov 2016 00:51:40 -0500 Subject: [PATCH 4/7] Modify SendMessage to include an embeds field --- src/Discord.Net.Commands/ModuleBase.cs | 4 ++-- src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs | 2 +- src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs | 7 ------- .../Entities/Channels/IRestMessageChannel.cs | 2 +- src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs | 8 ++++---- .../Entities/Channels/RestGroupChannel.cs | 8 ++++---- src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs | 8 ++++---- .../Entities/Channels/RestVirtualMessageChannel.cs | 8 ++++---- src/Discord.Net.Rpc/Entities/Channels/RpcDMChannel.cs | 8 ++++---- src/Discord.Net.Rpc/Entities/Channels/RpcGroupChannel.cs | 8 ++++---- src/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs | 8 ++++---- .../Entities/Channels/ISocketMessageChannel.cs | 2 +- .../Entities/Channels/SocketDMChannel.cs | 8 ++++---- .../Entities/Channels/SocketGroupChannel.cs | 8 ++++---- .../Entities/Channels/SocketTextChannel.cs | 8 ++++---- 15 files changed, 45 insertions(+), 52 deletions(-) diff --git a/src/Discord.Net.Commands/ModuleBase.cs b/src/Discord.Net.Commands/ModuleBase.cs index c5b6d7436..73770402e 100644 --- a/src/Discord.Net.Commands/ModuleBase.cs +++ b/src/Discord.Net.Commands/ModuleBase.cs @@ -6,9 +6,9 @@ namespace Discord.Commands { public CommandContext Context { get; internal set; } - protected virtual async Task ReplyAsync(string message, bool isTTS = false, RequestOptions options = null) + protected virtual async Task ReplyAsync(string message, bool isTTS = false, API.Embed embed = null, RequestOptions options = null) { - return await Context.Channel.SendMessageAsync(message, isTTS, options).ConfigureAwait(false); + return await Context.Channel.SendMessageAsync(message, isTTS, embed, options).ConfigureAwait(false); } } } diff --git a/src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs b/src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs index 7c13e4a6f..30ca044bd 100644 --- a/src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs +++ b/src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs @@ -8,7 +8,7 @@ namespace Discord public interface IMessageChannel : IChannel { /// Sends a message to this message channel. - Task SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null); + Task SendMessageAsync(string text, bool isTTS = false, API.Embed embed = null, RequestOptions options = null); /// Sends a file to this text channel, with an optional caption. Task SendFileAsync(string filePath, string text = null, bool isTTS = false, RequestOptions options = null); /// Sends a file to this text channel, with an optional caption. diff --git a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs index a27bf0493..aecdf292e 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs @@ -110,13 +110,6 @@ namespace Discord.Rest } public static async Task SendMessageAsync(IChannel channel, BaseDiscordClient client, - string text, bool isTTS, IGuild guild, RequestOptions options) - { - var args = new CreateMessageParams(text) { IsTTS = isTTS }; - var model = await client.ApiClient.CreateMessageAsync(channel.Id, args, options).ConfigureAwait(false); - return RestUserMessage.Create(client, guild, model); - } - public static async Task SendRichMessageAsync(IChannel channel, BaseDiscordClient client, string text, bool isTTS, API.Embed embed, IGuild guild, RequestOptions options) { var args = new CreateMessageParams(text) { IsTTS = isTTS, Embed = embed }; diff --git a/src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs b/src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs index 6d2b729dd..82783700e 100644 --- a/src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs @@ -7,7 +7,7 @@ namespace Discord.Rest public interface IRestMessageChannel : IMessageChannel { /// Sends a message to this message channel. - new Task SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null); + new Task SendMessageAsync(string text, bool isTTS = false, API.Embed embed = null, RequestOptions options = null); /// Sends a file to this text channel, with an optional caption. new Task SendFileAsync(string filePath, string text = null, bool isTTS = false, RequestOptions options = null); /// Sends a file to this text channel, with an optional caption. diff --git a/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs index 9d866220d..8c547ad80 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs @@ -63,8 +63,8 @@ namespace Discord.Rest public Task> GetPinnedMessagesAsync(RequestOptions options = null) => ChannelHelper.GetPinnedMessagesAsync(this, Discord, null, options); - public Task SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, null, options); + public Task SendMessageAsync(string text, bool isTTS = false, API.Embed embed = null, RequestOptions options = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, null, options); public Task SendFileAsync(string filePath, string text, bool isTTS = false, RequestOptions options = null) => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, null, options); public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, RequestOptions options = null) @@ -126,8 +126,8 @@ namespace Discord.Rest => await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) => await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false); - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options).ConfigureAwait(false); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, API.Embed embed, RequestOptions options) + => await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs index bb840ece4..eb29192c4 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs @@ -76,8 +76,8 @@ namespace Discord.Rest public Task> GetPinnedMessagesAsync(RequestOptions options = null) => ChannelHelper.GetPinnedMessagesAsync(this, Discord, null, options); - public Task SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, null, options); + public Task SendMessageAsync(string text, bool isTTS = false, API.Embed embed = null, RequestOptions options = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, null, options); public Task SendFileAsync(string filePath, string text, bool isTTS = false, RequestOptions options = null) => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, null, options); public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, RequestOptions options = null) @@ -136,8 +136,8 @@ namespace Discord.Rest => await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) => await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false); - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options).ConfigureAwait(false); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, API.Embed embed, RequestOptions options) + => await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); diff --git a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs index 4a617517e..5c6fc371b 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs @@ -55,8 +55,8 @@ namespace Discord.Rest public Task> GetPinnedMessagesAsync(RequestOptions options = null) => ChannelHelper.GetPinnedMessagesAsync(this, Discord, null, options); - public Task SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, null, options); + public Task SendMessageAsync(string text, bool isTTS = false, API.Embed embed = null, RequestOptions options = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, null, options); public Task SendFileAsync(string filePath, string text, bool isTTS = false, RequestOptions options = null) => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, null, options); public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, RequestOptions options = null) @@ -108,8 +108,8 @@ namespace Discord.Rest => await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) => await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false); - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options).ConfigureAwait(false); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, API.Embed embed, RequestOptions options) + => await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); diff --git a/src/Discord.Net.Rest/Entities/Channels/RestVirtualMessageChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestVirtualMessageChannel.cs index 97a0a93e6..a99430a82 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestVirtualMessageChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestVirtualMessageChannel.cs @@ -33,8 +33,8 @@ namespace Discord.Rest public Task> GetPinnedMessagesAsync(RequestOptions options = null) => ChannelHelper.GetPinnedMessagesAsync(this, Discord, null, options); - public Task SendMessageAsync(string text, bool isTTS, RequestOptions options = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, null, options); + public Task SendMessageAsync(string text, bool isTTS, API.Embed embed = null, RequestOptions options = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, null, options); public Task SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options = null) => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, null, options); public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options = null) @@ -86,8 +86,8 @@ namespace Discord.Rest => await SendFileAsync(filePath, text, isTTS, options); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) => await SendFileAsync(stream, filename, text, isTTS, options); - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, API.Embed embed, RequestOptions options) + => await SendMessageAsync(text, isTTS, embed, options); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); diff --git a/src/Discord.Net.Rpc/Entities/Channels/RpcDMChannel.cs b/src/Discord.Net.Rpc/Entities/Channels/RpcDMChannel.cs index 3df04b320..e9393b5f9 100644 --- a/src/Discord.Net.Rpc/Entities/Channels/RpcDMChannel.cs +++ b/src/Discord.Net.Rpc/Entities/Channels/RpcDMChannel.cs @@ -44,8 +44,8 @@ namespace Discord.Rpc public Task> GetPinnedMessagesAsync(RequestOptions options = null) => ChannelHelper.GetPinnedMessagesAsync(this, Discord, null, options); - public Task SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, null, options); + public Task SendMessageAsync(string text, bool isTTS = false, API.Embed embed = null, RequestOptions options = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, null, options); public Task SendFileAsync(string filePath, string text, bool isTTS = false, RequestOptions options = null) => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, null, options); public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, RequestOptions options = null) @@ -104,8 +104,8 @@ namespace Discord.Rpc => await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) => await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false); - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options).ConfigureAwait(false); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, API.Embed embed, RequestOptions options) + => await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); diff --git a/src/Discord.Net.Rpc/Entities/Channels/RpcGroupChannel.cs b/src/Discord.Net.Rpc/Entities/Channels/RpcGroupChannel.cs index d88847067..12fb91343 100644 --- a/src/Discord.Net.Rpc/Entities/Channels/RpcGroupChannel.cs +++ b/src/Discord.Net.Rpc/Entities/Channels/RpcGroupChannel.cs @@ -46,8 +46,8 @@ namespace Discord.Rpc public Task> GetPinnedMessagesAsync(RequestOptions options = null) => ChannelHelper.GetPinnedMessagesAsync(this, Discord, null, options); - public Task SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, null, options); + public Task SendMessageAsync(string text, bool isTTS = false, API.Embed embed = null, RequestOptions options = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, null, options); public Task SendFileAsync(string filePath, string text, bool isTTS = false, RequestOptions options = null) => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, null, options); public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, RequestOptions options = null) @@ -103,8 +103,8 @@ namespace Discord.Rpc => await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) => await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false); - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options).ConfigureAwait(false); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, API.Embed embed, RequestOptions options) + => await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); diff --git a/src/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs b/src/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs index e6e3d3e48..7b20660ab 100644 --- a/src/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs +++ b/src/Discord.Net.Rpc/Entities/Channels/RpcTextChannel.cs @@ -49,8 +49,8 @@ namespace Discord.Rpc public Task> GetPinnedMessagesAsync(RequestOptions options = null) => ChannelHelper.GetPinnedMessagesAsync(this, Discord, null, options); - public Task SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, null, options); + public Task SendMessageAsync(string text, bool isTTS = false, API.Embed embed = null, RequestOptions options = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, null, options); public Task SendFileAsync(string filePath, string text, bool isTTS = false, RequestOptions options = null) => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, null, options); public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, RequestOptions options = null) @@ -105,8 +105,8 @@ namespace Discord.Rpc => await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) => await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false); - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options).ConfigureAwait(false); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, API.Embed embed, RequestOptions options) + => await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs index 7ba08544b..ed22c78a8 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs @@ -11,7 +11,7 @@ namespace Discord.WebSocket IReadOnlyCollection CachedMessages { get; } /// Sends a message to this message channel. - new Task SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null); + new Task SendMessageAsync(string text, bool isTTS = false, API.Embed embed = null, RequestOptions options = null); /// Sends a file to this text channel, with an optional caption. new Task SendFileAsync(string filePath, string text = null, bool isTTS = false, RequestOptions options = null); /// Sends a file to this text channel, with an optional caption. diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs index 4da4139d0..e9d37cc9c 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs @@ -66,8 +66,8 @@ namespace Discord.WebSocket public Task> GetPinnedMessagesAsync(RequestOptions options = null) => ChannelHelper.GetPinnedMessagesAsync(this, Discord, null, options); - public Task SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, null, options); + public Task SendMessageAsync(string text, bool isTTS = false, API.Embed embed = null, RequestOptions options = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, null, options); public Task SendFileAsync(string filePath, string text, bool isTTS = false, RequestOptions options = null) => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, null, options); public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, RequestOptions options = null) @@ -134,8 +134,8 @@ namespace Discord.WebSocket => await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) => await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false); - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options).ConfigureAwait(false); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, API.Embed embed, RequestOptions options) + => await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs index 3b47a8452..723df5390 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs @@ -89,8 +89,8 @@ namespace Discord.WebSocket public Task> GetPinnedMessagesAsync(RequestOptions options = null) => ChannelHelper.GetPinnedMessagesAsync(this, Discord, null, options); - public Task SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, null, options); + public Task SendMessageAsync(string text, bool isTTS = false, API.Embed embed = null, RequestOptions options = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, null, options); public Task SendFileAsync(string filePath, string text, bool isTTS = false, RequestOptions options = null) => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, null, options); public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, RequestOptions options = null) @@ -197,8 +197,8 @@ namespace Discord.WebSocket => await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) => await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false); - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options).ConfigureAwait(false); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, API.Embed embed, RequestOptions options) + => await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs index 8dff22232..693af4312 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs @@ -72,8 +72,8 @@ namespace Discord.WebSocket public Task> GetPinnedMessagesAsync(RequestOptions options = null) => ChannelHelper.GetPinnedMessagesAsync(this, Discord, Guild, options); - public Task SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null) - => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, Guild, options); + public Task SendMessageAsync(string text, bool isTTS = false, API.Embed embed = null, RequestOptions options = null) + => ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, Guild, options); public Task SendFileAsync(string filePath, string text, bool isTTS = false, RequestOptions options = null) => ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, Guild, options); public Task SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, RequestOptions options = null) @@ -135,8 +135,8 @@ namespace Discord.WebSocket => await SendFileAsync(filePath, text, isTTS, options).ConfigureAwait(false); async Task IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options) => await SendFileAsync(stream, filename, text, isTTS, options).ConfigureAwait(false); - async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options) - => await SendMessageAsync(text, isTTS, options).ConfigureAwait(false); + async Task IMessageChannel.SendMessageAsync(string text, bool isTTS, API.Embed embed, RequestOptions options) + => await SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false); IDisposable IMessageChannel.EnterTypingState(RequestOptions options) => EnterTypingState(options); } From 8866a1499c33bf1bc585f1b95033379a7c03fef6 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sun, 13 Nov 2016 01:02:44 -0500 Subject: [PATCH 5/7] Allow content to be empty when sending a message --- src/Discord.Net.Core/API/DiscordRestApiClient.cs | 3 +-- src/Discord.Net.Core/API/Rest/CreateMessageParams.cs | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net.Core/API/DiscordRestApiClient.cs b/src/Discord.Net.Core/API/DiscordRestApiClient.cs index ac18e8ace..91bdbfd11 100644 --- a/src/Discord.Net.Core/API/DiscordRestApiClient.cs +++ b/src/Discord.Net.Core/API/DiscordRestApiClient.cs @@ -439,8 +439,7 @@ namespace Discord.API { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); - Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content)); - if (args.Content.Length > DiscordConfig.MaxMessageSize) + if (args.Content.GetValueOrDefault()?.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); diff --git a/src/Discord.Net.Core/API/Rest/CreateMessageParams.cs b/src/Discord.Net.Core/API/Rest/CreateMessageParams.cs index a0dbb59dd..a6b06f9f8 100644 --- a/src/Discord.Net.Core/API/Rest/CreateMessageParams.cs +++ b/src/Discord.Net.Core/API/Rest/CreateMessageParams.cs @@ -8,7 +8,7 @@ namespace Discord.API.Rest public class CreateMessageParams { [JsonProperty("content")] - public string Content { get; } + public Optional Content { get; } [JsonProperty("nonce")] public Optional Nonce { get; set; } @@ -19,7 +19,10 @@ namespace Discord.API.Rest public CreateMessageParams(string content) { - Content = content; + if (string.IsNullOrEmpty(content)) + Content = null; + else + Content = content; } } } From 754970bb566efc55ea51d2c4380bbfe46cb7cf90 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sun, 13 Nov 2016 13:54:46 -0500 Subject: [PATCH 6/7] When sending a message with no content, do not send a null value. Resolves an issue where the ratelimiter would panic. --- src/Discord.Net.Core/API/Rest/CreateMessageParams.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Discord.Net.Core/API/Rest/CreateMessageParams.cs b/src/Discord.Net.Core/API/Rest/CreateMessageParams.cs index a6b06f9f8..9904f12bb 100644 --- a/src/Discord.Net.Core/API/Rest/CreateMessageParams.cs +++ b/src/Discord.Net.Core/API/Rest/CreateMessageParams.cs @@ -9,7 +9,6 @@ namespace Discord.API.Rest { [JsonProperty("content")] public Optional Content { get; } - [JsonProperty("nonce")] public Optional Nonce { get; set; } [JsonProperty("tts")] @@ -20,7 +19,7 @@ namespace Discord.API.Rest public CreateMessageParams(string content) { if (string.IsNullOrEmpty(content)) - Content = null; + Content = Optional.Create(); else Content = content; } From 3698dbfedc209bb2e962bedfd59185c754c0b87b Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sun, 13 Nov 2016 14:16:49 -0500 Subject: [PATCH 7/7] Only allow messages with an embed present to be sent with no content --- src/Discord.Net.Core/API/DiscordRestApiClient.cs | 5 ++++- src/Discord.Net.Core/API/Rest/CreateMessageParams.cs | 8 +++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Discord.Net.Core/API/DiscordRestApiClient.cs b/src/Discord.Net.Core/API/DiscordRestApiClient.cs index 91bdbfd11..7268d7b34 100644 --- a/src/Discord.Net.Core/API/DiscordRestApiClient.cs +++ b/src/Discord.Net.Core/API/DiscordRestApiClient.cs @@ -439,7 +439,10 @@ namespace Discord.API { Preconditions.NotEqual(channelId, 0, nameof(channelId)); Preconditions.NotNull(args, nameof(args)); - if (args.Content.GetValueOrDefault()?.Length > DiscordConfig.MaxMessageSize) + if (!args.Embed.IsSpecified || args.Embed.Value == null) + Preconditions.NotNullOrEmpty(args.Content, nameof(args.Content)); + + 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); diff --git a/src/Discord.Net.Core/API/Rest/CreateMessageParams.cs b/src/Discord.Net.Core/API/Rest/CreateMessageParams.cs index 9904f12bb..a0dbb59dd 100644 --- a/src/Discord.Net.Core/API/Rest/CreateMessageParams.cs +++ b/src/Discord.Net.Core/API/Rest/CreateMessageParams.cs @@ -8,7 +8,8 @@ namespace Discord.API.Rest public class CreateMessageParams { [JsonProperty("content")] - public Optional Content { get; } + public string Content { get; } + [JsonProperty("nonce")] public Optional Nonce { get; set; } [JsonProperty("tts")] @@ -18,10 +19,7 @@ namespace Discord.API.Rest public CreateMessageParams(string content) { - if (string.IsNullOrEmpty(content)) - Content = Optional.Create(); - else - Content = content; + Content = content; } } }