Added DeleteGuildRequest

This commit is contained in:
RogueException
2016-02-16 03:34:11 -04:00
parent 1f1e6e6ed4
commit 433ead6f3f
3 changed files with 24 additions and 5 deletions

View File

@@ -256,6 +256,9 @@
<Compile Include="..\Discord.Net\API\Client\Rest\DeleteChannel.cs">
<Link>API\Client\Rest\DeleteChannel.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\API\Client\Rest\DeleteGuild.cs">
<Link>API\Client\Rest\DeleteGuild.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\API\Client\Rest\DeleteInvite.cs">
<Link>API\Client\Rest\DeleteInvite.cs</Link>
</Compile>

View File

@@ -0,0 +1,20 @@
using Newtonsoft.Json;
namespace Discord.API.Client.Rest
{
[JsonObject(MemberSerialization.OptIn)]
public class DeleteGuildRequest : IRestRequest<Guild>
{
string IRestRequest.Method => "DELETE";
string IRestRequest.Endpoint => $"guilds/{GuildId}";
object IRestRequest.Payload => null;
bool IRestRequest.IsPrivate => false;
public ulong GuildId { get; set; }
public DeleteGuildRequest(ulong guildId)
{
GuildId = guildId;
}
}
}

View File

@@ -208,17 +208,13 @@ namespace Discord
/// <summary> Leaves this server. This function will fail if you're the owner - use Delete instead. </summary>
public async Task Leave()
{
if (_ownerId == CurrentUser.Id)
throw new InvalidOperationException("Unable to leave a server you own, use Server.Delete instead");
try { await Client.ClientAPI.Send(new LeaveGuildRequest(Id)).ConfigureAwait(false); }
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
}
/// <summary> Deletes this server. This function will fail if you're not the owner - use Leave instead. </summary>
public async Task Delete()
{
if (_ownerId != CurrentUser.Id)
throw new InvalidOperationException("Unable to delete a server you don't own, use Server.Leave instead");
try { await Client.ClientAPI.Send(new LeaveGuildRequest(Id)).ConfigureAwait(false); }
try { await Client.ClientAPI.Send(new DeleteGuildRequest(Id)).ConfigureAwait(false); }
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
}