Browse Source

Added DeleteGuildRequest

tags/docs-0.9
RogueException 9 years ago
parent
commit
433ead6f3f
3 changed files with 24 additions and 5 deletions
  1. +3
    -0
      src/Discord.Net.Net45/Discord.Net.csproj
  2. +20
    -0
      src/Discord.Net/API/Client/Rest/DeleteGuild.cs
  3. +1
    -5
      src/Discord.Net/Models/Server.cs

+ 3
- 0
src/Discord.Net.Net45/Discord.Net.csproj View File

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


+ 20
- 0
src/Discord.Net/API/Client/Rest/DeleteGuild.cs 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;
}
}
}

+ 1
- 5
src/Discord.Net/Models/Server.cs 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> /// <summary> Leaves this server. This function will fail if you're the owner - use Delete instead. </summary>
public async Task Leave() 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); } try { await Client.ClientAPI.Send(new LeaveGuildRequest(Id)).ConfigureAwait(false); }
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { } 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> /// <summary> Deletes this server. This function will fail if you're not the owner - use Leave instead. </summary>
public async Task Delete() 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) { } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
} }




Loading…
Cancel
Save