Skip to content

Reimplement message parsing as a toggleable feature #338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
28cf758
Initial whitespace changes
nikita-petko Oct 1, 2024
ca7507e
#337: LuaVM changes
nikita-petko Oct 1, 2024
4180ad3
#336: Script Logger
nikita-petko Oct 1, 2024
b91578b
Update BacktraceUtility
nikita-petko Oct 1, 2024
4e5438c
Update SocketInteractionExtensions.cs
nikita-petko Oct 1, 2024
5772194
#336: Extension methods
nikita-petko Oct 1, 2024
3878343
Update CommandsSettings.cs
nikita-petko Oct 1, 2024
a63fc00
Update ScriptLogger.cs
nikita-petko Oct 1, 2024
ba3e4ee
Update OnSlashCommandExecuted.cs
nikita-petko Oct 1, 2024
3bb1267
#336: OnCommandExecutedEvent
nikita-petko Oct 1, 2024
6144127
Update OnLogMessage.cs
nikita-petko Oct 1, 2024
e99be23
#336: OnMessage
nikita-petko Oct 1, 2024
faaaa53
Update OnInteraction.cs
nikita-petko Oct 1, 2024
5b61a89
#336: Update Runner.cs
nikita-petko Oct 1, 2024
c763749
#336: OnReady
nikita-petko Oct 1, 2024
92b48a7
#336: Lock Down Attribute
nikita-petko Oct 1, 2024
9361cc3
#336: RequireBotRoleAttribute
nikita-petko Oct 1, 2024
7b4089c
#336: Private Modules
nikita-petko Oct 1, 2024
8cbbcbe
#336: Modules
nikita-petko Oct 1, 2024
729d5e8
Local Testing: Noop Job Manager
nikita-petko Oct 3, 2024
018a839
Administration: Bot roles
nikita-petko Oct 3, 2024
aa14bcf
Account for change to BotRole enum.
nikita-petko Oct 3, 2024
ab65c9a
#336: Help Command
nikita-petko Oct 3, 2024
248a576
Rewrap on interaction + command service calls
nikita-petko Oct 3, 2024
72a0978
Update on command and interaction executed.
nikita-petko Oct 3, 2024
428757a
Bump all mfdlabs packages
nikita-petko Oct 9, 2024
1df7a25
Reflect package upgrades
nikita-petko Oct 9, 2024
3d6a316
#336: Text commands clean ups
nikita-petko Oct 9, 2024
4a99d5a
#336: Settings Text command.
nikita-petko Oct 9, 2024
158b6c7
#336: Minor fix with Help command
nikita-petko Oct 9, 2024
9dbfef0
Update recovery to reflect logger changes
nikita-petko Oct 9, 2024
79ea416
Update recovery log message adaptor
nikita-petko Oct 9, 2024
7289969
#336: Settings Command List
nikita-petko Oct 9, 2024
fe515bf
Update Help.cs
nikita-petko Oct 9, 2024
b1e9235
Update ClientSettings.cs
nikita-petko Oct 9, 2024
709b8a6
Update OnLogMessage.cs
nikita-petko Oct 9, 2024
e830e97
Update OnLogMessage.cs
nikita-petko Oct 9, 2024
31112cf
Update ScriptLogger.cs
nikita-petko Oct 9, 2024
f7d094b
Update IScriptLogger.cs
nikita-petko Oct 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .editorconfig
100644 → 100755
Empty file.
Empty file modified .gitattributes
100644 → 100755
Empty file.
Empty file modified .github/ISSUE_TEMPLATE/blacklist_appeal.yml
100644 → 100755
Empty file.
Empty file modified .github/ISSUE_TEMPLATE/bug_report.yml
100644 → 100755
Empty file.
Empty file modified .github/ISSUE_TEMPLATE/config.yml
100644 → 100755
Empty file.
Empty file modified .github/ISSUE_TEMPLATE/feature_request.yml
100644 → 100755
Empty file.
Empty file modified .github/ISSUE_TEMPLATE/security_vulnerabilty.yml
100644 → 100755
Empty file.
Empty file modified .github/workflows/build.yml
100644 → 100755
Empty file.
Empty file modified .github/workflows/deploy.yml
100644 → 100755
Empty file.
Empty file modified .github/workflows/docs.yml
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .gitmodules
100644 → 100755
Empty file.
Empty file modified CODEOWNERS
100644 → 100755
Empty file.
Empty file modified CONTRIBUTING.md
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified SECURITY.md
100644 → 100755
Empty file.
Empty file modified docs/CNAME
100644 → 100755
Empty file.
Empty file modified docs/assets/logo.svg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified docs/assets/theme.css
100644 → 100755
Empty file.
Empty file modified docs/index.md
100644 → 100755
Empty file.
Empty file modified docs/legal/index.md
100644 → 100755
Empty file.
Empty file modified docs/legal/privacy-policy.md
100644 → 100755
Empty file.
Empty file modified docs/legal/tos.md
100644 → 100755
Empty file.
Empty file modified docs/overrides/assets/stylesheets/main.css
100644 → 100755
Empty file.
Empty file modified docs/overrides/main.html
100644 → 100755
Empty file.
Empty file modified docs/request-data-deletion.md
100644 → 100755
Empty file.
Empty file modified mkdocs.yml
100644 → 100755
Empty file.
Empty file modified proto/grid_bot.proto
100644 → 100755
Empty file.
Empty file modified scripts/clean.sh
100644 → 100755
Empty file.
Empty file modified services/Directory.Build.props
100644 → 100755
Empty file.
Empty file modified services/Directory.Build.targets
100644 → 100755
Empty file.
Empty file modified services/grid-bot/.component.yaml
100644 → 100755
Empty file.
Empty file modified services/grid-bot/.dockerignore
100644 → 100755
Empty file.
Empty file modified services/grid-bot/Dockerfile
100644 → 100755
Empty file.
Empty file modified services/grid-bot/README.md
100644 → 100755
Empty file.
Empty file modified services/grid-bot/grid-bot-bare.sln
100644 → 100755
Empty file.
Empty file modified services/grid-bot/grid-bot.sln
100644 → 100755
Empty file.
Empty file modified services/grid-bot/lib/Directory.Build.props
100644 → 100755
Empty file.
Empty file modified services/grid-bot/lib/Directory.Build.targets
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
namespace Grid.Bot.Commands;

