Skip to content

Commit

Permalink
Merge branch 'main' into rework/cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Nov 30, 2023
2 parents af0f688 + 2368c1c commit 18e3e4c
Show file tree
Hide file tree
Showing 36 changed files with 655 additions and 328 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class ApplicationCommandsConfiguration
/// </summary>
public bool EnableLocalization { internal get; set; } = false;

// TODO: Check if it interferes with callback hints
/// <summary>
/// <para>Automatically defer all responses.</para>
/// <note type="note">If you enable this, you can't use CreateResponse. Use EditResponse instead.</note>
Expand Down
370 changes: 190 additions & 180 deletions DisCatSharp.ApplicationCommands/ApplicationCommandsExtension.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ internal static bool IsEqualTo(
{
sourceApplicationCommand.IntegrationTypes ??= new()
{
ApplicationCommandIntegrationTypes.InstalledToGuild
ApplicationCommandIntegrationTypes.GuildInstall
};
targetApplicationCommand.IntegrationTypes ??= new()
{
ApplicationCommandIntegrationTypes.InstalledToGuild
ApplicationCommandIntegrationTypes.GuildInstall
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ Documentation: https://docs.dcs.aitsys.dev/articles/modules/application_commands
<ProjectReference Include="..\DisCatSharp\DisCatSharp.csproj" />
<ProjectReference Include="..\DisCatSharp.Common\DisCatSharp.Common.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>
</Project>
41 changes: 23 additions & 18 deletions DisCatSharp.ApplicationCommands/Workers/RegistrationWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ internal static async Task<List<DiscordApplicationCommand>> RegisterGlobalComman
action.NameLocalizations = command.NameLocalizations;
action.Description = command.Description;
action.DescriptionLocalizations = command.DescriptionLocalizations;
if(command.Options != null && command.Options.Any())
if (command.Options != null && command.Options.Any())
action.Options = Optional.Some(command.Options);
action.DefaultMemberPermissions = command.DefaultMemberPermissions;
action.DmPermission = command.DmPermission ?? true;
action.IsNsfw = command.IsNsfw;
action.AllowedContexts = command.AllowedContexts;
action.IntegrationTypes = command.IntegrationTypes;
}).ConfigureAwait(false);

commands.Add(discordBackendCommand);
Expand Down Expand Up @@ -80,12 +81,13 @@ internal static async Task<List<DiscordApplicationCommand>> RegisterGlobalComman
action.NameLocalizations = command.NameLocalizations;
action.Description = command.Description;
action.DescriptionLocalizations = command.DescriptionLocalizations;
if(command.Options != null && command.Options.Any())
if (command.Options != null && command.Options.Any())
action.Options = Optional.Some(command.Options);
action.DefaultMemberPermissions = command.DefaultMemberPermissions;
action.DmPermission = command.DmPermission ?? true;
action.IsNsfw = command.IsNsfw;
action.AllowedContexts = command.AllowedContexts;
action.AllowedContexts = command.AllowedContexts;
action.IntegrationTypes = command.IntegrationTypes;
}).ConfigureAwait(false);

commands.Add(discordBackendCommand);
Expand All @@ -107,12 +109,13 @@ internal static async Task<List<DiscordApplicationCommand>> RegisterGlobalComman
action.NameLocalizations = command.NameLocalizations;
action.Description = command.Description;
action.DescriptionLocalizations = command.DescriptionLocalizations;
if(command.Options != null && command.Options.Any())
if (command.Options != null && command.Options.Any())
action.Options = Optional.Some(command.Options);
action.DefaultMemberPermissions = command.DefaultMemberPermissions;
action.DmPermission = command.DmPermission ?? true;
action.IsNsfw = command.IsNsfw;
action.AllowedContexts = command.AllowedContexts;
action.IntegrationTypes = command.IntegrationTypes;
}).ConfigureAwait(false);

commands.Add(discordBackendCommand);
Expand All @@ -131,6 +134,7 @@ internal static async Task<List<DiscordApplicationCommand>> RegisterGlobalComman
cmd.Id = overwrite.Key;
overwriteList.Add(cmd);
}

