From aeebe5d596328c9bd49cb404aa75ecbad82892cc Mon Sep 17 00:00:00 2001 From: Khionu Terabite Date: Sun, 19 Jun 2016 05:11:11 -0400 Subject: [PATCH 1/3] Added OutOfBounds exception for DeleteMessages, for when Message Count is less than 2 or greater than 100 --- src/Discord.Net/Models/Channel.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Discord.Net/Models/Channel.cs b/src/Discord.Net/Models/Channel.cs index 03eb5d6101..2835a10874 100644 --- a/src/Discord.Net/Models/Channel.cs +++ b/src/Discord.Net/Models/Channel.cs @@ -204,6 +204,8 @@ public async Task Edit(string name = null, string topic = null, int? position = public async Task DeleteMessages(ulong[] messageIds) { + if (messageIds.Count() < 2) throw new ArgumentOutOfRangeException("messageIds", "You must provide at least 2 Messages or Message Ids"); + await Client.ClientAPI.Send(new BulkMessageDelete(Id, messageIds)); } From 402d47959c6065a744dd80cc9a4c7cc7783d1239 Mon Sep 17 00:00:00 2001 From: Khionu Terabite Date: Sun, 19 Jun 2016 05:17:32 -0400 Subject: [PATCH 2/3] Included unsaved local changes --- src/Discord.Net/Models/Channel.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net/Models/Channel.cs b/src/Discord.Net/Models/Channel.cs index 2835a10874..26973bd235 100644 --- a/src/Discord.Net/Models/Channel.cs +++ b/src/Discord.Net/Models/Channel.cs @@ -204,7 +204,9 @@ public async Task Edit(string name = null, string topic = null, int? position = public async Task DeleteMessages(ulong[] messageIds) { - if (messageIds.Count() < 2) throw new ArgumentOutOfRangeException("messageIds", "You must provide at least 2 Messages or Message Ids"); + if (messageIds.Count() < 2 || messageIds.Count() > 100) + throw new ArgumentOutOfRangeException("messageIds", + "You must provide no more than 100 and no less than 2 Messages or Message Ids"); await Client.ClientAPI.Send(new BulkMessageDelete(Id, messageIds)); } From 99637d0a215d4408c1bc4ec8589f6425c6119b74 Mon Sep 17 00:00:00 2001 From: Khionu Terabite Date: Tue, 21 Jun 2016 06:13:42 -0400 Subject: [PATCH 3/3] Separated the conditions --- src/Discord.Net/Models/Channel.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net/Models/Channel.cs b/src/Discord.Net/Models/Channel.cs index 26973bd235..cd73b607c3 100644 --- a/src/Discord.Net/Models/Channel.cs +++ b/src/Discord.Net/Models/Channel.cs @@ -204,11 +204,14 @@ public async Task Edit(string name = null, string topic = null, int? position = public async Task DeleteMessages(ulong[] messageIds) { - if (messageIds.Count() < 2 || messageIds.Count() > 100) + if (messageIds.Count() > 100) throw new ArgumentOutOfRangeException("messageIds", - "You must provide no more than 100 and no less than 2 Messages or Message Ids"); - - await Client.ClientAPI.Send(new BulkMessageDelete(Id, messageIds)); + "You must provide no more than 100 Messages or Message Ids"); + + if (messageIds.Count() == 1) + await Client.ClientAPI.Send(new DeleteMessageRequest(Id, messageIds.First())); + else if (messageIds.Any()) + await Client.ClientAPI.Send(new BulkMessageDelete(Id, messageIds)); } public async Task Delete()