Skip to content

Commit

Permalink
chore(code-style): enforce new code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Sep 21, 2023
1 parent 8cb67f3 commit b3a0213
Show file tree
Hide file tree
Showing 643 changed files with 14,783 additions and 5,272 deletions.
3,971 changes: 3,815 additions & 156 deletions .editorconfig

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions .nuget/NuGet.config
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>

<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
</configuration>
9 changes: 5 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>

<Project>
<ItemGroup>
<SourceRoot Include="$(MSBuildThisFileDirectory)/"/>
</ItemGroup>
<ItemGroup>
<SourceRoot Include="$(MSBuildThisFileDirectory)/" />
</ItemGroup>
<PropertyGroup>
<!--<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)/DisCatSharp.Tools/DisCatSharp.ruleset</CodeAnalysisRuleSet>-->
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public class ApplicationCommandsConfiguration
/// </summary>
[ActivatorUtilitiesConstructor]
public ApplicationCommandsConfiguration()
{ }
{
}

/// <summary>
/// Utilized via dependency injection pipeline.
Expand Down
617 changes: 380 additions & 237 deletions DisCatSharp.ApplicationCommands/ApplicationCommandsExtension.cs

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions DisCatSharp.ApplicationCommands/ApplicationCommandsUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ internal static bool IsModuleCandidateType(this TypeInfo targetTypeInfo)
}

// check if anonymous
if (targetTypeInfo.IsGenericType && targetTypeInfo.Name.Contains("AnonymousType") && (targetTypeInfo.Name.StartsWith("<>") || targetTypeInfo.Name.StartsWith("VB$")) && (targetTypeInfo.Attributes & TypeAttributes.NotPublic) == TypeAttributes.NotPublic)
if (targetTypeInfo.IsGenericType && targetTypeInfo.Name.Contains("AnonymousType") &&
(targetTypeInfo.Name.StartsWith("<>") || targetTypeInfo.Name.StartsWith("VB$")) &&
(targetTypeInfo.Attributes & TypeAttributes.NotPublic) == TypeAttributes.NotPublic)
{
if (ApplicationCommandsExtension.DebugEnabled)
ApplicationCommandsExtension.Logger.LogDebug("Anonymous");
Expand All @@ -65,7 +67,8 @@ internal static bool IsModuleCandidateType(this TypeInfo targetTypeInfo)
if (ApplicationCommandsExtension.DebugEnabled)
ApplicationCommandsExtension.Logger.LogDebug("Checking qualifying methods");
// qualifies if any method or type qualifies
return targetTypeInfo.DeclaredMethods.Any(xmi => xmi.IsCommandCandidate(out _)) || targetTypeInfo.DeclaredNestedTypes.Any(xti => xti.IsModuleCandidateType());
return targetTypeInfo.DeclaredMethods.Any(xmi => xmi.IsCommandCandidate(out _)) ||
targetTypeInfo.DeclaredNestedTypes.Any(xti => xti.IsModuleCandidateType());
}

/// <summary>
Expand All @@ -83,6 +86,7 @@ internal static bool IsCommandCandidate(this MethodInfo? method, out ParameterIn
ApplicationCommandsExtension.Logger.LogDebug("Not existent");
return false;
}

if (ApplicationCommandsExtension.DebugEnabled)
ApplicationCommandsExtension.Logger.LogDebug("Checking method {name}", method.Name);

