fix(bot): use proxy name format even when tag is disabled/null

This commit is contained in:
Iris System 2024-11-12 22:05:16 +13:00
parent b26ca69071
commit 2555f7922c

View file

@ -34,18 +34,16 @@ public class ProxyMember
// If not set, this formatting will be applied to the proxy name // If not set, this formatting will be applied to the proxy name
public static string DefaultFormat = "{name} {tag}"; public static string DefaultFormat = "{name} {tag}";
public static string FormatTag(string template, string tag, string name) => StringUtils.SafeFormat(template, new[] { public static string FormatTag(string template, string? tag, string name) => StringUtils.SafeFormat(template, new[] {
("{tag}", tag), ("{tag}", tag ?? ""),
("{name}", name) ("{name}", name)
}); }).Trim();
public string ProxyName(MessageContext ctx) public string ProxyName(MessageContext ctx)
{ {
// TODO: if tag is null it should still format but only if it appears in the formatting.
var memberName = ServerName ?? DisplayName ?? Name; var memberName = ServerName ?? DisplayName ?? Name;
var tag = ctx.SystemGuildTag ?? ctx.SystemTag; var tag = ctx.SystemGuildTag ?? ctx.SystemTag;
if (!ctx.TagEnabled || tag == null) if (!ctx.TagEnabled) tag = null;
return memberName;
return FormatTag(ctx.NameFormat ?? DefaultFormat, tag, memberName); return FormatTag(ctx.NameFormat ?? DefaultFormat, tag, memberName);
} }