From 433ead6f3f201e87a62d8d7c1b50bddbfd35ad17 Mon Sep 17 00:00:00 2001 From: RogueException Date: Tue, 16 Feb 2016 03:34:11 -0400 Subject: [PATCH] Added DeleteGuildRequest --- src/Discord.Net.Net45/Discord.Net.csproj | 3 +++ .../API/Client/Rest/DeleteGuild.cs | 20 +++++++++++++++++++ src/Discord.Net/Models/Server.cs | 6 +----- 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 src/Discord.Net/API/Client/Rest/DeleteGuild.cs diff --git a/src/Discord.Net.Net45/Discord.Net.csproj b/src/Discord.Net.Net45/Discord.Net.csproj index d8023d6bd..b26180c07 100644 --- a/src/Discord.Net.Net45/Discord.Net.csproj +++ b/src/Discord.Net.Net45/Discord.Net.csproj @@ -256,6 +256,9 @@ API\Client\Rest\DeleteChannel.cs + + API\Client\Rest\DeleteGuild.cs + API\Client\Rest\DeleteInvite.cs diff --git a/src/Discord.Net/API/Client/Rest/DeleteGuild.cs b/src/Discord.Net/API/Client/Rest/DeleteGuild.cs new file mode 100644 index 000000000..d55c6d989 --- /dev/null +++ b/src/Discord.Net/API/Client/Rest/DeleteGuild.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; + +namespace Discord.API.Client.Rest +{ + [JsonObject(MemberSerialization.OptIn)] + public class DeleteGuildRequest : IRestRequest + { + 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; + } + } +} diff --git a/src/Discord.Net/Models/Server.cs b/src/Discord.Net/Models/Server.cs index 2c0e9f288..7db898804 100644 --- a/src/Discord.Net/Models/Server.cs +++ b/src/Discord.Net/Models/Server.cs @@ -208,17 +208,13 @@ namespace Discord /// Leaves this server. This function will fail if you're the owner - use Delete instead. 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) { } } /// Deletes this server. This function will fail if you're not the owner - use Leave instead. 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) { } }