Skip to content

Commit

Permalink
fix: strings being incorrect, speed up code
Browse files Browse the repository at this point in the history
  • Loading branch information
LumiFae committed Jan 3, 2025
1 parent f24a766 commit f89b9e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion DiscordLab.AdvancedLogging/API/Modules/GenerateEvent.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Reflection;
using System.Text.RegularExpressions;
using Discord.WebSocket;
using DiscordLab.Bot.API.Extensions;
using Exiled.API.Features;

namespace DiscordLab.AdvancedLogging.API.Modules
Expand Down Expand Up @@ -40,7 +41,7 @@ public static void Event(object ev, SocketTextChannel channel, string content, I
}
}

channel.SendMessageAsync(content);
channel.SendMessageAsync(content.LowercaseParams().StaticReplace());
}
}
}
15 changes: 8 additions & 7 deletions DiscordLab.Bot/API/Extensions/TranslationExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
using Exiled.API.Features;

Expand Down Expand Up @@ -101,30 +102,30 @@ public static string LowercaseParams(this string str)
str,
pattern,
m =>
m.Groups[1].Success ? m.Groups[1].Value.ToLower() : m.Groups[2].Value
m.Groups[1].Success ? $"{{{m.Groups[1].Value.ToLower()}}}" : m.Groups[2].Value
);
}

public static string StaticReplace(this string str)
{
string ret = str;
StringBuilder builder = new(str);
foreach ((string placeholder, Func<string> replaceWith) in StaticReplacers)
{
ret = str.Replace($"{{{placeholder}}}", replaceWith());
builder.Replace($"{{{placeholder}}}", replaceWith());
}

return ret;
return builder.ToString();
}

public static string PlayerReplace(this string str, string prefix, Player player)
{
string ret = str;
StringBuilder builder = new(str);
foreach ((string placeholder, Func<Player, string> replaceWith) in PlayerReplacers)
{
ret = str.Replace($"{{{prefix}{placeholder}}}", replaceWith(player));
builder.Replace($"{{{prefix}{placeholder}}}", replaceWith(player));
}

return ret;
return builder.ToString();
}
}
}

0 comments on commit f89b9e5

Please sign in to comment.