From 81a61715268a3a830f5366a5cc9442e9c5046049 Mon Sep 17 00:00:00 2001 From: Toastie Date: Sat, 14 Sep 2024 00:49:35 +1200 Subject: [PATCH] Fixed some string replacements not working (fixed default help string). Removed some references to nsfw stuff --- src/EllieBot/Modules/Help/Help.cs | 4 -- .../_common/Replacements/Impl/Replacer.cs | 43 ++++++++++--------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/EllieBot/Modules/Help/Help.cs b/src/EllieBot/Modules/Help/Help.cs index 95fabd6..aedb8e8 100644 --- a/src/EllieBot/Modules/Help/Help.cs +++ b/src/EllieBot/Modules/Help/Help.cs @@ -175,8 +175,6 @@ public sealed partial class Help : EllieModule return strs.module_description_gambling; case "music": return strs.module_description_music; - case "nsfw": - return strs.module_description_nsfw; case "permissions": return strs.module_description_permissions; case "xp": @@ -211,8 +209,6 @@ public sealed partial class Help : EllieModule return "💰"; case "music": return "🎶"; - case "nsfw": - return "😳"; case "permissions": return "🚓"; case "xp": diff --git a/src/EllieBot/_common/Replacements/Impl/Replacer.cs b/src/EllieBot/_common/Replacements/Impl/Replacer.cs index 9b43331..0bf092c 100644 --- a/src/EllieBot/_common/Replacements/Impl/Replacer.cs +++ b/src/EllieBot/_common/Replacements/Impl/Replacer.cs @@ -9,8 +9,8 @@ public sealed partial class Replacer private readonly IEnumerable _regexReps; private readonly object[] _inputData; - [GeneratedRegex(@"\%[\p{L}\p{N}\._]*[\p{L}\p{N}]+[\p{L}\p{N}\._]*\%")] - private static partial Regex TokenExtractionRegex(); + // [GeneratedRegex(@"\%[\p{L}\p{N}\._]*[\p{L}\p{N}]+[\p{L}\p{N}\._]*\%")] + // private static partial Regex TokenExtractionRegex(); public Replacer(IEnumerable reps, IEnumerable regexReps, object[] inputData) { @@ -24,19 +24,19 @@ public sealed partial class Replacer if (string.IsNullOrWhiteSpace(input)) return input; - var matches = TokenExtractionRegex().IsMatch(input); + // var matches = TokenExtractionRegex().IsMatch(input); - if (matches) + // if (matches) + // { + foreach (var rep in _reps) { - foreach (var rep in _reps) + if (input.Contains(rep.Token, StringComparison.InvariantCulture)) { - if (input.Contains(rep.Token, StringComparison.InvariantCulture)) - { - var objs = GetParams(rep.InputTypes); - input = input.Replace(rep.Token, await rep.GetValueAsync(objs), StringComparison.InvariantCulture); - } + var objs = GetParams(rep.InputTypes); + input = input.Replace(rep.Token, await rep.GetValueAsync(objs), StringComparison.InvariantCulture); } } + // } foreach (var rep in _regexReps) { @@ -47,7 +47,7 @@ public sealed partial class Replacer if (match.Success) { sb.Append(input, 0, match.Index) - .Append(await rep.GetValueAsync(match, objs)); + .Append(await rep.GetValueAsync(match, objs)); var lastIndex = match.Index + match.Length; sb.Append(input, lastIndex, input.Length - lastIndex); @@ -93,14 +93,16 @@ public sealed partial class Replacer Embeds = await embedArr.Embeds.Map(async e => await ReplaceAsync(e) with { Color = e.Color - }).WhenAll(), + }) + .WhenAll(), Content = await ReplaceAsync(embedArr.Content) }; private async ValueTask ReplaceAsync(SmartPlainText plain) => await ReplaceAsync(plain.Text); - private async Task ReplaceAsync(T embedData) where T : SmartEmbedTextBase, new() + private async Task ReplaceAsync(T embedData) + where T : SmartEmbedTextBase, new() { var newEmbedData = new T { @@ -117,13 +119,14 @@ public sealed partial class Replacer IconUrl = await ReplaceAsync(embedData.Author.IconUrl) }, Fields = await Task.WhenAll(embedData - .Fields? - .Map(async f => new SmartTextEmbedField - { - Name = await ReplaceAsync(f.Name), - Value = await ReplaceAsync(f.Value), - Inline = f.Inline - }) ?? []), + .Fields? + .Map(async f => new SmartTextEmbedField + { + Name = await ReplaceAsync(f.Name), + Value = await ReplaceAsync(f.Value), + Inline = f.Inline + }) + ?? []), Footer = embedData.Footer is null ? null : new()