Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Issue is impossible.
Upgrade to net8.0
Implement C# evaluation.
  • Loading branch information
nikita-petko committed Nov 13, 2023
1 parent 0bd7fd8 commit bd11111
Show file tree
Hide file tree
Showing 21 changed files with 629 additions and 472 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
- name: Setup .NET 6
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x

- name: Create Deployment Directory
run: |
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/bin/debug/net6.0/Grid.Bot.dll",
"program": "${workspaceFolder}/src/bin/debug/net8.0/Grid.Bot.dll",
"cwd": "${workspaceFolder}/src",
"console": "internalConsole",
"stopAtEntry": false,
Expand Down
2 changes: 1 addition & 1 deletion shared/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</PropertyGroup>

<PropertyGroup Label="LibStandard">
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>preview</LangVersion>
<RootNamespace>Grid.Bot</RootNamespace>

Expand Down
16 changes: 6 additions & 10 deletions shared/commands/Attributes/RequireInteractionBotRoleAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ namespace Grid.Bot.Interactions;
/// <summary>
/// An attribute that validates if the user has the required bot role.
/// </summary>
public class RequireBotRoleAttribute : PreconditionAttribute
/// <remarks>
/// Construct a new instance of <see cref="RequireBotRoleAttribute"/>.
/// </remarks>
/// <param name="botRole">The <see cref="BotRole"/>.</param>
public class RequireBotRoleAttribute(BotRole botRole = BotRole.Privileged) : PreconditionAttribute
{
private readonly BotRole _botRole;
private readonly BotRole _botRole = botRole;

/// <summary>
/// Construct a new instance of <see cref="RequireBotRoleAttribute"/>.
/// </summary>
/// <param name="botRole">The <see cref="BotRole"/>.</param>
public RequireBotRoleAttribute(BotRole botRole = BotRole.Privileged)
{
_botRole = botRole;
}

/// <inheritdoc cref="PreconditionAttribute.CheckRequirementsAsync(IInteractionContext, ICommandInfo, IServiceProvider)"/>
public override Task<PreconditionResult> CheckRequirementsAsync(IInteractionContext context, ICommandInfo commandInfo, IServiceProvider services)
Expand Down
109 changes: 51 additions & 58 deletions shared/commands/Modules/ExecuteScript.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Grid.Bot.Interactions;
namespace Grid.Bot.Interactions.Public;

using System;
using System.IO;
Expand Down Expand Up @@ -28,70 +28,63 @@ namespace Grid.Bot.Interactions;
/// <summary>
/// Interaction handler for executing Luau code.
/// </summary>
/// <remarks>
/// Construct a new instance of <see cref="ExecuteScript"/>.
/// </remarks>
/// <param name="logger">The <see cref="ILogger"/>.</param>
/// <param name="gridSettings">The <see cref="GridSettings"/>.</param>
/// <param name="scriptsSettings">The <see cref="ScriptsSettings"/>.</param>
/// <param name="luaUtility">The <see cref="ILuaUtility"/>.</param>
/// <param name="floodCheckerRegistry">The <see cref="IFloodCheckerRegistry"/>.</param>
/// <param name="backtraceUtility">The <see cref="IBacktraceUtility"/>.</param>
/// <param name="jobManager">The <see cref="IJobManager"/>.</param>
/// <param name="adminUtility">The <see cref="IAdminUtility"/>.</param>
/// <param name="discordWebhookAlertManager">The <see cref="IDiscordWebhookAlertManager"/>.</param>
/// <exception cref="ArgumentNullException">
/// - <paramref name="logger"/> cannot be null.
/// - <paramref name="gridSettings"/> cannot be null.
/// - <paramref name="scriptsSettings"/> cannot be null.
/// - <paramref name="luaUtility"/> cannot be null.
/// - <paramref name="floodCheckerRegistry"/> cannot be null.
/// - <paramref name="backtraceUtility"/> cannot be null.
/// - <paramref name="jobManager"/> cannot be null.
/// - <paramref name="adminUtility"/> cannot be null.
/// - <paramref name="discordWebhookAlertManager"/> cannot be null.
/// </exception>
[Group("execute", "Commands used for executing Luau code.")]
public class ExecuteScript : InteractionModuleBase<ShardedInteractionContext>
public partial class ExecuteScript(
ILogger logger,
GridSettings gridSettings,
ScriptsSettings scriptsSettings,
ILuaUtility luaUtility,
IFloodCheckerRegistry floodCheckerRegistry,
IBacktraceUtility backtraceUtility,
IJobManager jobManager,
IAdminUtility adminUtility,
IDiscordWebhookAlertManager discordWebhookAlertManager
) : InteractionModuleBase<ShardedInteractionContext>
{
private const int _maxErrorLength = EmbedBuilder.MaxDescriptionLength - 8;
private const int _maxResultLength = EmbedFieldBuilder.MaxFieldValueLength - 8;


private readonly ILogger _logger;
private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger));

