mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
fix(bot): clean up hid padding code
This commit is contained in:
parent
80b685ae9b
commit
1f11dbf269
5 changed files with 24 additions and 14 deletions
|
|
@ -66,7 +66,7 @@ public class GroupMember
|
|||
if (groups.Count == 0)
|
||||
description = "This member has no groups.";
|
||||
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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -128,9 +128,7 @@ public static class ContextListExt
|
|||
// so run it through a helper that "makes it work" :)
|
||||
eb.WithSimpleLineContent(page.Select(m =>
|
||||
{
|
||||
var leftpad = m.Hid.Length == 5 && ctx.Config?.HidListPadding == SystemConfig.HidPadFormat.Left ? " " : "";
|
||||
var rightpad = m.Hid.Length == 5 && ctx.Config?.HidListPadding == SystemConfig.HidPadFormat.Right ? " " : "";
|
||||
var ret = $"[`{leftpad}{m.DisplayHid(ctx.Config)}{rightpad}`] **{m.NameFor(ctx)}** ";
|
||||
var ret = $"[`{m.DisplayHid(ctx.Config, isList: true)}`] **{m.NameFor(ctx)}** ";
|
||||
|
||||
if (opts.IncludeMessageCount && m.MessageCountFor(lookupCtx) is { } count)
|
||||
ret += $"({count} messages)";
|
||||
|
|
@ -240,9 +238,7 @@ public static class ContextListExt
|
|||
// so run it through a helper that "makes it work" :)
|
||||
eb.WithSimpleLineContent(page.Select(g =>
|
||||
{
|
||||
var leftpad = g.Hid.Length == 5 && ctx.Config?.HidListPadding == SystemConfig.HidPadFormat.Left ? " " : "";
|
||||
var rightpad = g.Hid.Length == 5 && ctx.Config?.HidListPadding == SystemConfig.HidPadFormat.Right ? " " : "";
|
||||
var ret = $"[`{leftpad}{g.DisplayHid(ctx.Config)}{rightpad}`] **{g.NameFor(ctx)}** ";
|
||||
var ret = $"[`{g.DisplayHid(ctx.Config, isList: true)}`] **{g.NameFor(ctx)}** ";
|
||||
|
||||
switch (opts.SortProperty)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ public class EmbedService
|
|||
// More than 5 groups show in "compact" format without ID
|
||||
var content = groups.Count > 5
|
||||
? 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)));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 DisplayHid(this PKSystem system, SystemConfig? cfg = null) => HidTransform(system.Hid, cfg);
|
||||
public static string DisplayHid(this PKGroup group, SystemConfig? cfg = null) => HidTransform(group.Hid, cfg);
|
||||
public static string DisplayHid(this PKMember member, SystemConfig? cfg = null) => HidTransform(member.Hid, cfg);
|
||||
private static string HidTransform(string hid, SystemConfig? cfg = null) =>
|
||||
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, bool isList = false) => HidTransform(group.Hid, cfg, isList);
|
||||
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, bool isList = false) =>
|
||||
HidUtils.HidTransform(
|
||||
hid,
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public static class HidUtils
|
|||
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)
|
||||
{
|
||||
|
|
@ -33,6 +33,19 @@ public static class HidUtils
|
|||
if (caps)
|
||||
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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue