Browse Source

Add user locale & guild locale in interactions (#2040)

tags/3.2.0
Quin Lynch GitHub 3 years ago
parent
commit
2731e20146
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 0 deletions
  1. +13
    -0
      src/Discord.Net.Core/Entities/Interactions/IDiscordInteraction.cs
  2. +6
    -0
      src/Discord.Net.Rest/API/Common/Interaction.cs
  3. +13
    -0
      src/Discord.Net.Rest/Entities/Interactions/RestInteraction.cs
  4. +13
    -0
      src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs

+ 13
- 0
src/Discord.Net.Core/Entities/Interactions/IDiscordInteraction.cs View File

@@ -49,6 +49,19 @@ namespace Discord
/// </summary>
IUser User { get; }

/// <summary>
/// The preferred locale of the invoking User.
/// </summary>
string UserLocale { get; }

/// <summary>
/// The preferred locale of the guild this interaction was executed in. <see cref="null"/> if not executed in a guild.
/// </summary>
/// <remarks>
/// Non-community guilds (With no locale setting available) will have en-US as the default value sent by Discord.
/// </remarks>
string GuildLocale { get; }

/// <summary>
/// Responds to an Interaction with type <see cref="InteractionResponseType.ChannelMessageWithSource"/>.
/// </summary>


+ 6
- 0
src/Discord.Net.Rest/API/Common/Interaction.cs View File

@@ -37,5 +37,11 @@ namespace Discord.API

[JsonProperty("message")]
public Optional<Message> Message { get; set; }

[JsonProperty("locale")]
public Optional<string> UserLocale { get; set; }

[JsonProperty("guild_locale")]
public Optional<string> GuildLocale { get; set; }
}
}

+ 13
- 0
src/Discord.Net.Rest/Entities/Interactions/RestInteraction.cs View File

@@ -32,6 +32,12 @@ namespace Discord.Rest
/// </summary>
public RestUser User { get; private set; }

/// <inheritdoc/>
public string UserLocale { get; private set; }

/// <inheritdoc/>
public string GuildLocale { get; private set; }

/// <inheritdoc/>
public DateTimeOffset CreatedAt { get; private set; }

@@ -126,6 +132,13 @@ namespace Discord.Rest
{
Channel = (IRestMessageChannel)await discord.GetChannelAsync(model.ChannelId.Value);
}

UserLocale = model.UserLocale.IsSpecified
? model.UserLocale.Value
: null;
GuildLocale = model.GuildLocale.IsSpecified
? model.GuildLocale.Value
: null;
}

internal string SerializePayload(object payload)


+ 13
- 0
src/Discord.Net.WebSocket/Entities/Interaction/SocketInteraction.cs View File

@@ -39,6 +39,12 @@ namespace Discord.WebSocket
/// </summary>
public IDiscordInteractionData Data { get; private set; }

/// <inheritdoc/>
public string UserLocale { get; private set; }

/// <inheritdoc/>
public string GuildLocale { get; private set; }

/// <summary>
/// The version of this interaction.
/// </summary>
@@ -121,6 +127,13 @@ namespace Discord.WebSocket
User = SocketGlobalUser.Create(Discord, Discord.State, model.User.Value);
}
}

UserLocale = model.UserLocale.IsSpecified
? model.UserLocale.Value
: null;
GuildLocale = model.GuildLocale.IsSpecified
? model.GuildLocale.Value
: null;
}

/// <summary>


Loading…
Cancel
Save