From e524aeb84586603b1c7a497fb903fdf4ceca38d1 Mon Sep 17 00:00:00 2001 From: Nikita Petko Date: Mon, 2 Sep 2024 21:06:05 +0100 Subject: [PATCH] Updates to system. Fix #326 Add user context commands for pub commands. --- .../lib/commands/Modules/ExecuteScript.cs | 22 +++++++++++++++++-- .../grid-bot/lib/commands/Modules/Render.cs | 3 +++ .../grid-bot/lib/commands/Modules/Support.cs | 2 ++ .../commands/PrivateModules/ClientSettings.cs | 4 +++- .../commands/PrivateModules/Maintenance.cs | 4 +++- .../lib/commands/PrivateModules/Roles.cs | 4 +++- 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/services/grid-bot/lib/commands/Modules/ExecuteScript.cs b/services/grid-bot/lib/commands/Modules/ExecuteScript.cs index f345106f..b25e4f4f 100644 --- a/services/grid-bot/lib/commands/Modules/ExecuteScript.cs +++ b/services/grid-bot/lib/commands/Modules/ExecuteScript.cs @@ -58,6 +58,8 @@ namespace Grid.Bot.Interactions.Public; /// - cannot be null. /// [Group("execute", "Commands used for executing Luau code.")] +[IntegrationType(ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall)] +[CommandContextType(InteractionContextType.Guild, InteractionContextType.BotDm, InteractionContextType.PrivateChannel)] public partial class ExecuteScript( ILogger logger, GridSettings gridSettings, @@ -143,6 +145,19 @@ private static string GetCodeBlockContents(string s) { if (string.IsNullOrEmpty(input)) return (null, null); + // Check if the input matches grid syntax error + if (GridSyntaxErrorRegex().IsMatch(input)) + { + var match = GridSyntaxErrorRegex().Match(input); + var line = match.Groups[1].Value; + var error = match.Groups[2].Value; + + input = $"Line {line}: {error}"; + } + + // Replace backticks with escaped backticks + input = input.Replace("`", "\\`"); + if (input.Length > _maxErrorLength) { var maxSize = _scriptsSettings.ScriptExecutionMaxFileSizeKb; @@ -160,6 +175,9 @@ private static string GetCodeBlockContents(string s) { if (string.IsNullOrEmpty(input)) return (null, null); + // Replace backticks with escaped backticks + input = input.Replace("`", "\\`"); + if (input.Length > _maxResultLength) { var maxSize = _scriptsSettings.ScriptExecutionMaxResultSizeKb; @@ -259,10 +277,10 @@ private async Task ParseLuaAsync(string input) } var embed = new EmbedBuilder() - .WithTitle("Luau Syntax Error") + .WithTitle("Lua Error") .WithAuthor(Context.User) .WithCurrentTimestamp() - .WithColor(0xff, 0x00, 0x00) + .WithColor(Color.Red) .WithDescription($"```\n{errorString}\n```") .Build(); diff --git a/services/grid-bot/lib/commands/Modules/Render.cs b/services/grid-bot/lib/commands/Modules/Render.cs index 57d364a4..e69829be 100644 --- a/services/grid-bot/lib/commands/Modules/Render.cs +++ b/services/grid-bot/lib/commands/Modules/Render.cs @@ -3,6 +3,7 @@ namespace Grid.Bot.Interactions.Public; using System; using System.Threading.Tasks; +using Discord; using Discord.Interactions; using Logging; @@ -31,6 +32,8 @@ namespace Grid.Bot.Interactions.Public; /// - cannot be null. /// [Group("render", "Commands used for rendering a Roblox character.")] +[IntegrationType(ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall)] +[CommandContextType(InteractionContextType.Guild, InteractionContextType.BotDm, InteractionContextType.PrivateChannel)] public class Render( AvatarSettings avatarSettings, ILogger logger, diff --git a/services/grid-bot/lib/commands/Modules/Support.cs b/services/grid-bot/lib/commands/Modules/Support.cs index 1e55be3f..9ea0e7cd 100644 --- a/services/grid-bot/lib/commands/Modules/Support.cs +++ b/services/grid-bot/lib/commands/Modules/Support.cs @@ -28,6 +28,8 @@ namespace Grid.Bot.Interactions.Public; /// - cannot be null. /// [Group("support", "Commands used for grid-bot-support.")] +[IntegrationType(ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall)] +[CommandContextType(InteractionContextType.Guild, InteractionContextType.BotDm, InteractionContextType.PrivateChannel)] public class Support( GridSettings gridSettings, GlobalSettings globalSettings, diff --git a/services/grid-bot/lib/commands/PrivateModules/ClientSettings.cs b/services/grid-bot/lib/commands/PrivateModules/ClientSettings.cs index fa177e62..d4e124cf 100644 --- a/services/grid-bot/lib/commands/PrivateModules/ClientSettings.cs +++ b/services/grid-bot/lib/commands/PrivateModules/ClientSettings.cs @@ -28,8 +28,10 @@ namespace Grid.Bot.Interactions.Private; /// - cannot be null. /// - cannot be null. /// -[Group("clientsettings", "Manage the client settings.")] [RequireBotRole(BotRole.Administrator)] +[CommandContextType(InteractionContextType.Guild)] +[IntegrationType(ApplicationIntegrationType.GuildInstall)] +[Group("clientsettings", "Manage the client settings.")] public class ClientSettingsModule(IClientSettingsClient clientSettingsClient, ClientSettingsClientSettings clientSettingsClientSettings) : InteractionModuleBase { private readonly IClientSettingsClient _clientSettingsClient = clientSettingsClient ?? throw new ArgumentNullException(nameof(clientSettingsClient)); diff --git a/services/grid-bot/lib/commands/PrivateModules/Maintenance.cs b/services/grid-bot/lib/commands/PrivateModules/Maintenance.cs index 55d6c249..190e99ed 100644 --- a/services/grid-bot/lib/commands/PrivateModules/Maintenance.cs +++ b/services/grid-bot/lib/commands/PrivateModules/Maintenance.cs @@ -21,8 +21,10 @@ namespace Grid.Bot.Interactions.Private; /// - cannot be null. /// - cannot be null. /// -[Group("maintenance", "Commands used for grid-bot-maintenance.")] [RequireBotRole(BotRole.Administrator)] +[CommandContextType(InteractionContextType.Guild)] +[IntegrationType(ApplicationIntegrationType.GuildInstall)] +[Group("maintenance", "Commands used for grid-bot-maintenance.")] public class Maintenance( MaintenanceSettings maintenanceSettings, DiscordSettings discordSettings, diff --git a/services/grid-bot/lib/commands/PrivateModules/Roles.cs b/services/grid-bot/lib/commands/PrivateModules/Roles.cs index 669920f1..21992e65 100644 --- a/services/grid-bot/lib/commands/PrivateModules/Roles.cs +++ b/services/grid-bot/lib/commands/PrivateModules/Roles.cs @@ -20,8 +20,10 @@ namespace Grid.Bot.Interactions.Private; /// - cannot be null. /// - cannot be null. /// -[Group("role", "Commands used for updating user bot roles.")] [RequireBotRole(BotRole.Administrator)] +[CommandContextType(InteractionContextType.Guild)] +[IntegrationType(ApplicationIntegrationType.GuildInstall)] +[Group("role", "Commands used for updating user bot roles.")] public class Roles( DiscordRolesSettings discordRolesSettings, IAdminUtility adminUtility