From 09eaac357f76e15c32dc2a5c8f8a9c9864f6153a Mon Sep 17 00:00:00 2001 From: RogueException Date: Tue, 8 Sep 2015 17:43:02 -0300 Subject: [PATCH] Added DeleteMessages() --- src/Discord.Net/DiscordClient.API.cs | 36 +++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/Discord.Net/DiscordClient.API.cs b/src/Discord.Net/DiscordClient.API.cs index 55fc3b399..939671d7a 100644 --- a/src/Discord.Net/DiscordClient.API.cs +++ b/src/Discord.Net/DiscordClient.API.cs @@ -1,6 +1,7 @@ using Discord.API; using Discord.API.Models; using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; @@ -320,7 +321,7 @@ namespace Discord public Task DeleteMessage(Message msg) => DeleteMessage(msg?.ChannelId, msg?.Id); /// Deletes the provided message. - public async Task DeleteMessage(string channelId, string msgId) + public async Task DeleteMessage(string channelId, string msgId) { CheckReady(); if (channelId == null) throw new ArgumentNullException(nameof(channelId)); @@ -329,11 +330,40 @@ namespace Discord try { await _api.DeleteMessage(channelId, msgId); - return _messages.Remove(msgId); + _messages.Remove(msgId); } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.InternalServerError) { } //TODO: Remove me - temporary fix for deleting nonexisting messages - return null; + } + public async Task DeleteMessages(IEnumerable msgs) + { + CheckReady(); + if (msgs == null) throw new ArgumentNullException(nameof(msgs)); + + foreach (var msg in msgs) + { + try + { + await _api.DeleteMessage(msg.ChannelId, msg.Id); + } + catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { } + catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.InternalServerError) { } //TODO: Remove me - temporary fix for deleting nonexisting messages + } + } + public async Task DeleteMessages(string channelId, IEnumerable msgIds) + { + CheckReady(); + if (msgIds == null) throw new ArgumentNullException(nameof(msgIds)); + + foreach (var msgId in msgIds) + { + try + { + await _api.DeleteMessage(channelId, msgId); + } + catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { } + catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.InternalServerError) { } //TODO: Remove me - temporary fix for deleting nonexisting messages + } } /// Sends a file to the provided channel.