Skip to content

Commit

Permalink
Updates to system.
Browse files Browse the repository at this point in the history
Fix #326
Add user context commands for pub commands.
  • Loading branch information
jf-06 committed Sep 2, 2024
1 parent 660e1ea commit e524aeb
Showing 6 changed files with 34 additions and 5 deletions.
22 changes: 20 additions & 2 deletions services/grid-bot/lib/commands/Modules/ExecuteScript.cs
Original file line number Diff line number Diff line change
@@ -58,6 +58,8 @@ namespace Grid.Bot.Interactions.Public;
/// - <paramref name="gridServerFileHelper"/> cannot be null.
/// </exception>
[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<bool> 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();

3 changes: 3 additions & 0 deletions services/grid-bot/lib/commands/Modules/Render.cs
Original file line number Diff line number Diff line change
@@ -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;
/// - <paramref name="adminUtility"/> cannot be null.
/// </exception>
[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,
2 changes: 2 additions & 0 deletions services/grid-bot/lib/commands/Modules/Support.cs
Original file line number Diff line number Diff line change
@@ -28,6 +28,8 @@ namespace Grid.Bot.Interactions.Public;
/// - <paramref name="gridServerFileHelper"/> cannot be null.
/// </exception>
[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,
Original file line number Diff line number Diff line change
@@ -28,8 +28,10 @@ namespace Grid.Bot.Interactions.Private;
/// - <paramref name="clientSettingsClient"/> cannot be null.
/// - <paramref name="clientSettingsClientSettings"/> cannot be null.
/// </exception>
[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<ShardedInteractionContext>
{
private readonly IClientSettingsClient _clientSettingsClient = clientSettingsClient ?? throw new ArgumentNullException(nameof(clientSettingsClient));
4 changes: 3 additions & 1 deletion services/grid-bot/lib/commands/PrivateModules/Maintenance.cs
Original file line number Diff line number Diff line change
@@ -21,8 +21,10 @@ namespace Grid.Bot.Interactions.Private;
/// - <paramref name="discordSettings"/> cannot be null.
/// - <paramref name="discordShardedClient"/> cannot be null.
/// </exception>
[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,
4 changes: 3 additions & 1 deletion services/grid-bot/lib/commands/PrivateModules/Roles.cs
Original file line number Diff line number Diff line change
@@ -20,8 +20,10 @@ namespace Grid.Bot.Interactions.Private;
/// - <paramref name="discordRolesSettings"/> cannot be null.
/// - <paramref name="adminUtility"/> cannot be null.
/// </exception>
[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

0 comments on commit e524aeb

Please sign in to comment.