mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
feat(bot): config setting to pad 5-character ids in lists
This commit is contained in:
parent
0a6d4bcb76
commit
6d49961daf
7 changed files with 86 additions and 3 deletions
|
|
@ -542,6 +542,8 @@ public partial class CommandTree
|
||||||
return ctx.Execute<Config>(null, m => m.HidDisplaySplit(ctx));
|
return ctx.Execute<Config>(null, m => m.HidDisplaySplit(ctx));
|
||||||
if (ctx.MatchMultiple(new[] { "cap", "caps", "capitalize", "capitalise" }, new[] { "id", "ids" }) || ctx.Match("capid", "capids"))
|
if (ctx.MatchMultiple(new[] { "cap", "caps", "capitalize", "capitalise" }, new[] { "id", "ids" }) || ctx.Match("capid", "capids"))
|
||||||
return ctx.Execute<Config>(null, m => m.HidDisplayCaps(ctx));
|
return ctx.Execute<Config>(null, m => m.HidDisplayCaps(ctx));
|
||||||
|
if (ctx.MatchMultiple(new[] { "pad" }, new[] { "id", "ids" }) || ctx.MatchMultiple(new[] { "id" }, new[] { "pad", "padding" }) || ctx.Match("idpad", "padid", "padids"))
|
||||||
|
return ctx.Execute<Config>(null, m => m.HidListPadding(ctx));
|
||||||
|
|
||||||
// todo: maybe add the list of configuration keys here?
|
// todo: maybe add the list of configuration keys here?
|
||||||
return ctx.Reply($"{Emojis.Error} Could not find a setting with that name. Please see `pk;commands config` for the list of possible config settings.");
|
return ctx.Reply($"{Emojis.Error} Could not find a setting with that name. Please see `pk;commands config` for the list of possible config settings.");
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,13 @@ public class Config
|
||||||
"disabled"
|
"disabled"
|
||||||
));
|
));
|
||||||
|
|
||||||
|
items.Add(new(
|
||||||
|
"Pad IDs",
|
||||||
|
"Whether to pad 5-character IDs in lists (left/right)",
|
||||||
|
ctx.Config.HidListPadding.ToUserString(),
|
||||||
|
"off"
|
||||||
|
));
|
||||||
|
|
||||||
await ctx.Paginate<PaginatedConfigItem>(
|
await ctx.Paginate<PaginatedConfigItem>(
|
||||||
items.ToAsyncEnumerable(),
|
items.ToAsyncEnumerable(),
|
||||||
items.Count,
|
items.Count,
|
||||||
|
|
@ -485,4 +492,48 @@ public class Config
|
||||||
await ctx.Repository.UpdateSystemConfig(ctx.System.Id, new() { HidDisplayCaps = newVal });
|
await ctx.Repository.UpdateSystemConfig(ctx.System.Id, new() { HidDisplayCaps = newVal });
|
||||||
await ctx.Reply($"Displaying IDs as capital letters is now {EnabledDisabled(newVal)}.");
|
await ctx.Reply($"Displaying IDs as capital letters is now {EnabledDisabled(newVal)}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task HidListPadding(Context ctx)
|
||||||
|
{
|
||||||
|
if (!ctx.HasNext())
|
||||||
|
{
|
||||||
|
string message;
|
||||||
|
switch (ctx.Config.HidListPadding)
|
||||||
|
{
|
||||||
|
case SystemConfig.HidPadFormat.None: message = "Padding 5-character IDs in lists is currently disabled."; break;
|
||||||
|
case SystemConfig.HidPadFormat.Left: message = "5-character IDs displayed in lists will have a padding space added to the beginning."; break;
|
||||||
|
case SystemConfig.HidPadFormat.Right: message = "5-character IDs displayed in lists will have a padding space added to the end."; break;
|
||||||
|
default: throw new Exception("unreachable");
|
||||||
|
}
|
||||||
|
await ctx.Reply(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var badInputError = "Valid padding settings are `left`, `right`, or `off`.";
|
||||||
|
|
||||||
|
var toggleOff = ctx.MatchToggleOrNull(false);
|
||||||
|
|
||||||
|
switch (toggleOff)
|
||||||
|
{
|
||||||
|
case true: throw new PKError(badInputError);
|
||||||
|
case false:
|
||||||
|
{
|
||||||
|
await ctx.Repository.UpdateSystemConfig(ctx.System.Id, new() { HidListPadding = SystemConfig.HidPadFormat.None });
|
||||||
|
await ctx.Reply("Padding 5-character IDs in lists has been disabled.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx.Match("left", "l"))
|
||||||
|
{
|
||||||
|
await ctx.Repository.UpdateSystemConfig(ctx.System.Id, new() { HidListPadding = SystemConfig.HidPadFormat.Left });
|
||||||
|
await ctx.Reply("5-character IDs displayed in lists will now have a padding space added to the beginning.");
|
||||||
|
}
|
||||||
|
else if (ctx.Match("right", "r"))
|
||||||
|
{
|
||||||
|
await ctx.Repository.UpdateSystemConfig(ctx.System.Id, new() { HidListPadding = SystemConfig.HidPadFormat.Right });
|
||||||
|
await ctx.Reply("5-character IDs displayed in lists will now have a padding space added to the end.");
|
||||||
|
}
|
||||||
|
else throw new PKError(badInputError);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -128,7 +128,9 @@ 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 ret = $"[`{m.DisplayHid(ctx.Config)}`] **{m.NameFor(ctx)}** ";
|
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)}** ";
|
||||||
|
|
||||||
if (opts.IncludeMessageCount && m.MessageCountFor(lookupCtx) is { } count)
|
if (opts.IncludeMessageCount && m.MessageCountFor(lookupCtx) is { } count)
|
||||||
ret += $"({count} messages)";
|
ret += $"({count} messages)";
|
||||||
|
|
@ -238,7 +240,9 @@ 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 ret = $"[`{g.DisplayHid(ctx.Config)}`] **{g.NameFor(ctx)}** ";
|
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)}** ";
|
||||||
|
|
||||||
switch (opts.SortProperty)
|
switch (opts.SortProperty)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
6
PluralKit.Core/Database/Migrations/43.sql
Normal file
6
PluralKit.Core/Database/Migrations/43.sql
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
-- database version 43
|
||||||
|
-- add config setting for padding 5-character IDs in lists
|
||||||
|
|
||||||
|
alter table system_config add column hid_list_padding int not null default 0;
|
||||||
|
|
||||||
|
update info set schema_version = 43;
|
||||||
|
|
@ -9,7 +9,7 @@ namespace PluralKit.Core;
|
||||||
internal class DatabaseMigrator
|
internal class DatabaseMigrator
|
||||||
{
|
{
|
||||||
private const string RootPath = "PluralKit.Core.Database"; // "resource path" root for SQL files
|
private const string RootPath = "PluralKit.Core.Database"; // "resource path" root for SQL files
|
||||||
private const int TargetSchemaVersion = 42;
|
private const int TargetSchemaVersion = 43;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
public DatabaseMigrator(ILogger logger)
|
public DatabaseMigrator(ILogger logger)
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ public class SystemConfigPatch: PatchObject
|
||||||
public Partial<bool> ProxyErrorMessageEnabled { get; set; }
|
public Partial<bool> ProxyErrorMessageEnabled { get; set; }
|
||||||
public Partial<bool> HidDisplaySplit { get; set; }
|
public Partial<bool> HidDisplaySplit { get; set; }
|
||||||
public Partial<bool> HidDisplayCaps { get; set; }
|
public Partial<bool> HidDisplayCaps { get; set; }
|
||||||
|
public Partial<SystemConfig.HidPadFormat> HidListPadding { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||||
|
|
@ -37,6 +38,7 @@ public class SystemConfigPatch: PatchObject
|
||||||
.With("proxy_error_message_enabled", ProxyErrorMessageEnabled)
|
.With("proxy_error_message_enabled", ProxyErrorMessageEnabled)
|
||||||
.With("hid_display_split", HidDisplaySplit)
|
.With("hid_display_split", HidDisplaySplit)
|
||||||
.With("hid_display_caps", HidDisplayCaps)
|
.With("hid_display_caps", HidDisplayCaps)
|
||||||
|
.With("hid_list_padding", HidListPadding)
|
||||||
);
|
);
|
||||||
|
|
||||||
public new void AssertIsValid()
|
public new void AssertIsValid()
|
||||||
|
|
@ -98,6 +100,9 @@ public class SystemConfigPatch: PatchObject
|
||||||
if (HidDisplayCaps.IsPresent)
|
if (HidDisplayCaps.IsPresent)
|
||||||
o.Add("hid_display_caps", HidDisplayCaps.Value);
|
o.Add("hid_display_caps", HidDisplayCaps.Value);
|
||||||
|
|
||||||
|
if (HidListPadding.IsPresent)
|
||||||
|
o.Add("hid_list_padding", HidListPadding.Value.ToUserString());
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,14 @@ public class SystemConfig
|
||||||
public bool ProxyErrorMessageEnabled { get; }
|
public bool ProxyErrorMessageEnabled { get; }
|
||||||
public bool HidDisplaySplit { get; }
|
public bool HidDisplaySplit { get; }
|
||||||
public bool HidDisplayCaps { get; }
|
public bool HidDisplayCaps { get; }
|
||||||
|
public HidPadFormat HidListPadding { get; }
|
||||||
|
|
||||||
|
public enum HidPadFormat
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Left = 1,
|
||||||
|
Right = 2,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SystemConfigExt
|
public static class SystemConfigExt
|
||||||
|
|
@ -43,9 +51,16 @@ public static class SystemConfigExt
|
||||||
o.Add("proxy_error_message_enabled", cfg.ProxyErrorMessageEnabled);
|
o.Add("proxy_error_message_enabled", cfg.ProxyErrorMessageEnabled);
|
||||||
o.Add("hid_display_split", cfg.HidDisplaySplit);
|
o.Add("hid_display_split", cfg.HidDisplaySplit);
|
||||||
o.Add("hid_display_caps", cfg.HidDisplayCaps);
|
o.Add("hid_display_caps", cfg.HidDisplayCaps);
|
||||||
|
o.Add("hid_list_padding", cfg.HidListPadding.ToUserString());
|
||||||
|
|
||||||
o.Add("description_templates", JArray.FromObject(cfg.DescriptionTemplates));
|
o.Add("description_templates", JArray.FromObject(cfg.DescriptionTemplates));
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string ToUserString(this SystemConfig.HidPadFormat val)
|
||||||
|
{
|
||||||
|
if (val == SystemConfig.HidPadFormat.None) return "off";
|
||||||
|
return val.ToString().ToLower();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue