fix(bot): clean up hid padding code

This commit is contained in:
alyssa 2024-06-04 18:56:28 +09:00
parent 80b685ae9b
commit 1f11dbf269
5 changed files with 24 additions and 14 deletions

View file

@ -66,7 +66,7 @@ public class GroupMember
if (groups.Count == 0) if (groups.Count == 0)
description = "This member has no groups."; description = "This member has no groups.";
else else
description = string.Join("\n", groups.Select(g => $"[`{g.DisplayHid(ctx.Config)}`] **{g.DisplayName ?? g.Name}**")); description = string.Join("\n", groups.Select(g => $"[`{g.DisplayHid(ctx.Config, isList: true)}`] **{g.DisplayName ?? g.Name}**"));
if (pctx == LookupContext.ByOwner) if (pctx == LookupContext.ByOwner)
{ {

View file

@ -128,9 +128,7 @@ public static class ContextListExt
// so run it through a helper that "makes it work" :) // so run it through a helper that "makes it work" :)
eb.WithSimpleLineContent(page.Select(m => eb.WithSimpleLineContent(page.Select(m =>
{ {
var leftpad = m.Hid.Length == 5 && ctx.Config?.HidListPadding == SystemConfig.HidPadFormat.Left ? " " : ""; var ret = $"[`{m.DisplayHid(ctx.Config, isList: true)}`] **{m.NameFor(ctx)}** ";
var rightpad = m.Hid.Length == 5 && ctx.Config?.HidListPadding == SystemConfig.HidPadFormat.Right ? " " : "";
var ret = $"[`{leftpad}{m.DisplayHid(ctx.Config)}{rightpad}`] **{m.NameFor(ctx)}** ";
if (opts.IncludeMessageCount && m.MessageCountFor(lookupCtx) is { } count) if (opts.IncludeMessageCount && m.MessageCountFor(lookupCtx) is { } count)
ret += $"({count} messages)"; ret += $"({count} messages)";
@ -240,9 +238,7 @@ public static class ContextListExt
// so run it through a helper that "makes it work" :) // so run it through a helper that "makes it work" :)
eb.WithSimpleLineContent(page.Select(g => eb.WithSimpleLineContent(page.Select(g =>
{ {
var leftpad = g.Hid.Length == 5 && ctx.Config?.HidListPadding == SystemConfig.HidPadFormat.Left ? " " : ""; var ret = $"[`{g.DisplayHid(ctx.Config, isList: true)}`] **{g.NameFor(ctx)}** ";
var rightpad = g.Hid.Length == 5 && ctx.Config?.HidListPadding == SystemConfig.HidPadFormat.Right ? " " : "";
var ret = $"[`{leftpad}{g.DisplayHid(ctx.Config)}{rightpad}`] **{g.NameFor(ctx)}** ";
switch (opts.SortProperty) switch (opts.SortProperty)
{ {

View file

@ -255,7 +255,7 @@ public class EmbedService
// More than 5 groups show in "compact" format without ID // More than 5 groups show in "compact" format without ID
var content = groups.Count > 5 var content = groups.Count > 5
? string.Join(", ", groups.Select(g => g.DisplayName ?? g.Name)) ? string.Join(", ", groups.Select(g => g.DisplayName ?? g.Name))
: string.Join("\n", groups.Select(g => $"[`{g.DisplayHid(ccfg)}`] **{g.DisplayName ?? g.Name}**")); : string.Join("\n", groups.Select(g => $"[`{g.DisplayHid(ccfg, isList: true)}`] **{g.DisplayName ?? g.Name}**"));
eb.Field(new Embed.Field($"Groups ({groups.Count})", content.Truncate(1000))); eb.Field(new Embed.Field($"Groups ({groups.Count})", content.Truncate(1000)));
} }

View file

@ -28,14 +28,15 @@ public static class ModelUtils
public static string Reference(this PKGroup group, Context ctx) => EntityReference(group.DisplayHid(ctx.Config), group.NameFor(ctx)); public static string Reference(this PKGroup group, Context ctx) => EntityReference(group.DisplayHid(ctx.Config), group.NameFor(ctx));
public static string DisplayHid(this PKSystem system, SystemConfig? cfg = null) => HidTransform(system.Hid, cfg); public static string DisplayHid(this PKSystem system, SystemConfig? cfg = null, bool isList = false) => HidTransform(system.Hid, cfg, isList);
public static string DisplayHid(this PKGroup group, SystemConfig? cfg = null) => HidTransform(group.Hid, cfg); public static string DisplayHid(this PKGroup group, SystemConfig? cfg = null, bool isList = false) => HidTransform(group.Hid, cfg, isList);
public static string DisplayHid(this PKMember member, SystemConfig? cfg = null) => HidTransform(member.Hid, cfg); public static string DisplayHid(this PKMember member, SystemConfig? cfg = null, bool isList = false) => HidTransform(member.Hid, cfg, isList);
private static string HidTransform(string hid, SystemConfig? cfg = null) => private static string HidTransform(string hid, SystemConfig? cfg = null, bool isList = false) =>
HidUtils.HidTransform( HidUtils.HidTransform(
hid, hid,
cfg != null && cfg.HidDisplaySplit, cfg != null && cfg.HidDisplaySplit,
cfg != null && cfg.HidDisplayCaps cfg != null && cfg.HidDisplayCaps,
isList ? (cfg?.HidListPadding ?? SystemConfig.HidPadFormat.None) : SystemConfig.HidPadFormat.None // padding only on lists
); );
private static string EntityReference(string hid, string name) private static string EntityReference(string hid, string name)

View file

@ -22,7 +22,7 @@ public static class HidUtils
return hid != null; return hid != null;
} }
public static string HidTransform(string input, bool split, bool caps) public static string HidTransform(string input, bool split, bool caps, SystemConfig.HidPadFormat pad)
{ {
if (split && input.Length > 5) if (split && input.Length > 5)
{ {
@ -33,6 +33,19 @@ public static class HidUtils
if (caps) if (caps)
input = input.ToUpper(); input = input.ToUpper();
if (input.Length == 5)
switch (pad)
{
case SystemConfig.HidPadFormat.Left:
input = " " + input;
if (split) input = " " + input;
break;
case SystemConfig.HidPadFormat.Right:
input = input + " ";
if (split) input = input + " ";
break;
}
return input; return input;
} }
} }