Expand All @@ -96,10 +100,13 @@ internal static bool IsCommandCandidate(this MethodInfo? method, out ParameterIn

// check if appropriate return and arguments
parameters = method.GetParameters();
if (!parameters.Any() || (parameters.First().ParameterType != typeof(ContextMenuContext) && parameters.First().ParameterType != typeof(InteractionContext)) || method.ReturnType != typeof(Task))
if (!parameters.Any() ||
(parameters.First().ParameterType != typeof(ContextMenuContext) &&
parameters.First().ParameterType != typeof(InteractionContext)) || method.ReturnType != typeof(Task))
{
if (ApplicationCommandsExtension.DebugEnabled)
ApplicationCommandsExtension.Logger.LogDebug("Missing first parameter with type ContextMenuContext or InteractionContext");
ApplicationCommandsExtension.Logger
.LogDebug("Missing first parameter with type ContextMenuContext or InteractionContext");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public sealed class ContextMenuAttribute : Attribute
/// <param name="isNsfw">Whether the context menu is marked as NSFW.</param>
/// <param name="allowedContexts">The allowed contexts of the context menu.</param>
/// <param name="integrationTypes">The allowed integration types of the context menu.</param>
public ContextMenuAttribute(ApplicationCommandType type, string name, bool isNsfw = false, ApplicationCommandContexts[]? allowedContexts = null, ApplicationCommandIntegrationTypes[]? integrationTypes = null)
public ContextMenuAttribute(ApplicationCommandType type, string name, bool isNsfw = false,
ApplicationCommandContexts[]? allowedContexts = null,
ApplicationCommandIntegrationTypes[]? integrationTypes = null)
{
if (type == ApplicationCommandType.ChatInput)
throw new ArgumentException("Context menus cannot be of type ChatInput (Slash).");
Expand All @@ -69,7 +71,6 @@ public ContextMenuAttribute(ApplicationCommandType type, string name, bool isNsf
this.IntegrationTypes = integrationTypes?.ToList();
}


/// <summary>
/// Marks this method as a context menu.
/// </summary>
Expand All @@ -79,7 +80,9 @@ public ContextMenuAttribute(ApplicationCommandType type, string name, bool isNsf
/// <param name="isNsfw">Whether the context menu is marked as NSFW.</param>
/// <param name="allowedContexts">The allowed contexts of the context menu.</param>
/// <param name="integrationTypes">The allowed integration types of the context menu.</param>
public ContextMenuAttribute(ApplicationCommandType type, string name, long defaultMemberPermissions, bool isNsfw = false, ApplicationCommandContexts[]? allowedContexts = null, ApplicationCommandIntegrationTypes[]? integrationTypes = null)
public ContextMenuAttribute(ApplicationCommandType type, string name, long defaultMemberPermissions,
bool isNsfw = false, ApplicationCommandContexts[]? allowedContexts = null,
ApplicationCommandIntegrationTypes[]? integrationTypes = null)
{
if (type == ApplicationCommandType.ChatInput)
throw new ArgumentException("Context menus cannot be of type ChatInput (Slash).");
Expand All @@ -93,7 +96,6 @@ public ContextMenuAttribute(ApplicationCommandType type, string name, long defau
this.IntegrationTypes = integrationTypes?.ToList();
}


/// <summary>
/// Marks this method as context menu.
/// </summary>
Expand All @@ -103,7 +105,9 @@ public ContextMenuAttribute(ApplicationCommandType type, string name, long defau
/// <param name="isNsfw">Whether the context menu is marked as NSFW.</param>
/// <param name="allowedContexts">The allowed contexts of the context menu.</param>
/// <param name="integrationTypes">The allowed integration types of the context menu.</param>
public ContextMenuAttribute(ApplicationCommandType type, string name, bool dmPermission, bool isNsfw = false, ApplicationCommandContexts[]? allowedContexts = null, ApplicationCommandIntegrationTypes[]? integrationTypes = null)
public ContextMenuAttribute(ApplicationCommandType type, string name, bool dmPermission, bool isNsfw = false,
ApplicationCommandContexts[]? allowedContexts = null,
ApplicationCommandIntegrationTypes[]? integrationTypes = null)
{
if (type == ApplicationCommandType.ChatInput)
throw new ArgumentException("Context menus cannot be of type ChatInput (Slash).");
Expand All @@ -127,7 +131,10 @@ public ContextMenuAttribute(ApplicationCommandType type, string name, bool dmPer
/// <param name="isNsfw">Whether the context menu is marked as NSFW.</param>
/// <param name="allowedContexts">The allowed contexts of the context menu.</param>
/// <param name="integrationTypes">The allowed integration types of the context menu.</param>
public ContextMenuAttribute(ApplicationCommandType type, string name, long defaultMemberPermissions, bool dmPermission, bool isNsfw = false, ApplicationCommandContexts[]? allowedContexts = null, ApplicationCommandIntegrationTypes[]? integrationTypes = null)
public ContextMenuAttribute(ApplicationCommandType type, string name, long defaultMemberPermissions,
bool dmPermission, bool isNsfw = false,
ApplicationCommandContexts[]? allowedContexts = null,
ApplicationCommandIntegrationTypes[]? integrationTypes = null)
{
if (type == ApplicationCommandType.ChatInput)
throw new ArgumentException("Context menus cannot be of type ChatInput (Slash).");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace DisCatSharp.ApplicationCommands.Attributes;
/// Defines a cooldown for this command. This allows you to define how many times can users execute a specific command
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public sealed class ContextMenuCooldownAttribute : ApplicationCommandCheckBaseAttribute, ICooldown<BaseContext, ContextMenuCooldownBucket>
public sealed class ContextMenuCooldownAttribute : ApplicationCommandCheckBaseAttribute,
ICooldown<BaseContext, ContextMenuCooldownBucket>
{
/// <summary>
/// Gets the maximum number of uses before this command triggers a cooldown for its bucket.
Expand Down Expand Up @@ -68,7 +69,11 @@ public ContextMenuCooldownBucket GetBucket(BaseContext ctx)
public TimeSpan GetRemainingCooldown(BaseContext ctx)
{
var bucket = this.GetBucket(ctx);
return bucket == null ? TimeSpan.Zero : bucket.RemainingUses > 0 ? TimeSpan.Zero : bucket.ResetsAt - DateTimeOffset.UtcNow;
return bucket == null
? TimeSpan.Zero
: bucket.RemainingUses > 0
? TimeSpan.Zero
: bucket.ResetsAt - DateTimeOffset.UtcNow;
}

/// <summary>
Expand Down Expand Up @@ -121,7 +126,8 @@ public override async Task<bool> ExecuteChecksAsync(BaseContext ctx)
/// </summary>
public sealed class ContextMenuCooldownBucket : CooldownBucket
{
internal ContextMenuCooldownBucket(int maxUses, TimeSpan resetAfter, ulong userId = 0, ulong channelId = 0, ulong guildId = 0)
internal ContextMenuCooldownBucket(int maxUses, TimeSpan resetAfter, ulong userId = 0, ulong channelId = 0,
ulong guildId = 0)
: base(maxUses, resetAfter, userId, channelId, guildId)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ namespace DisCatSharp.ApplicationCommands.Attributes;
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class DontInjectAttribute : Attribute
{ }
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public sealed class ApplicationCommandRequireDirectMessageAttribute : Applicatio
/// Defines that this command is only usable within a direct message channel.
/// </summary>
public ApplicationCommandRequireDirectMessageAttribute()
{ }
{
}

/// <summary>
/// Runs checks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public sealed class ApplicationCommandRequireDisCatSharpDeveloperAttribute : App
/// Defines that this application command is restricted to DisCatSharp Developers.
/// </summary>
public ApplicationCommandRequireDisCatSharpDeveloperAttribute()
{ }
{
}

/// <summary>
/// Runs checks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public sealed class ApplicationCommandRequireGuildAttribute : ApplicationCommand
/// Defines that this command is only usable within a guild.
/// </summary>
public ApplicationCommandRequireGuildAttribute()
{ }
{
}

/// <summary>
/// Runs checks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public sealed class ApplicationCommandRequireGuildOwnerAttributeAttribute : Appl
/// Defines that this command is only usable within a guild by its owner.
/// </summary>
public ApplicationCommandRequireGuildOwnerAttributeAttribute()
{ }
{
}

/// <summary>
/// Runs checks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public sealed class ApplicationCommandRequireNsfwAttribute : ApplicationCommandC
/// Defines that this command is only usable within a guild.
/// </summary>
public ApplicationCommandRequireNsfwAttribute()
{ }
{
}

/// <summary>
/// Runs checks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ namespace DisCatSharp.ApplicationCommands.Attributes;
/// <summary>
/// Defines that this application command is restricted to the owner of the bot.
/// </summary>
[Deprecated("This is deprecated and will be remove in future in favor of RequireTeamXY"), AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)]
[Deprecated("This is deprecated and will be remove in future in favor of RequireTeamXY"),
AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)]
public sealed class ApplicationCommandRequireOwnerAttribute : ApplicationCommandCheckBaseAttribute
{
/// <summary>
/// Defines that this application command is restricted to the owner of the bot.
/// </summary>
[Deprecated("This is deprecated and will be remove in future in favor of RequireTeamXY")]
public ApplicationCommandRequireOwnerAttribute()
{ }
{
}

/// <summary>
/// Runs checks.
Expand All @@ -28,6 +30,8 @@ public override Task<bool> ExecuteChecksAsync(BaseContext ctx)
var app = ctx.Client.CurrentApplication!;
var me = ctx.Client.CurrentUser!;

return app != null ? Task.FromResult(app.Members.Any(x => x.Id == ctx.User.Id)) : Task.FromResult(ctx.User.Id == me.Id);
return app != null
? Task.FromResult(app.Members.Any(x => x.Id == ctx.User.Id))
: Task.FromResult(ctx.User.Id == me.Id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace DisCatSharp.ApplicationCommands.Attributes;
/// <summary>
/// Requires ownership of the bot or a whitelisted id to execute this command.
/// </summary>
[Deprecated("This is deprecated and will be remove in future in favor of RequireTeamXY"), AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)]
[Deprecated("This is deprecated and will be remove in future in favor of RequireTeamXY"),
AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = false)]
public sealed class ApplicationCommandRequireOwnerOrIdAttribute : ApplicationCommandCheckBaseAttribute
{
/// <summary>
Expand All @@ -39,7 +40,9 @@ public override Task<bool> ExecuteChecksAsync(BaseContext ctx)
var app = ctx.Client.CurrentApplication!;
var me = ctx.Client.CurrentUser!;

var owner = app != null ? Task.FromResult(app.Members.Any(x => x.Id == ctx.User.Id)) : Task.FromResult(ctx.User.Id == me.Id);
var owner = app != null
? Task.FromResult(app.Members.Any(x => x.Id == ctx.User.Id))
: Task.FromResult(ctx.User.Id == me.Id);

var allowed = this.UserIds.Contains(ctx.User.Id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public sealed class ApplicationCommandRequireTeamAdminAttribute : ApplicationCom
/// Defines that this application command is restricted to team members of the bot with admin role or higher.
/// </summary>
public ApplicationCommandRequireTeamAdminAttribute()
{ }
{
}

/// <summary>
/// Runs checks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public sealed class ApplicationCommandRequireTeamDeveloperAttribute : Applicatio
/// Defines that this application command is restricted to team members of the bot with developer role or higher.
/// </summary>
public ApplicationCommandRequireTeamDeveloperAttribute()
{ }
{
}

/// <summary>
/// Runs checks.
Expand All @@ -28,6 +29,8 @@ public override Task<bool> ExecuteChecksAsync(BaseContext ctx)
return Task.FromResult(app.Owner.Id == ctx.User.Id);

var teamMember = app.Team?.Members.FirstOrDefault(x => x.User.Id == ctx.User.Id);
return teamMember == null ? Task.FromResult(false) : Task.FromResult(teamMember.Role is "developer" or "admin" or "owner");
return teamMember == null
? Task.FromResult(false)
: Task.FromResult(teamMember.Role is "developer" or "admin" or "owner");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ public sealed class ApplicationCommandRequireTeamMemberAttribute : ApplicationCo
/// Defines that this application command is restricted to the team members of the bot.
/// </summary>
public ApplicationCommandRequireTeamMemberAttribute()
{ }
{
}

/// <summary>
/// Runs checks.
/// </summary>
public override Task<bool> ExecuteChecksAsync(BaseContext ctx)
{
var app = ctx.Client.CurrentApplication!;
return app.Team is null ? Task.FromResult(app.Owner.Id == ctx.User.Id) : Task.FromResult(app.Members.Any(x => x.Id == ctx.User.Id));
return app.Team is null
? Task.FromResult(app.Owner.Id == ctx.User.Id)
: Task.FromResult(app.Members.Any(x => x.Id == ctx.User.Id));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public sealed class ApplicationCommandRequireTeamOwnerAttribute : ApplicationCom
/// Defines that this application command is restricted to team members of the bot with owner role.
/// </summary>
public ApplicationCommandRequireTeamOwnerAttribute()
{ }
{
}

/// <summary>
/// Runs checks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public sealed class ApplicationCommandRequireTeamReadOnlyAttribute : Application
/// Defines that this application command is restricted to team members of the bot with read-only role or higher.
/// </summary>
public ApplicationCommandRequireTeamReadOnlyAttribute()
{ }
{
}

/// <summary>
/// Runs checks.
Expand All @@ -28,6 +29,8 @@ public override Task<bool> ExecuteChecksAsync(BaseContext ctx)
return Task.FromResult(app.Owner.Id == ctx.User.Id);

var teamMember = app.Team?.Members.FirstOrDefault(x => x.User.Id == ctx.User.Id);
return teamMember == null ? Task.FromResult(false) : Task.FromResult(teamMember.Role is "read-only" or "developer" or "admin" or "owner");
return teamMember == null
? Task.FromResult(false)
: Task.FromResult(teamMember.Role is "read-only" or "developer" or "admin" or "owner");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public override Task<bool> ExecuteChecksAsync(BaseContext ctx)
var pusr = ctx.Channel.PermissionsFor(usr);

return (pusr & Permissions.Administrator) != 0
? Task.FromResult(true)
: (pusr & this.Permissions) == this.Permissions ? Task.FromResult(true) : Task.FromResult(false);
? Task.FromResult(true)
: (pusr & this.Permissions) == this.Permissions
? Task.FromResult(true)
: Task.FromResult(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace DisCatSharp.ApplicationCommands.Attributes;
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true)]
public class ChoiceProviderAttribute : Attribute
{

/// <summary>
/// The type of the provider.
/// </summary>
Expand Down
Loading

0 comments on commit b3a0213

Please sign in to comment.