* Fix #1381 Guild PreferredLocale support Adds support for getting and modifying a guild's preferred_locale. This is a language tag in IETF BCP 47 format, which works with the built-in CultureInfo. While Discord only supports a number of cultures, I think that this restriction should be handled at the API and not by the wrapper. (Also easier on our end) * Add PreferredCulture to IGuild This property was defined in RestGuild and SocketGuild, so it only makes sense to make it part of IGuild as well.
This commit is contained in:
committed by
Christopher F
parent
0bda8a4217
commit
a61adb07e0
@@ -1,3 +1,5 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
/// <summary>
|
||||
@@ -84,5 +86,23 @@ namespace Discord
|
||||
/// are enabled, without the need to manipulate the logic of the flag.
|
||||
/// </remarks>
|
||||
public Optional<SystemChannelMessageDeny> SystemChannelFlags { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the preferred locale of the guild in IETF BCP 47 language tag format.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This property takes precedence over <see cref="PreferredCulture"/>.
|
||||
/// When it is set, the value of <see cref="PreferredCulture"/>
|
||||
/// will not be used.
|
||||
/// </remarks>
|
||||
public Optional<string> PreferredLocale { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the preferred locale of the guild.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The <see cref="PreferredLocale"/> property takes precedence
|
||||
/// over this property. When <see cref="PreferredLocale"/> is set,
|
||||
/// the value of <see cref="PreferredCulture"/> will be unused.
|
||||
/// </remarks>
|
||||
public Optional<CultureInfo> PreferredCulture { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Discord.Audio;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord
|
||||
@@ -249,6 +250,24 @@ namespace Discord
|
||||
/// </returns>
|
||||
int PremiumSubscriptionCount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the preferred locale of this guild in IETF BCP 47
|
||||
/// language tag format.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The preferred locale of the guild in IETF BCP 47
|
||||
/// language tag format.
|
||||
/// </returns>
|
||||
string PreferredLocale { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the preferred culture of this guild.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The preferred culture information of this guild.
|
||||
/// </returns>
|
||||
CultureInfo PreferredCulture { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Modifies this guild.
|
||||
/// </summary>
|
||||
|
||||
@@ -58,5 +58,7 @@ namespace Discord.API
|
||||
public SystemChannelMessageDeny SystemChannelFlags { get; set; }
|
||||
[JsonProperty("premium_subscription_count")]
|
||||
public int? PremiumSubscriptionCount { get; set; }
|
||||
[JsonProperty("preferred_locale")]
|
||||
public string PreferredLocale { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,5 +32,7 @@ namespace Discord.API.Rest
|
||||
public Optional<ExplicitContentFilterLevel> ExplicitContentFilter { get; set; }
|
||||
[JsonProperty("system_channel_flags")]
|
||||
public Optional<SystemChannelMessageDeny> SystemChannelFlags { get; set; }
|
||||
[JsonProperty("preferred_locale")]
|
||||
public string PreferredLocale { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,12 @@ namespace Discord.Rest
|
||||
if (args.SystemChannelFlags.IsSpecified)
|
||||
apiArgs.SystemChannelFlags = args.SystemChannelFlags.Value;
|
||||
|
||||
// PreferredLocale takes precedence over PreferredCulture
|
||||
if (args.PreferredLocale.IsSpecified)
|
||||
apiArgs.PreferredLocale = args.PreferredLocale.Value;
|
||||
else if (args.PreferredCulture.IsSpecified)
|
||||
apiArgs.PreferredLocale = args.PreferredCulture.Value.Name;
|
||||
|
||||
return await client.ApiClient.ModifyGuildAsync(guild.Id, apiArgs, options).ConfigureAwait(false);
|
||||
}
|
||||
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception>
|
||||
|
||||
@@ -3,6 +3,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using EmbedModel = Discord.API.GuildEmbed;
|
||||
@@ -64,6 +65,11 @@ namespace Discord.Rest
|
||||
public string Description { get; private set; }
|
||||
/// <inheritdoc />
|
||||
public int PremiumSubscriptionCount { get; private set; }
|
||||
/// <inheritdoc />
|
||||
public string PreferredLocale { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public CultureInfo PreferredCulture { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
@@ -124,6 +130,8 @@ namespace Discord.Rest
|
||||
SystemChannelFlags = model.SystemChannelFlags;
|
||||
Description = model.Description;
|
||||
PremiumSubscriptionCount = model.PremiumSubscriptionCount.GetValueOrDefault();
|
||||
PreferredLocale = model.PreferredLocale;
|
||||
PreferredCulture = new CultureInfo(PreferredLocale);
|
||||
|
||||
if (model.Emojis != null)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -105,6 +106,11 @@ namespace Discord.WebSocket
|
||||
public string Description { get; private set; }
|
||||
/// <inheritdoc />
|
||||
public int PremiumSubscriptionCount { get; private set; }
|
||||
/// <inheritdoc />
|
||||
public string PreferredLocale { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public CultureInfo PreferredCulture { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
|
||||
@@ -374,6 +380,8 @@ namespace Discord.WebSocket
|
||||
SystemChannelFlags = model.SystemChannelFlags;
|
||||
Description = model.Description;
|
||||
PremiumSubscriptionCount = model.PremiumSubscriptionCount.GetValueOrDefault();
|
||||
PreferredLocale = model.PreferredLocale;
|
||||
PreferredCulture = new CultureInfo(PreferredLocale);
|
||||
|
||||
if (model.Emojis != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user