Skip to content

Commit

Permalink
Merge pull request #108 from Aiko-IT-Systems/release/3_1_0
Browse files Browse the repository at this point in the history
DisCatSharp.Extensions v3.1.0 Release
  • Loading branch information
Lulalaby authored Jan 26, 2025
2 parents 007dd93 + fed02c7 commit 5bbe108
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 189 deletions.
23 changes: 7 additions & 16 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,27 @@ It is recommended you have prior experience with multi-target .NET Core/Standard
In order to build the library, you will first need to install some software.

### Windows
On Windows, we only officially support Visual Studio 2019 16.10 or newer. Visual Studio Code and other IDEs might work, but are generally not supported or even guaranteed to work properly.
On Windows, we only officially support Visual Studio 2022 17.0 or newer. Visual Studio Code and other IDEs might work, but are generally not supported or even guaranteed to work properly.

* **Windows 10** - while we support running the library on Windows 7 and above, we only support building on Windows 10 and better.
* [**Git for Windows**](https://git-scm.com/download/win) - required to clone the repository.
* [**Visual Studio 2021**](https://www.visualstudio.com/downloads/) - community edition or better. We do not support Visual Studio 2017 and older. Note that to build the library, you need Visual Studio 2019 version 16.10 or newer.
* **Workloads**:
* **.NET Framework Desktop** - required to build .NETFX (4.5, 4.6, and 4.7 targets)
* **.NET Core Cross-Platform Development** - required to build .NET Standard targets (1.1, 1.3, and 2.0) and the project overall.
* **Individual Components**:
* **.NET Framework 4.5 SDK** - required for .NETFX 4.5 target
* **.NET Framework 4.6 SDK** - required for .NETFX 4.6 target
* **.NET Framework 4.7 SDK** - required for .NETFX 4.7 target
* [**.NET Core SDK 3.1**](https://www.microsoft.com/net/download) - required to build the project.
* [**Visual Studio 2022**](https://www.visualstudio.com/downloads/) - community edition or better. We do not support Visual Studio 2021 and older.
* **Windows PowerShell** - required to run the build scripts. You need to make sure your script execution policy allows execution of unsigned scripts.
* [**.NET SDK 8.0 or newer**](https://www.microsoft.com/net/download) - required to build the project.

### GNU/Linux
On GNU/Linux, we support building via Visual Studio Code and .NET Core SDK. Other IDEs might work, but are not supported or guaranteed to work properly.

While these should apply to any modern distribution, we only test against Debian 10. Your mileage may vary.
While these should apply to any modern distribution, we only test against Ubuntu 24.04. Your mileage may vary.

When installing the below, make sure you install all the dependencies properly. We might ship a build environment as a docker container in the future.

* **Any modern GNU/Linux distribution** - like Debian 10.
* **Any modern GNU/Linux distribution** - like Ubuntu 24.04.
* **Git** - to clone the repository.
* [**Visual Studio Code**](https://code.visualstudio.com/Download) - a recent version is required.
* **C# for Visual Studio Code (powered by OmniSharp)** - required for syntax highlighting and basic Intellisense
* [**.NET SDK 6.0**](https://www.microsoft.com/net/download) - required to build the project.
* [**Mono 5.x**](http://www.mono-project.com/download/#download-lin) - required to build the .NETFX 4.5, 4.6, and 4.7 targets, as well as to build the docs.
* [**PowerShell Core**](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7.1) - required to execute the build scripts.
* **p7zip-full** - required to package docs.
* [**.NET SDK 8.0 or newer**](https://www.microsoft.com/net/download) - required to build the project.
* [**PowerShell Core**](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7.5) - required to execute the build scripts.

## Instructions
Once you install all the necessary prerequisites, you can proceed to building. These instructions assume you have already cloned the repository.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<ItemGroup>
<PackageReference Include="Backport.System.Threading.Lock" Version="3.1.4" />
<PackageReference Include="ConcurrentHashSet" Version="1.3.0" />
<PackageReference Include="DisCatSharp" Version="10.6.6-nightly-031" />
<PackageReference Include="DisCatSharp" Version="10.6.6" />
<PackageReference Include="DisCatSharp.Analyzer.Roselyn" Version="6.2.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DisCatSharp" Version="10.6.6-nightly-031" />
<PackageReference Include="DisCatSharp" Version="10.6.6" />
<PackageReference Include="DisCatSharp.Analyzer.Roselyn" Version="6.2.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.1" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="9.0.1" />
<PackageReference Include="DisCatSharp.ApplicationCommands" Version="10.6.6-nightly-031" />
<PackageReference Include="DisCatSharp.ApplicationCommands" Version="10.6.6" />
<PackageReference Include="DisCatSharp.Attributes" Version="10.6.*" />
<PackageReference Include="DisCatSharp.Lavalink" Version="10.6.6-nightly-031" />
<PackageReference Include="DisCatSharp.Common" Version="10.6.6-nightly-031" />
<PackageReference Include="DisCatSharp.Lavalink" Version="10.6.6" />
<PackageReference Include="DisCatSharp.Common" Version="10.6.6" />
<PackageReference Include="Microsoft.DependencyValidation.Analyzers" Version="0.11.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.1" />
Expand Down
14 changes: 7 additions & 7 deletions DisCatSharp.Extensions.SimpleMusicCommands/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
namespace DisCatSharp.Extensions.SimpleMusicCommands;

/// <summary>
/// Defines various extensions specific to SimpleMusicCommandsExtension.
/// Defines various extensions specific to SimpleMusicCommandsExtension.
/// </summary>
public static class ExtensionMethods
{
/// <summary>
/// Enables SimpleMusicCommandsExtension module on this <see cref="DiscordClient"/>.
/// Enables SimpleMusicCommandsExtension module on this <see cref="DiscordClient" />.
/// </summary>
/// <param name="client">Client to enable SimpleMusicCommandsExtension for.</param>
/// <param name="cfg">Lavalink configuration to use.</param>
/// <returns>Created <see cref="SimpleMusicCommandsExtension"/>.</returns>
/// <returns>Created <see cref="SimpleMusicCommandsExtension" />.</returns>
public static SimpleMusicCommandsExtension UseSimpleMusicCommands(this DiscordClient client, LavalinkConfiguration? cfg = null)
{
if (client.GetExtension<SimpleMusicCommandsExtension>() != null)
Expand All @@ -55,11 +55,11 @@ public static SimpleMusicCommandsExtension UseSimpleMusicCommands(this DiscordCl
}

/// <summary>
/// Enables SimpleMusicCommandsExtension module on all shards in this <see cref="DiscordShardedClient"/>.
/// Enables SimpleMusicCommandsExtension module on all shards in this <see cref="DiscordShardedClient" />.
/// </summary>
/// <param name="client">Client to enable SimpleMusicCommandsExtension for.</param>
/// <param name="cfg">Lavalink configuration to use.</param>
/// <returns>A dictionary of created <see cref="SimpleMusicCommandsExtension"/>, indexed by shard id.</returns>
/// <returns>A dictionary of created <see cref="SimpleMusicCommandsExtension" />, indexed by shard id.</returns>
public static async Task<IReadOnlyDictionary<int, SimpleMusicCommandsExtension>> UseSimpleMusicCommandsAsync(this DiscordShardedClient client, LavalinkConfiguration? cfg = null)
{
var modules = new Dictionary<int, SimpleMusicCommandsExtension>();
Expand All @@ -77,15 +77,15 @@ public static async Task<IReadOnlyDictionary<int, SimpleMusicCommandsExtension>>
}

/// <summary>
/// Gets the active SimpleMusicCommandsExtension module for this client.
/// Gets the active SimpleMusicCommandsExtension module for this client.
/// </summary>
/// <param name="client">Client to get SimpleMusicCommandsExtension module from.</param>
/// <returns>The module, or null if not activated.</returns>
public static SimpleMusicCommandsExtension? GetSimpleMusicCommandsExtension(this DiscordClient client)
=> client.GetExtension<SimpleMusicCommandsExtension>();

/// <summary>
/// Gets the active SimpleMusicCommandsExtension modules for all shards in this client.
/// Gets the active SimpleMusicCommandsExtension modules for all shards in this client.
/// </summary>
/// <param name="client">Client to get SimpleMusicCommandsExtension instances from.</param>
/// <returns>A dictionary of the modules, indexed by shard id.</returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
<ItemGroup>
<PackageReference Include="Backport.System.Threading.Lock" Version="3.1.4" />
<PackageReference Include="DatabaseWrapper.Sqlite" Version="6.1.4" />
<PackageReference Include="DisCatSharp" Version="10.6.6-nightly-031" />
<PackageReference Include="DisCatSharp" Version="10.6.6" />
<PackageReference Include="DisCatSharp.Analyzer.Roselyn" Version="6.2.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="DisCatSharp.ApplicationCommands" Version="10.6.6-nightly-031" />
<PackageReference Include="DisCatSharp.ApplicationCommands" Version="10.6.6" />
<PackageReference Include="DisCatSharp.Attributes" Version="10.6.*" />
<PackageReference Include="DisCatSharp.CommandsNext" Version="10.6.6-nightly-031" />
<PackageReference Include="DisCatSharp.Common" Version="10.6.6-nightly-031" />
<PackageReference Include="DisCatSharp.Interactivity" Version="10.6.6-nightly-031" />
<PackageReference Include="DisCatSharp.CommandsNext" Version="10.6.6" />
<PackageReference Include="DisCatSharp.Common" Version="10.6.6" />
<PackageReference Include="DisCatSharp.Interactivity" Version="10.6.6" />
<PackageReference Include="Microsoft.DependencyValidation.Analyzers" Version="0.11.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,32 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using DisCatSharp.Entities;
using DisCatSharp.EventArgs;
using DisCatSharp.Extensions.TwoFactorCommands.Enums;

namespace DisCatSharp.Extensions.TwoFactorCommands.Entities;

/// <summary>
/// The response given upon attempted two factor authentication.
/// The response given upon attempted two factor authentication.
/// </summary>
public class TwoFactorResponse
{
internal TwoFactorResponse()
{ }

/// <summary>
/// The modal response <see cref="ComponentInteractionCreateEventArgs"/>. Null if <see cref="Result"/> is <see cref="TwoFactorResult.NotEnrolled"/> or <see cref="TwoFactorResult.TimedOut"/>.
/// The modal response <see cref="ComponentInteractionCreateEventArgs" />. Null if <see cref="Result" /> is
/// <see cref="TwoFactorResult.NotEnrolled" /> or <see cref="TwoFactorResult.TimedOut" />.
/// </summary>
public ComponentInteractionCreateEventArgs ComponentInteraction { get; internal set; } = null;

Check warning on line 40 in DisCatSharp.Extensions.TwoFactorCommands/Entities/TwoFactorResponse.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Cannot convert null literal to non-nullable reference type.

Check warning on line 40 in DisCatSharp.Extensions.TwoFactorCommands/Entities/TwoFactorResponse.cs

View workflow job for this annotation

GitHub Actions / Build library and release

Cannot convert null literal to non-nullable reference type.

/// <summary>
/// The <see cref="DiscordClient"/> this interaction took place with.
/// The <see cref="DiscordClient" /> this interaction took place with.
/// </summary>
public DiscordClient Client { get; internal set; } = null;

Check warning on line 45 in DisCatSharp.Extensions.TwoFactorCommands/Entities/TwoFactorResponse.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Cannot convert null literal to non-nullable reference type.

Check warning on line 45 in DisCatSharp.Extensions.TwoFactorCommands/Entities/TwoFactorResponse.cs

View workflow job for this annotation

GitHub Actions / Build library and release

Cannot convert null literal to non-nullable reference type.

/// <summary>
/// The <see cref="TwoFactorResult"/> of the two factor authentication.
/// The <see cref="TwoFactorResult" /> of the two factor authentication.
/// </summary>
public TwoFactorResult Result { get; internal set; } = TwoFactorResult.TimedOut;

internal TwoFactorResponse()
{ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@
namespace DisCatSharp.Extensions.TwoFactorCommands.Enums;

/// <summary>
/// Represents two factor responses.
/// Represents two factor responses.
/// </summary>
public enum TwoFactorResult : int
public enum TwoFactorResult
{
/// <summary>
/// Code is invalid.
/// Code is invalid.
/// </summary>
InvalidCode = 1,

/// <summary>
/// Code is valid.
/// Code is valid.
/// </summary>
ValidCode = 2,

/// <summary>
/// User is not enrolled.
/// User is not enrolled.
/// </summary>
NotEnrolled = 3,

/// <summary>
/// Two factor input timed out.
/// Two factor input timed out.
/// </summary>
TimedOut = 4,

/// <summary>
/// This function is not implemented.
/// This function is not implemented.
/// </summary>
NotImplemented = int.MaxValue
}
14 changes: 7 additions & 7 deletions DisCatSharp.Extensions.TwoFactorCommands/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
namespace DisCatSharp.Extensions.TwoFactorCommands;

/// <summary>
/// Defines various extensions specific to TwoFactor.
/// Defines various extensions specific to TwoFactor.
/// </summary>
public static class ExtensionMethods
{
/// <summary>
/// Enables TwoFactor module on this <see cref="DiscordClient"/>.
/// Enables TwoFactor module on this <see cref="DiscordClient" />.
/// </summary>
/// <param name="client">Client to enable TwoFactor for.</param>
/// <param name="cfg">TwoFactor configuration to use.</param>
/// <returns>Created <see cref="TwoFactorExtension"/>.</returns>
/// <returns>Created <see cref="TwoFactorExtension" />.</returns>
public static TwoFactorExtension UseTwoFactor(this DiscordClient client, TwoFactorConfiguration? cfg = null)
{
if (client.GetExtension<TwoFactorExtension>() != null)
Expand All @@ -55,11 +55,11 @@ public static TwoFactorExtension UseTwoFactor(this DiscordClient client, TwoFact
}

/// <summary>
/// Enables TwoFactor module on all shards in this <see cref="DiscordShardedClient"/>.
/// Enables TwoFactor module on all shards in this <see cref="DiscordShardedClient" />.
/// </summary>
/// <param name="client">Client to enable TwoFactor for.</param>
/// <param name="cfg">TwoFactor configuration to use.</param>
/// <returns>A dictionary of created <see cref="TwoFactorExtension"/>, indexed by shard id.</returns>
/// <returns>A dictionary of created <see cref="TwoFactorExtension" />, indexed by shard id.</returns>
public static async Task<IReadOnlyDictionary<int, TwoFactorExtension>> UseTwoFactorAsync(this DiscordShardedClient client, TwoFactorConfiguration? cfg = null)
{
var modules = new Dictionary<int, TwoFactorExtension>();
Expand All @@ -77,15 +77,15 @@ public static async Task<IReadOnlyDictionary<int, TwoFactorExtension>> UseTwoFac
}

/// <summary>
/// Gets the active TwoFactor module for this client.
/// Gets the active TwoFactor module for this client.
/// </summary>
/// <param name="client">Client to get TwoFactor module from.</param>
/// <returns>The module, or null if not activated.</returns>
public static TwoFactorExtension? GetTwoFactor(this DiscordClient client)
=> client.GetExtension<TwoFactorExtension>();

/// <summary>
/// Gets the active TwoFactor modules for all shards in this client.
/// Gets the active TwoFactor modules for all shards in this client.
/// </summary>
/// <param name="client">Client to get TwoFactor instances from.</param>
/// <returns>A dictionary of the modules, indexed by shard id.</returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@
namespace DisCatSharp.ApplicationCommands.Attributes;

/// <summary>
/// Defines that this application command can only be executed if the user is enrolled in two factor auth.
/// Defines that this application command can only be executed if the user is enrolled in two factor auth.
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)]
public sealed class ApplicationCommandRequireEnrolledTwoFactorAttribute : ApplicationCommandCheckBaseAttribute
{
/// <summary>
/// Defines that this application command can only be executed if the user is enrolled in two factor auth.
/// Defines that this application command can only be executed if the user is enrolled in two factor auth.
/// </summary>
public ApplicationCommandRequireEnrolledTwoFactorAttribute()
{ }

/// <summary>
/// Runs checks.
/// Runs checks.
/// </summary>
public override Task<bool> ExecuteChecksAsync(BaseContext ctx)
=> Task.FromResult(ctx.Client.GetTwoFactor().IsEnrolled(ctx.User.Id));

Check warning on line 47 in DisCatSharp.Extensions.TwoFactorCommands/Extensions/ApplicationCommands/ApplicationCommandRequireEnrolledTwoFactorAttribute.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.

Check warning on line 47 in DisCatSharp.Extensions.TwoFactorCommands/Extensions/ApplicationCommands/ApplicationCommandRequireEnrolledTwoFactorAttribute.cs

View workflow job for this annotation

GitHub Actions / Build library and release

Dereference of a possibly null reference.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@
using DisCatSharp.Entities;
using DisCatSharp.Enums;
using DisCatSharp.EventArgs;
using DisCatSharp.Extensions.TwoFactorCommands.Enums;
using DisCatSharp.Extensions.TwoFactorCommands.Entities;
using DisCatSharp.Extensions.TwoFactorCommands.Enums;
using DisCatSharp.Interactivity.Extensions;

namespace DisCatSharp.Extensions.TwoFactorCommands.ApplicationCommands;

public static class TwoFactorApplicationCommandExtension
{
/// <summary>
/// <para>Asks the user via modal input for the two factor code.</para>
/// <para>This uses DisCatSharp.Interactivity.</para>
/// <para>To be used as first action for application commands.</para>
/// <para>Asks the user via modal input for the two factor code.</para>
/// <para>This uses DisCatSharp.Interactivity.</para>
/// <para>To be used as first action for application commands.</para>
/// </summary>
/// <param name="ctx">The base context.</param>
/// <returns>A <see cref="TwoFactorResponse"/>.</returns>
/// <returns>A <see cref="TwoFactorResponse" />.</returns>
public static async Task<TwoFactorResponse> RequestTwoFactorAsync(this BaseContext ctx)
{
var ext = ctx.Client.GetTwoFactor();
Expand All @@ -62,7 +62,7 @@ public static async Task<TwoFactorResponse> RequestTwoFactorAsync(this BaseConte
builder.AddTextComponent(new(TextComponentStyle.Small, "code", "Code", "123456", ext.Configuration.Digits, ext.Configuration.Digits));
await ctx.CreateModalResponseAsync(builder);

var response = new TwoFactorResponse()
var response = new TwoFactorResponse
{
Client = ctx.Client
};
Expand Down Expand Up @@ -99,13 +99,13 @@ public static async Task<TwoFactorResponse> RequestTwoFactorAsync(this BaseConte
}

/// <summary>
/// <para>Asks the user via modal input for the two factor code.</para>
/// <para>This uses DisCatSharp.Interactivity.</para>
/// <para>To be used as first action for button.</para>
/// <para>Asks the user via modal input for the two factor code.</para>
/// <para>This uses DisCatSharp.Interactivity.</para>
/// <para>To be used as first action for button.</para>
/// </summary>
/// <param name="evt">The interaction context.</param>
/// <param name="client">The discord client to use.</param>
/// <returns>A <see cref="TwoFactorResponse"/>.</returns>
/// <returns>A <see cref="TwoFactorResponse" />.</returns>
public static async Task<TwoFactorResponse> RequestTwoFactorAsync(this ComponentInteractionCreateEventArgs evt, DiscordClient client)
{
var ext = client.GetTwoFactor();
Expand All @@ -126,7 +126,7 @@ public static async Task<TwoFactorResponse> RequestTwoFactorAsync(this Component
builder.AddTextComponent(new(TextComponentStyle.Small, "code", "Code", "123456", ext.Configuration.Digits, ext.Configuration.Digits));
await evt.Interaction.CreateInteractionModalResponseAsync(builder);

var response = new TwoFactorResponse()
var response = new TwoFactorResponse
{
Client = client
};
Expand Down
Loading

0 comments on commit 5bbe108

Please sign in to comment.