Skip to content

Commit

Permalink
Merge pull request discord-net#74 from khionu/master
Browse files Browse the repository at this point in the history
Add BulkMessageDelete Functionality
  • Loading branch information
Auralytical committed Jun 7, 2016
2 parents f629481 + e3dea5b commit 4e2b919
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Discord.Net.Net45/Discord.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@
<Compile Include="..\Discord.Net\API\Client\Rest\AddGuildBan.cs">
<Link>API\Client\Rest\AddGuildBan.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\API\Client\Rest\BulkMessageDelete.cs">
<Link>API\Client\Rest\BulkMessageDelete.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\API\Client\Rest\CreateChannel.cs">
<Link>API\Client\Rest\CreateChannel.cs</Link>
</Compile>
Expand Down
23 changes: 23 additions & 0 deletions src/Discord.Net/API/Client/Rest/BulkMessageDelete.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Newtonsoft.Json;

namespace Discord.API.Client.Rest
{
[JsonObject(MemberSerialization.OptIn)]
public class BulkMessageDelete : IRestRequest
{
string IRestRequest.Endpoint => $"/channels/{ChannelId}/messages/bulk_delete";
string IRestRequest.Method => "POST";
object IRestRequest.Payload => this;

public ulong ChannelId { get; set; }

public BulkMessageDelete(ulong channelId, ulong[] messageIds)
{
ChannelId = channelId;
MessageIds = messageIds;
}

[JsonProperty("messages")]
public ulong[] MessageIds { get; set; }
}
}
7 changes: 7 additions & 0 deletions src/Discord.Net/Models/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ public async Task Edit(string name = null, string topic = null, int? position =
}
}

public async Task DeleteMessages(Message[] messages) => await DeleteMessages(messages.Select(m => m.Id).ToArray());

public async Task DeleteMessages(ulong[] messageIds)
{
await Client.ClientAPI.Send(new BulkMessageDelete(Id, messageIds));
}

public async Task Delete()
{
try { await Client.ClientAPI.Send(new DeleteChannelRequest(Id)).ConfigureAwait(false); }
Expand Down

0 comments on commit 4e2b919

Please sign in to comment.