Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Jan 26, 2025
1 parent 007dd93 commit bb99848
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 162 deletions.
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 @@ -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.

/// <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.

/// <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.
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@
namespace DisCatSharp.CommandsNext.Attributes;

/// <summary>
/// Defines that this command can only be executed if the user is enrolled in two factor auth.
/// Defines that this command can only be executed if the user is enrolled in two factor auth.
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false), Experimental("No support for this yet")]
public sealed class CommandRequireEnrolledTwoFactorAttribute : CheckBaseAttribute
{
/// <summary>
/// Defines that this command can only be executed if the user is enrolled in two factor auth.
/// Defines that this command can only be executed if the user is enrolled in two factor auth.
/// </summary>
public CommandRequireEnrolledTwoFactorAttribute()
{ }

/// <summary>
/// Runs checks.
/// Runs checks.
/// </summary>
public override Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help)
=> Task.FromResult(ctx.Client.GetTwoFactor().IsEnrolled(ctx.User.Id));

Check warning on line 47 in DisCatSharp.Extensions.TwoFactorCommands/Extensions/CommandsNext/CommandRequireEnrolledTwoFactorAttribute.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,27 @@

using DisCatSharp.Attributes;
using DisCatSharp.CommandsNext;
using DisCatSharp.Extensions.TwoFactorCommands.Enums;
using DisCatSharp.Extensions.TwoFactorCommands.Entities;
using DisCatSharp.Extensions.TwoFactorCommands.Enums;

namespace DisCatSharp.Extensions.TwoFactorCommands.CommandsNext;

public static class TwoFactorCommandsNextExtension
{
// TODO: Implement
/// <summary>
/// <para>Asks the user via private for the two factor code.</para>
/// <para>This uses DisCatSharp.Interactivity.</para>
/// <para>To be used for commands next.</para>
/// <para><note type="caution">Not implemented yet. Returns <see cref="TwoFactorResult.NotImplemented"/>.</note></para>
/// <para>Asks the user via private for the two factor code.</para>
/// <para>This uses DisCatSharp.Interactivity.</para>
/// <para>To be used for commands next.</para>
/// <para>
/// <note type="caution">Not implemented yet. Returns <see cref="TwoFactorResult.NotImplemented" />.</note>
/// </para>
/// </summary>
/// <param name="ctx">The command context.</param>
/// <returns>A <see cref="TwoFactorResponse"/>.</returns>
/// <returns>A <see cref="TwoFactorResponse" />.</returns>
[Experimental("No support for this yet. Not implemented")]
public static async Task<TwoFactorResponse> RequestTwoFactorAsync(CommandContext ctx)
=> await Task.FromResult(new TwoFactorResponse()
=> await Task.FromResult(new TwoFactorResponse
{
Result = TwoFactorResult.NotImplemented
});
Expand Down
Loading

0 comments on commit bb99848

Please sign in to comment.