Browse Source

Added IGuild.IsOwner, cleaned a few exceptions

tags/1.0-rc
RogueException 9 years ago
parent
commit
4bc37d8c33
3 changed files with 10 additions and 2 deletions
  1. +2
    -0
      src/Discord.Net/Common/Entities/Guilds/IGuild.cs
  2. +6
    -0
      src/Discord.Net/Rest/Entities/Guilds/Guild.cs
  3. +2
    -2
      src/Discord.Net/Rest/Entities/Guilds/UserGuild.cs

+ 2
- 0
src/Discord.Net/Common/Entities/Guilds/IGuild.cs View File

@@ -11,6 +11,8 @@ namespace Discord
int AFKTimeout { get; }
/// <summary> Returns true if this guild is embeddable (e.g. widget) </summary>
bool IsEmbeddable { get; }
/// <summary> Returns true if the current user owns this guild. </summary>
bool IsOwner { get; }
/// <summary> Gets the name of this guild. </summary>
string Name { get; }
int VerificationLevel { get; }


+ 6
- 0
src/Discord.Net/Rest/Entities/Guilds/Guild.cs View File

@@ -46,6 +46,8 @@ namespace Discord.Rest
/// <inheritdoc />
public DateTime CreatedAt => DateTimeHelper.FromSnowflake(Id);
/// <inheritdoc />
public bool IsOwner => OwnerId == Discord.CurrentUser.Id;
/// <inheritdoc />
public string IconUrl => API.CDN.GetGuildIconUrl(Id, _iconId);
/// <inheritdoc />
public string SplashUrl => API.CDN.GetGuildSplashUrl(Id, _splashId);
@@ -155,11 +157,15 @@ namespace Discord.Rest
/// <inheritdoc />
public async Task Leave()
{
if (IsOwner)
throw new InvalidOperationException("Unable to leave a guild the current user owns.");
await Discord.BaseClient.LeaveGuild(Id).ConfigureAwait(false);
}
/// <inheritdoc />
public async Task Delete()
{
if (!IsOwner)
throw new InvalidOperationException("Unable to delete a guild the current user does not own.");
await Discord.BaseClient.DeleteGuild(Id).ConfigureAwait(false);
}



+ 2
- 2
src/Discord.Net/Rest/Entities/Guilds/UserGuild.cs View File

@@ -41,14 +41,14 @@ namespace Discord.Rest
public async Task Leave()
{
if (IsOwner)
throw new InvalidOperationException("Unable to leave a guild the current user owns, use Delete() instead.");
throw new InvalidOperationException("Unable to leave a guild the current user owns.");
await Discord.BaseClient.LeaveGuild(Id).ConfigureAwait(false);
}
/// <inheritdoc />
public async Task Delete()
{
if (!IsOwner)
throw new InvalidOperationException("Unable to leave a guild the current user owns, use Delete() instead.");
throw new InvalidOperationException("Unable to delete a guild the current user does not own.");
await Discord.BaseClient.DeleteGuild(Id).ConfigureAwait(false);
}



Loading…
Cancel
Save