Skip to content

Commit b7657fa

Browse files
committed
skip metadata when passing contents
1 parent f89a8cb commit b7657fa

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

ECommons

SomethingNeedDoing/LuaMacro/NLuaMacroEngine.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using NLua;
22
using SomethingNeedDoing.Core.Events;
33
using SomethingNeedDoing.Core.Interfaces;
4+
using SomethingNeedDoing.Utils;
45
using System.Text;
56
using System.Threading;
67
using System.Threading.Tasks;
@@ -93,7 +94,7 @@ await Svc.Framework.RunOnTick(async () =>
9394
try
9495
{
9596
// Execute the script
96-
var results = lua.LoadEntryPointWrappedScript(macro.Macro.Content);
97+
var results = lua.LoadEntryPointWrappedScript(macro.Macro.ContentSansMetadata());
9798
if (results.Length == 0 || results[0] is not LuaFunction func)
9899
throw new LuaException("Failed to load Lua script: No function returned");
99100

SomethingNeedDoing/NativeMacro/NativeMacroEngine.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using SomethingNeedDoing.Core.Events;
22
using SomethingNeedDoing.Core.Interfaces;
3+
using SomethingNeedDoing.Utils;
34
using System.Threading;
45
using System.Threading.Tasks;
56

@@ -51,7 +52,7 @@ public async Task StartMacro(IMacro macro, CancellationToken token, TriggerEvent
5152

5253
var state = new MacroExecutionState(macro)
5354
{
54-
Commands = parser.Parse(macro.Content, Scheduler),
55+
Commands = parser.Parse(macro.ContentSansMetadata(), Scheduler),
5556
CurrentLoop = 0,
5657
LoopCount = loopCount == 0 ? 1 : loopCount
5758
};

SomethingNeedDoing/Utils/ConfigMacroExtensions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
using SomethingNeedDoing.Core.Events;
22
using SomethingNeedDoing.Core.Interfaces;
3+
using System.Text.RegularExpressions;
34

45
namespace SomethingNeedDoing.Utils;
56
public static class ConfigMacroExtensions
67
{
8+
private static readonly Regex MetadataBlockRegex = new(
9+
@"^--\[\[SND\s*Metadata\s*\]\]\s*\n(.*?)\n--\[\[End\s*Metadata\s*\]\]",
10+
RegexOptions.Singleline | RegexOptions.IgnoreCase);
11+
12+
/// <summary>
13+
/// Removes the metadata block from macro content.
14+
/// </summary>
15+
public static string ContentSansMetadata(this IMacro macro)
16+
{
17+
var match = MetadataBlockRegex.Match(macro.Content);
18+
if (!match.Success)
19+
return macro.Content;
20+
return macro.Content[..match.Index] + macro.Content[(match.Index + match.Length)..].TrimStart('\r', '\n');
21+
}
22+
723
public static void Rename(this ConfigMacro macro, string newName)
824
{
925
macro.Name = newName;

0 commit comments

Comments
 (0)