private readonly GridSettings _gridSettings;
private readonly ScriptsSettings _scriptsSettings;
private readonly GridSettings _gridSettings = gridSettings ?? throw new ArgumentNullException(nameof(gridSettings));
private readonly ScriptsSettings _scriptsSettings = scriptsSettings ?? throw new ArgumentNullException(nameof(scriptsSettings));

private readonly ILuaUtility _luaUtility;
private readonly IFloodCheckerRegistry _floodCheckerRegistry;
private readonly IBacktraceUtility _backtraceUtility;
private readonly IJobManager _jobManager;
private readonly IAdminUtility _adminUtility;
private readonly IDiscordWebhookAlertManager _discordWebhookAlertManager;
private readonly ILuaUtility _luaUtility = luaUtility ?? throw new ArgumentNullException(nameof(luaUtility));
private readonly IFloodCheckerRegistry _floodCheckerRegistry = floodCheckerRegistry ?? throw new ArgumentNullException(nameof(floodCheckerRegistry));
private readonly IBacktraceUtility _backtraceUtility = backtraceUtility ?? throw new ArgumentNullException(nameof(backtraceUtility));
private readonly IJobManager _jobManager = jobManager ?? throw new ArgumentNullException(nameof(jobManager));
private readonly IAdminUtility _adminUtility = adminUtility ?? throw new ArgumentNullException(nameof(adminUtility));
private readonly IDiscordWebhookAlertManager _discordWebhookAlertManager = discordWebhookAlertManager ?? throw new ArgumentNullException(nameof(discordWebhookAlertManager));

/// <summary>
/// Construct a new instance of <see cref="ExecuteScript"/>.
/// </summary>
/// <param name="logger">The <see cref="ILogger"/>.</param>
/// <param name="gridSettings">The <see cref="GridSettings"/>.</param>
/// <param name="scriptsSettings">The <see cref="ScriptsSettings"/>.</param>
/// <param name="luaUtility">The <see cref="ILuaUtility"/>.</param>
/// <param name="floodCheckerRegistry">The <see cref="IFloodCheckerRegistry"/>.</param>
/// <param name="backtraceUtility">The <see cref="IBacktraceUtility"/>.</param>
/// <param name="jobManager">The <see cref="IJobManager"/>.</param>
/// <param name="adminUtility">The <see cref="IAdminUtility"/>.</param>
/// <param name="discordWebhookAlertManager">The <see cref="IDiscordWebhookAlertManager"/>.</param>
/// <exception cref="ArgumentNullException">
/// - <paramref name="logger"/> cannot be null.
/// - <paramref name="gridSettings"/> cannot be null.
/// - <paramref name="scriptsSettings"/> cannot be null.
/// - <paramref name="luaUtility"/> cannot be null.
/// - <paramref name="floodCheckerRegistry"/> cannot be null.
/// - <paramref name="backtraceUtility"/> cannot be null.
/// - <paramref name="jobManager"/> cannot be null.
/// - <paramref name="adminUtility"/> cannot be null.
/// - <paramref name="discordWebhookAlertManager"/> cannot be null.
/// </exception>
public ExecuteScript(
ILogger logger,
GridSettings gridSettings,
ScriptsSettings scriptsSettings,
ILuaUtility luaUtility,
IFloodCheckerRegistry floodCheckerRegistry,
IBacktraceUtility backtraceUtility,
IJobManager jobManager,
IAdminUtility adminUtility,
IDiscordWebhookAlertManager discordWebhookAlertManager
)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_gridSettings = gridSettings ?? throw new ArgumentNullException(nameof(gridSettings));
_scriptsSettings = scriptsSettings ?? throw new ArgumentNullException(nameof(scriptsSettings));
_luaUtility = luaUtility ?? throw new ArgumentNullException(nameof(luaUtility));
_floodCheckerRegistry = floodCheckerRegistry ?? throw new ArgumentNullException(nameof(floodCheckerRegistry));
_backtraceUtility = backtraceUtility ?? throw new ArgumentNullException(nameof(backtraceUtility));
_jobManager = jobManager ?? throw new ArgumentNullException(nameof(jobManager));
_adminUtility = adminUtility ?? throw new ArgumentNullException(nameof(adminUtility));
_discordWebhookAlertManager = discordWebhookAlertManager ?? throw new ArgumentNullException(nameof(discordWebhookAlertManager));
}

