Added IGuild.IsOwner, cleaned a few exceptions

This commit is contained in:
RogueException
2016-05-12 10:57:29 -03:00
parent 227c8f3e60
commit 4bc37d8c33
3 changed files with 10 additions and 2 deletions

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; }

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);
}

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);
}