diff --git a/src/Discord.Net.Commands/Discord.Net.Commands.csproj b/src/Discord.Net.Commands/Discord.Net.Commands.csproj index 183493d29..b0f2a78d0 100644 --- a/src/Discord.Net.Commands/Discord.Net.Commands.csproj +++ b/src/Discord.Net.Commands/Discord.Net.Commands.csproj @@ -25,5 +25,10 @@ + + + Always + + diff --git a/src/Discord.Net.Core/Discord.Net.Core.csproj b/src/Discord.Net.Core/Discord.Net.Core.csproj index 38cc03c8f..c2bceb814 100644 --- a/src/Discord.Net.Core/Discord.Net.Core.csproj +++ b/src/Discord.Net.Core/Discord.Net.Core.csproj @@ -32,4 +32,9 @@ + + + Always + + diff --git a/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataResolved.cs b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataResolved.cs new file mode 100644 index 000000000..fe44fbc79 --- /dev/null +++ b/src/Discord.Net.Rest/API/Common/ApplicationCommandInteractionDataResolved.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace Discord.API +{ + internal class ApplicationCommandInteractionDataResolved + { + [JsonProperty("users")] + public Optional> Users { get; set; } + + [JsonProperty("members")] + public Optional> Members { get; set; } + + [JsonProperty("channels")] + public Optional> Channels { get; set; } + + [JsonProperty("roles")] + public Optional> Roles { get; set; } + } +} diff --git a/src/Discord.Net.Rest/Discord.Net.Rest.csproj b/src/Discord.Net.Rest/Discord.Net.Rest.csproj index 906e0a110..dc3aef2be 100644 --- a/src/Discord.Net.Rest/Discord.Net.Rest.csproj +++ b/src/Discord.Net.Rest/Discord.Net.Rest.csproj @@ -30,4 +30,9 @@ + + + Always + + diff --git a/src/Discord.Net.WebSocket/API/Gateway/ApplicationCommandCreatedUpdatedEvent.cs b/src/Discord.Net.WebSocket/API/Gateway/ApplicationCommandCreatedUpdatedEvent.cs index 94b3470e7..ac6c73c66 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/ApplicationCommandCreatedUpdatedEvent.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/ApplicationCommandCreatedUpdatedEvent.cs @@ -25,6 +25,6 @@ namespace Discord.API.Gateway public ulong GuildId { get; set; } [JsonProperty("options")] - public List Options { get; set; } + public Optional> Options { get; set; } } } diff --git a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj index ebd0dd257..34775254c 100644 --- a/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj +++ b/src/Discord.Net.WebSocket/Discord.Net.WebSocket.csproj @@ -27,4 +27,9 @@ + + + Always + + diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketApplicationCommand.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketApplicationCommand.cs index 3c44fa991..d10932c8c 100644 --- a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketApplicationCommand.cs +++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketApplicationCommand.cs @@ -56,8 +56,8 @@ namespace Discord.WebSocket this.Name = model.Name; this.GuildId = model.GuildId; - this.Options = model.Options.Any() - ? model.Options.Select(x => SocketApplicationCommandOption.Create(x)).ToImmutableArray() + this.Options = model.Options.IsSpecified + ? model.Options.Value.Select(x => SocketApplicationCommandOption.Create(x)).ToImmutableArray() : new ImmutableArray(); } diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandCache.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandCache.cs new file mode 100644 index 000000000..7dd30151d --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketSlashCommandCache.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Discord.WebSocket.Entities.Interaction +{ + internal class SlashCommandCache + { + private readonly ConcurrentDictionary _slashCommands; + private readonly ConcurrentQueue _orderedSlashCommands; + private readonly int _size; + + public IReadOnlyCollection Messages => _slashCommands.ToReadOnlyCollection(); + + public SlashCommandCache(DiscordSocketClient client) + { + _size = 256; + _slashCommands = new ConcurrentDictionary(); + + } + + public void Add(SocketSlashCommand slashCommand) + { + if (_slashCommands.TryAdd(slashCommand.Id, slashCommand)) + { + _orderedSlashCommands.Enqueue(slashCommand.Id); + + while (_orderedSlashCommands.Count > _size && _orderedSlashCommands.TryDequeue(out ulong msgId)) + _slashCommands.TryRemove(msgId, out _); + } + } + + public SocketSlashCommand Remove(ulong id) + { + _slashCommands.TryRemove(id, out var slashCommand); + return slashCommand; + } + + public SocketSlashCommand Get(ulong id) + { + _slashCommands.TryGetValue(id, out var slashCommands); + return slashCommands; + } + } +} diff --git a/src/Discord.Net.Webhook/Discord.Net.Webhook.csproj b/src/Discord.Net.Webhook/Discord.Net.Webhook.csproj index 1e4b096d5..84440b32c 100644 --- a/src/Discord.Net.Webhook/Discord.Net.Webhook.csproj +++ b/src/Discord.Net.Webhook/Discord.Net.Webhook.csproj @@ -25,4 +25,9 @@ + + + Always + +