var discordBackendCommands = await client.BulkOverwriteGlobalApplicationCommandsAsync(overwriteList).ConfigureAwait(false);
commands.AddRange(discordBackendCommands);
}
Expand Down Expand Up @@ -198,12 +202,13 @@ internal static async Task<List<DiscordApplicationCommand>> RegisterGuildCommand
action.NameLocalizations = command.NameLocalizations;
action.Description = command.Description;
action.DescriptionLocalizations = command.DescriptionLocalizations;
if(command.Options != null && command.Options.Any())
if (command.Options != null && command.Options.Any())
action.Options = Optional.Some(command.Options);
action.DefaultMemberPermissions = command.DefaultMemberPermissions;
action.DmPermission = command.DmPermission ?? true;
action.IsNsfw = command.IsNsfw;
action.AllowedContexts = command.AllowedContexts;
action.IntegrationTypes = command.IntegrationTypes;
}).ConfigureAwait(false);

commands.Add(discordBackendCommand);
Expand Down Expand Up @@ -231,12 +236,13 @@ internal static async Task<List<DiscordApplicationCommand>> RegisterGuildCommand
action.NameLocalizations = command.NameLocalizations;
action.Description = command.Description;
action.DescriptionLocalizations = command.DescriptionLocalizations;
if(command.Options != null && command.Options.Any())
if (command.Options != null && command.Options.Any())
action.Options = Optional.Some(command.Options);
action.DefaultMemberPermissions = command.DefaultMemberPermissions;
action.DmPermission = command.DmPermission ?? true;
action.IsNsfw = command.IsNsfw;
action.AllowedContexts = command.AllowedContexts;
action.IntegrationTypes = command.IntegrationTypes;
}).ConfigureAwait(false);

commands.Add(discordBackendCommand);
Expand All @@ -258,14 +264,15 @@ internal static async Task<List<DiscordApplicationCommand>> RegisterGuildCommand
action.NameLocalizations = command.NameLocalizations;
action.Description = command.Description;
action.DescriptionLocalizations = command.DescriptionLocalizations;
if(command.Options != null && command.Options.Any())
if (command.Options != null && command.Options.Any())
action.Options = Optional.Some(command.Options);
if (command.DefaultMemberPermissions.HasValue)
action.DefaultMemberPermissions = command.DefaultMemberPermissions.Value;
if (command.DmPermission.HasValue)
action.DmPermission = command.DmPermission.Value;
action.IsNsfw = command.IsNsfw;
action.AllowedContexts = command.AllowedContexts;
action.IntegrationTypes = command.IntegrationTypes;
}).ConfigureAwait(false);

commands.Add(discordBackendCommand);
Expand All @@ -284,6 +291,7 @@ internal static async Task<List<DiscordApplicationCommand>> RegisterGuildCommand
cmd.Id = overwrite.Key;
overwriteList.Add(cmd);
}

