Skip to content

Commit

Permalink
fix: NRE with PlayerReplace
Browse files Browse the repository at this point in the history
  • Loading branch information
LumiFae committed Jan 4, 2025
1 parent c3ecc72 commit dbdb015
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion DiscordLab.Bot/API/Extensions/TranslationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,17 @@ public static string PlayerReplace(this string str, string prefix, Player player
StringBuilder builder = new(str);
foreach ((string placeholder, Func<Player, string> replaceWith) in PlayerReplacers)
{
builder.Replace($"{{{prefix}{placeholder}}}", replaceWith(player));
string replacement;
try
{
replacement = replaceWith(player);
}
catch (NullReferenceException)
{
replacement = "Unknown";
}
if(string.IsNullOrEmpty(replacement)) replacement = "Unknown";
builder.Replace($"{{{prefix}{placeholder}}}", replacement);
}

return builder.ToString();
Expand Down

0 comments on commit dbdb015

Please sign in to comment.