using System;
using System.Threading.Tasks;

using Microsoft.Extensions.DependencyInjection;

using Discord.Commands;

using Utility;

/// <summary>
/// An attribute only allows the command to be executed within the DMs of
/// users within the specified bot role, or within the specified guild (if configured).
/// </summary>
/// <remarks>
/// Construct a new instance of <see cref="LockDownCommandAttribute"/>.
/// </remarks>
/// <param name="botRole">The <see cref="BotRole"/>.</param>
public class LockDownCommandAttribute(BotRole botRole = BotRole.Administrator) : PreconditionAttribute
{
private readonly BotRole _botRole = botRole;

/// <summary>
/// The marker to indicate that the command should not respond.
/// </summary>
public const string MarkerDoNotRespond = "___||DO_NOT_RESPOND||___";

/// <inheritdoc cref="PreconditionAttribute.CheckPermissionsAsync(ICommandContext, CommandInfo, IServiceProvider)"/>
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo commandInfo, IServiceProvider services)
{
var commandsSettings = services.GetRequiredService<CommandsSettings>();
if (!commandsSettings.EnableLockdownCommands)
return Task.FromResult(PreconditionResult.FromSuccess());

if (context.Guild is not null)
return context.Guild.Id == commandsSettings.LockdownGuildId
? Task.FromResult(PreconditionResult.FromSuccess())
: Task.FromResult(PreconditionResult.FromError(MarkerDoNotRespond));

var adminUtility = services.GetRequiredService<IAdminUtility>();

var isInRole = _botRole switch
{
BotRole.Privileged => adminUtility.UserIsPrivilaged(context.User),
BotRole.Administrator => adminUtility.UserIsPrivilaged(context.User),
BotRole.Owner => adminUtility.UserIsOwner(context.User),
_ => throw new ArgumentOutOfRangeException(nameof(_botRole), _botRole, null),
};

return isInRole
? Task.FromResult(PreconditionResult.FromSuccess())
: Task.FromResult(PreconditionResult.FromError(MarkerDoNotRespond));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace Grid.Bot.Commands;

using System;
using System.Threading.Tasks;

using Microsoft.Extensions.DependencyInjection;

using Discord.Commands;

using Utility;

/// <summary>
/// An attribute that validates if the user has the required bot role.
/// </summary>
/// <remarks>
/// Construct a new instance of <see cref="RequireBotRoleAttribute"/>.
/// </remarks>
/// <param name="botRole">The <see cref="Utility.BotRole"/>.</param>
public class RequireBotRoleAttribute(BotRole botRole = BotRole.Privileged) : PreconditionAttribute
{
/// <summary>
/// The role.
/// </summary>
public BotRole BotRole { get; } = botRole;

private const string _permissionDeniedText = "You lack permission to execute this command.";


/// <inheritdoc cref="PreconditionAttribute.CheckPermissionsAsync(ICommandContext, CommandInfo, IServiceProvider)"/>
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo commandInfo, IServiceProvider services)
{
var adminUtility = services.GetRequiredService<IAdminUtility>();

return BotRole switch
{
BotRole.Privileged => Task.FromResult(!adminUtility.UserIsPrivilaged(context.User)
? PreconditionResult.FromError(_permissionDeniedText)
: PreconditionResult.FromSuccess()),
BotRole.Administrator => Task.FromResult(!adminUtility.UserIsPrivilaged(context.User)
? PreconditionResult.FromError(_permissionDeniedText)
: PreconditionResult.FromSuccess()),
BotRole.Owner => Task.FromResult(!adminUtility.UserIsOwner(context.User)
? PreconditionResult.FromError(_permissionDeniedText)
: PreconditionResult.FromSuccess()),
_ => throw new ArgumentOutOfRangeException(nameof(BotRole), BotRole, null),
};

}
}

This file was deleted.

Loading