var discordBackendCommands = await client.BulkOverwriteGuildApplicationCommandsAsync(guildId, overwriteList).ConfigureAwait(false);
commands.AddRange(discordBackendCommands);
}
Expand Down Expand Up @@ -327,9 +335,8 @@ internal static async Task<List<DiscordApplicationCommand>> RegisterGuildCommand
/// <returns>A list of command ids.</returns>
private static List<ulong> BuildGuildDeleteList(DiscordClient client, ulong guildId, List<DiscordApplicationCommand> updateList)
{

if (ApplicationCommandsExtension.GuildDiscordCommands == null || !ApplicationCommandsExtension.GuildDiscordCommands.Any()
|| !ApplicationCommandsExtension.GuildDiscordCommands.TryGetFirstValueByKey(guildId, out var discord)
|| !ApplicationCommandsExtension.GuildDiscordCommands.TryGetFirstValueByKey(guildId, out var discord)
)
return null;

Expand Down Expand Up @@ -358,9 +365,8 @@ private static List<ulong> BuildGuildDeleteList(DiscordClient client, ulong guil
/// <returns></returns>
private static List<DiscordApplicationCommand> BuildGuildCreateList(DiscordClient client, ulong guildId, List<DiscordApplicationCommand> updateList)
{

if (ApplicationCommandsExtension.GuildDiscordCommands == null || !ApplicationCommandsExtension.GuildDiscordCommands.Any()
|| updateList == null || !ApplicationCommandsExtension.GuildDiscordCommands.TryGetFirstValueByKey(guildId, out var discord)
|| updateList == null || !ApplicationCommandsExtension.GuildDiscordCommands.TryGetFirstValueByKey(guildId, out var discord)
)
return updateList;

Expand All @@ -384,14 +390,13 @@ private static List<DiscordApplicationCommand> BuildGuildCreateList(DiscordClien
/// <param name="updateList">The command list.</param>
/// <returns>A dictionary of command id and command.</returns>
private static (
Dictionary<ulong, DiscordApplicationCommand> changedCommands,
List<DiscordApplicationCommand> unchangedCommands
Dictionary<ulong, DiscordApplicationCommand> changedCommands,
List<DiscordApplicationCommand> unchangedCommands
) BuildGuildOverwriteList(DiscordClient client, ulong guildId, List<DiscordApplicationCommand> updateList)
{

if (ApplicationCommandsExtension.GuildDiscordCommands == null || !ApplicationCommandsExtension.GuildDiscordCommands.Any()
|| ApplicationCommandsExtension.GuildDiscordCommands.All(l => l.Key != guildId) || updateList == null
|| !ApplicationCommandsExtension.GuildDiscordCommands.TryGetFirstValueByKey(guildId, out var discord)
|| ApplicationCommandsExtension.GuildDiscordCommands.All(l => l.Key != guildId) || updateList == null
|| !ApplicationCommandsExtension.GuildDiscordCommands.TryGetFirstValueByKey(guildId, out var discord)
)
return (null, null);

Expand Down Expand Up @@ -483,8 +488,8 @@ private static List<DiscordApplicationCommand> BuildGlobalCreateList(DiscordClie
/// <param name="updateList">The command list.</param>
/// <returns>A dictionary of command ids and commands.</returns>
private static (
Dictionary<ulong, DiscordApplicationCommand> changedCommands,
List<DiscordApplicationCommand> unchangedCommands
Dictionary<ulong, DiscordApplicationCommand> changedCommands,
List<DiscordApplicationCommand> unchangedCommands
) BuildGlobalOverwriteList(DiscordClient client, List<DiscordApplicationCommand> updateList)
{
if (ApplicationCommandsExtension.GlobalDiscordCommands == null || !ApplicationCommandsExtension.GlobalDiscordCommands.Any() || updateList == null)
Expand Down
4 changes: 4 additions & 0 deletions DisCatSharp.Attributes/DisCatSharp.Attributes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@
</Description>
<PackageTags>DisCatSharp</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions DisCatSharp.CommandsNext/DisCatSharp.CommandsNext.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ Documentation: https://docs.dcs.aitsys.dev/articles/modules/commandsnext/intro.h
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions DisCatSharp.Common/DisCatSharp.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ Common tools for DisCatSharp, like regexes and converters!
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions DisCatSharp.Configuration/DisCatSharp.Configuration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@
<ProjectReference Include="..\DisCatSharp\DisCatSharp.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions DisCatSharp.Experimental/DisCatSharp.Experimental.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@
<ProjectReference Include="..\DisCatSharp\DisCatSharp.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@
<ProjectReference Include="..\DisCatSharp.Hosting\DisCatSharp.Hosting.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions DisCatSharp.Hosting/DisCatSharp.Hosting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions DisCatSharp.Interactivity/DisCatSharp.Interactivity.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ Documentation: https://docs.dcs.aitsys.dev/articles/modules/interactivity.html
<ProjectReference Include="..\DisCatSharp\DisCatSharp.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions DisCatSharp.Lavalink/DisCatSharp.Lavalink.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions DisCatSharp.Targets/NuGet.targets
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' != 'true' And '$(TF_BUILD)' != 'true' And '$(CI)' != 'True'">
<ContinuousIntegrationBuild>false</ContinuousIntegrationBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release' And '$(GITHUB_ACTIONS)' == 'true' And '$(SENTRY_AUTH_TOKEN)' != ''">
<SentryOrg>aitsys</SentryOrg>
<SentryProject>discatsharp</SentryProject>
<SentryUploadSymbols>true</SentryUploadSymbols>
<SentryUploadSources>true</SentryUploadSources>
<UseSentryCLI>true</UseSentryCLI>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions DisCatSharp.Tests/SafetyTests/DisCatSharp.SafetyTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.7.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.8.0" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<ItemGroup>
<ProjectReference Include="..\DisCatSharp.Analyzer\DisCatSharp.Analyzer.csproj" />
<PackageReference Include="DisCatSharp.Attributes" Version="10.4.3" PrivateAssets="all" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.7.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" PrivateAssets="all" />
<PackageReference Update="NETStandard.Library" PrivateAssets="all" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.7.37357" />
</ItemGroup>

Expand Down
4 changes: 4 additions & 0 deletions DisCatSharp.VoiceNext/DisCatSharp.VoiceNext.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ Documentation: https://docs.dcs.aitsys.dev/articles/modules/audio/voicenext/prer
<ProjectReference Include="..\DisCatSharp.VoiceNext.Natives\DisCatSharp.VoiceNext.Natives.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion DisCatSharp/Clients/DiscordClient.Dispatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3404,7 +3404,8 @@ internal async Task OnInteractionCreateAsync(ulong? guildId, ulong channelId, Tr
if (member != null)
{
usr = new DiscordMember(member) { GuildId = guildId.Value, Discord = this };
this.UpdateUser(usr, guildId, interaction.Guild, member);
if (interaction.Guild is not null)
this.UpdateUser(usr, guildId, interaction.Guild, member);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions DisCatSharp/Clients/DiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ public Uri GetInAppOAuth(Permissions permissions = Permissions.None, OAuthScopes
.AddParameter("permissions", ((long)permissions).ToString(CultureInfo.InvariantCulture))
.AddParameter("state", state ?? string.Empty)
.AddParameter("redirect_uri", redir ?? string.Empty)
.AddParameter("user_install", user_install.ToString(CultureInfo.InvariantCulture))
.AddParameter("integration_type", user_install ? "1" : "0")
.AddParameter("guild_id", guild_id.HasValue ? guild_id.Value.ToString(CultureInfo.InvariantCulture) : string.Empty)
.AddParameter("access_type", access_type ?? string.Empty)
.AddParameter("response_type", response_type ?? string.Empty)
Expand Down Expand Up @@ -999,7 +999,7 @@ public Uri GenerateInAppOauthFor(DiscordUser bot, Permissions permissions = Perm
.AddParameter("permissions", ((long)permissions).ToString(CultureInfo.InvariantCulture))
.AddParameter("state", state ?? string.Empty)
.AddParameter("redirect_uri", redir ?? string.Empty)
.AddParameter("user_install", user_install.ToString(CultureInfo.InvariantCulture))
.AddParameter("integration_type", user_install ? "1" : "0")
.AddParameter("guild_id", guild_id.HasValue ? guild_id.Value.ToString(CultureInfo.InvariantCulture) : string.Empty)
.AddParameter("access_type", access_type ?? string.Empty)
.AddParameter("response_type", response_type ?? string.Empty)
Expand Down
8 changes: 6 additions & 2 deletions DisCatSharp/DisCatSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Written with love and for everyone.
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Sentry" Version="3.41.0" />
<PackageReference Include="Sentry.Extensions.Logging" Version="3.41.0" />
<PackageReference Include="Sentry" Version="3.41.3" />
<PackageReference Include="Sentry.Extensions.Logging" Version="3.41.3" />
<PackageReference Include="System.Memory" Version="4.5.5" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Net.WebSockets" Version="4.3.0" />
Expand All @@ -55,4 +55,8 @@ Written with love and for everyone.
<Folder Include="Entities\Interaction\Components\DateTime\" />
<Folder Include="Entities\Interaction\Components\Radio\" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>
</Project>
Loading

0 comments on commit 18e3e4c

Please sign in to comment.