From 7898b74207dd96b61c8e50ed0616958014d7a2c9 Mon Sep 17 00:00:00 2001 From: RogueException Date: Sun, 15 May 2016 19:25:57 -0300 Subject: [PATCH] Added content preconditions to CreateMessage and UploadFile --- src/Discord.Net/API/DiscordRawClient.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Discord.Net/API/DiscordRawClient.cs b/src/Discord.Net/API/DiscordRawClient.cs index 9875f423e..b4f23d5d4 100644 --- a/src/Discord.Net/API/DiscordRawClient.cs +++ b/src/Discord.Net/API/DiscordRawClient.cs @@ -628,6 +628,9 @@ namespace Discord.API { if (args == null) throw new ArgumentNullException(nameof(args)); if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId)); + if (string.IsNullOrEmpty(args.Content)) throw new ArgumentNullException(nameof(args.Content)); + if (args.Content.Length > DiscordConfig.MaxMessageSize) + throw new ArgumentOutOfRangeException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content)); if (guildId != 0) return await Send("POST", $"channels/{channelId}/messages", args, GuildBucket.SendEditMessage, guildId).ConfigureAwait(false); @@ -641,6 +644,12 @@ namespace Discord.API if (args == null) throw new ArgumentNullException(nameof(args)); //if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId)); if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId)); + if (args.Content.IsSpecified) + { + if (string.IsNullOrEmpty(args.Content.Value)) throw new ArgumentNullException(nameof(args.Content)); + if (args.Content.Value.Length > DiscordConfig.MaxMessageSize) + throw new ArgumentOutOfRangeException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content)); + } if (guildId != 0) return await Send("POST", $"channels/{channelId}/messages", file, args.ToDictionary(), GuildBucket.SendEditMessage, guildId).ConfigureAwait(false);