[GeneratedRegex(@"```(.*?)\s(.*?)```", RegexOptions.IgnoreCase | RegexOptions.Singleline, "en-GB")]
private static partial Regex CodeBlockRegex();
[GeneratedRegex("[\"“‘”]", RegexOptions.IgnoreCase | RegexOptions.Compiled, "en-GB")]
private static partial Regex QuotesRegex();

/// <inheritdoc cref="InteractionModuleBase{TContext}.BeforeExecuteAsync(ICommandInfo)"/>
public override async Task BeforeExecuteAsync(ICommandInfo command)
Expand All @@ -115,7 +108,7 @@ public override async Task BeforeExecuteAsync(ICommandInfo command)

private static string GetCodeBlockContents(string s)
{
var match = Regex.Match(s, @"```(.*?)\s(.*?)```", RegexOptions.IgnoreCase | RegexOptions.Singleline);
var match = CodeBlockRegex().Match(s);

if (match != null && match.Groups.Count == 3)
{
Expand All @@ -128,7 +121,7 @@ private static string GetCodeBlockContents(string s)
return s.Replace("`", ""); // Return the value here again?
}

private static string EscapeQuotes(string s) => Regex.Replace(s, "[\"“‘”]", "\"", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static string EscapeQuotes(string s) => QuotesRegex().Replace(s, "\"");

private static bool ContainsUnicode(string s) => s.Any(c => c > 255);

Expand Down
73 changes: 32 additions & 41 deletions shared/commands/Modules/Render.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Grid.Bot.Interactions;
namespace Grid.Bot.Interactions.Public;

using System;
using System.Threading.Tasks;
Expand All @@ -12,50 +12,41 @@ namespace Grid.Bot.Interactions;
/// <summary>
/// Interaction handler for rendering a Roblox character.
/// </summary>
/// <remarks>
/// Construct a new instance of <see cref="Render"/>.
/// </remarks>
/// <param name="avatarSettings">The <see cref="AvatarSettings"/>.</param>
/// <param name="logger">The <see cref="ILogger"/>.</param>
/// <param name="rbxUsersUtility">The <see cref="IRbxUsersUtility"/>.</param>
/// <param name="avatarUtility">The <see cref="IAvatarUtility"/>.</param>
/// <param name="floodCheckerRegistry">The <see cref="IFloodCheckerRegistry"/>.</param>
/// <param name="adminUtility">The <see cref="IAdminUtility"/>.</param>
/// <exception cref="ArgumentNullException">
/// - <paramref name="avatarSettings"/> cannot be null.
/// - <paramref name="logger"/> cannot be null.
/// - <paramref name="rbxUsersUtility"/> cannot be null.
/// - <paramref name="avatarUtility"/> cannot be null.
/// - <paramref name="floodCheckerRegistry"/> cannot be null.
/// - <paramref name="adminUtility"/> cannot be null.
/// </exception>
[Group("render", "Commands used for rendering a Roblox character.")]
public class Render : InteractionModuleBase<ShardedInteractionContext>
public class Render(
AvatarSettings avatarSettings,
ILogger logger,
IRbxUsersUtility rbxUsersUtility,
IAvatarUtility avatarUtility,
IFloodCheckerRegistry floodCheckerRegistry,
IAdminUtility adminUtility
) : InteractionModuleBase<ShardedInteractionContext>
{
private readonly AvatarSettings _avatarSettings;
private readonly AvatarSettings _avatarSettings = avatarSettings ?? throw new ArgumentNullException(nameof(avatarSettings));

private readonly ILogger _logger;
private readonly IRbxUsersUtility _rbxUsersUtility;
private readonly IAvatarUtility _avatarUtility;
private readonly IFloodCheckerRegistry _floodCheckerRegistry;
private readonly IAdminUtility _adminUtility;
private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger));
private readonly IRbxUsersUtility _rbxUsersUtility = rbxUsersUtility ?? throw new ArgumentNullException(nameof(rbxUsersUtility));
private readonly IAvatarUtility _avatarUtility = avatarUtility ?? throw new ArgumentNullException(nameof(avatarUtility));
private readonly IFloodCheckerRegistry _floodCheckerRegistry = floodCheckerRegistry ?? throw new ArgumentNullException(nameof(floodCheckerRegistry));
private readonly IAdminUtility _adminUtility = adminUtility ?? throw new ArgumentNullException(nameof(adminUtility));

/// <summary>
/// Construct a new instance of <see cref="Render"/>.
/// </summary>
/// <param name="avatarSettings">The <see cref="AvatarSettings"/>.</param>
/// <param name="logger">The <see cref="ILogger"/>.</param>
/// <param name="rbxUsersUtility">The <see cref="IRbxUsersUtility"/>.</param>
/// <param name="avatarUtility">The <see cref="IAvatarUtility"/>.</param>
/// <param name="floodCheckerRegistry">The <see cref="IFloodCheckerRegistry"/>.</param>
/// <param name="adminUtility">The <see cref="IAdminUtility"/>.</param>
/// <exception cref="ArgumentNullException">
/// - <paramref name="avatarSettings"/> cannot be null.
/// - <paramref name="logger"/> cannot be null.
/// - <paramref name="rbxUsersUtility"/> cannot be null.
/// - <paramref name="avatarUtility"/> cannot be null.
/// - <paramref name="floodCheckerRegistry"/> cannot be null.
/// - <paramref name="adminUtility"/> cannot be null.
/// </exception>
public Render(
AvatarSettings avatarSettings,
ILogger logger,
IRbxUsersUtility rbxUsersUtility,
IAvatarUtility avatarUtility,
IFloodCheckerRegistry floodCheckerRegistry,
IAdminUtility adminUtility
)
{
_avatarSettings = avatarSettings ?? throw new ArgumentNullException(nameof(avatarSettings));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_rbxUsersUtility = rbxUsersUtility ?? throw new ArgumentNullException(nameof(rbxUsersUtility));
_avatarUtility = avatarUtility ?? throw new ArgumentNullException(nameof(avatarUtility));
_floodCheckerRegistry = floodCheckerRegistry ?? throw new ArgumentNullException(nameof(floodCheckerRegistry));
_adminUtility = adminUtility ?? throw new ArgumentNullException(nameof(adminUtility));
}

/// <inheritdoc cref="InteractionModuleBase{TContext}.BeforeExecuteAsync(ICommandInfo)"/>
public override async Task BeforeExecuteAsync(ICommandInfo command)
Expand Down
46 changes: 20 additions & 26 deletions shared/commands/Modules/Support.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Grid.Bot.Interactions;
namespace Grid.Bot.Interactions.Public;

using System;
using System.Reflection;
Expand All @@ -12,34 +12,28 @@ namespace Grid.Bot.Interactions;
/// <summary>
/// Interaction handler for the support commands.
/// </summary>
/// <remarks>
/// Construct a new instance of <see cref="Support"/>.
/// </remarks>
/// <param name="gridSettings">The <see cref="GridSettings"/>.</param>
/// <param name="globalSettings">The <see cref="GlobalSettings"/>.</param>
/// <param name="localIpAddressProvider">The <see cref="ILocalIpAddressProvider"/>.</param>
/// <exception cref="ArgumentNullException">
/// - <paramref name="gridSettings"/> cannot be null.
/// - <paramref name="globalSettings"/> cannot be null.
/// - <paramref name="localIpAddressProvider"/> cannot be null.
/// </exception>
[Group("support", "Commands used for grid-bot-support.")]
public class Support : InteractionModuleBase<ShardedInteractionContext>
public class Support(
GridSettings gridSettings,
GlobalSettings globalSettings,
ILocalIpAddressProvider localIpAddressProvider
) : InteractionModuleBase<ShardedInteractionContext>
{
private readonly GridSettings _gridSettings;
private readonly GlobalSettings _globalSettings;
private readonly ILocalIpAddressProvider _localIpAddressProvider;
private readonly GridSettings _gridSettings = gridSettings ?? throw new ArgumentNullException(nameof(gridSettings));
private readonly GlobalSettings _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings));
private readonly ILocalIpAddressProvider _localIpAddressProvider = localIpAddressProvider ?? throw new ArgumentNullException(nameof(localIpAddressProvider));

/// <summary>
/// Construct a new instance of <see cref="Support"/>.
/// </summary>
/// <param name="gridSettings">The <see cref="GridSettings"/>.</param>
/// <param name="globalSettings">The <see cref="GlobalSettings"/>.</param>
/// <param name="localIpAddressProvider">The <see cref="ILocalIpAddressProvider"/>.</param>
/// <exception cref="ArgumentNullException">
/// - <paramref name="gridSettings"/> cannot be null.
/// - <paramref name="globalSettings"/> cannot be null.
/// - <paramref name="localIpAddressProvider"/> cannot be null.
/// </exception>
public Support(
GridSettings gridSettings,
GlobalSettings globalSettings,
ILocalIpAddressProvider localIpAddressProvider
)
{
_gridSettings = gridSettings ?? throw new ArgumentNullException(nameof(gridSettings));
_globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings));
_localIpAddressProvider = localIpAddressProvider ?? throw new ArgumentNullException(nameof(localIpAddressProvider));
}

/// <summary>
/// Gets informational links for the bot, in a stylish embed.
Expand Down
Loading

0 comments on commit bd11111

Please sign in to comment.