feat(bot): add option for hid capitalization

This commit is contained in:
Iris System 2024-04-28 21:05:46 +12:00
parent a3f1601938
commit 1ce9227b7d
7 changed files with 44 additions and 2 deletions

View file

@ -540,6 +540,8 @@ public partial class CommandTree
return ctx.Execute<Config>(null, m => m.ProxyErrorMessageEnabled(ctx)); return ctx.Execute<Config>(null, m => m.ProxyErrorMessageEnabled(ctx));
if (ctx.MatchMultiple(new[] { "split" }, new[] { "id", "ids" }) || ctx.Match("sid")) if (ctx.MatchMultiple(new[] { "split" }, new[] { "id", "ids" }) || ctx.Match("sid"))
return ctx.Execute<Config>(null, m => m.HidDisplaySplit(ctx)); return ctx.Execute<Config>(null, m => m.HidDisplaySplit(ctx));
if (ctx.MatchMultiple(new[] { "caps", "capitalize", "capitalise" }, new[] { "id", "ids" }) || ctx.Match("capid"))
return ctx.Execute<Config>(null, m => m.HidDisplayCaps(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.");

View file

@ -109,6 +109,13 @@ public class Config
"disabled" "disabled"
)); ));
items.Add(new(
"Capitalize IDs",
"Whether to display IDs as capital letters, to ease readability",
EnabledDisabled(ctx.Config.HidDisplayCaps),
"disabled"
));
await ctx.Paginate<PaginatedConfigItem>( await ctx.Paginate<PaginatedConfigItem>(
items.ToAsyncEnumerable(), items.ToAsyncEnumerable(),
items.Count, items.Count,
@ -464,4 +471,18 @@ public class Config
await ctx.Repository.UpdateSystemConfig(ctx.System.Id, new() { HidDisplaySplit = newVal }); await ctx.Repository.UpdateSystemConfig(ctx.System.Id, new() { HidDisplaySplit = newVal });
await ctx.Reply($"Splitting of 6-character IDs with a hyphen is now {EnabledDisabled(newVal)}."); await ctx.Reply($"Splitting of 6-character IDs with a hyphen is now {EnabledDisabled(newVal)}.");
} }
public async Task HidDisplayCaps(Context ctx)
{
if (!ctx.HasNext())
{
var msg = $"Displaying IDs as capital letters is currently **{EnabledDisabled(ctx.Config.HidDisplayCaps)}**.";
await ctx.Reply(msg);
return;
}
var newVal = ctx.MatchToggle(true);
await ctx.Repository.UpdateSystemConfig(ctx.System.Id, new() { HidDisplayCaps = newVal });
await ctx.Reply($"Displaying IDs as capital letters is now {EnabledDisabled(newVal)}.");
}
} }

View file

@ -31,7 +31,12 @@ public static class ModelUtils
public static string DisplayHid(this PKSystem system, SystemConfig? cfg = null) => HidTransform(system.Hid, cfg); 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 PKGroup group, SystemConfig? cfg = null) => HidTransform(group.Hid, cfg);
public static string DisplayHid(this PKMember member, SystemConfig? cfg = null) => HidTransform(member.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) => HidUtils.HidTransform(hid, cfg != null && cfg.HidDisplaySplit); private static string HidTransform(string hid, SystemConfig? cfg = null) =>
HidUtils.HidTransform(
hid,
cfg != null && cfg.HidDisplaySplit,
cfg != null && cfg.HidDisplayCaps
);
private static string EntityReference(string hid, string name) private static string EntityReference(string hid, string name)
{ {

View file

@ -6,5 +6,6 @@ alter table members alter column hid type char(6) using rpad(hid, 6, ' ');
alter table groups alter column hid type char(6) using rpad(hid, 6, ' '); alter table groups alter column hid type char(6) using rpad(hid, 6, ' ');
alter table system_config add column hid_display_split bool default false; alter table system_config add column hid_display_split bool default false;
alter table system_config add column hid_display_caps bool default false;
update info set schema_version = 42; update info set schema_version = 42;

View file

@ -22,7 +22,7 @@ public static class HidUtils
return hid != null; return hid != null;
} }
public static string HidTransform(string input, bool split = false) public static string HidTransform(string input, bool split, bool caps)
{ {
if (split && input.Length > 5) if (split && input.Length > 5)
{ {
@ -30,6 +30,9 @@ public static class HidUtils
input = string.Concat(input.AsSpan(0, len), "-", input.AsSpan(len)); input = string.Concat(input.AsSpan(0, len), "-", input.AsSpan(len));
} }
if (caps)
input = input.ToUpper();
return input; return input;
} }
} }

View file

@ -20,6 +20,7 @@ public class SystemConfigPatch: PatchObject
public Partial<bool> CaseSensitiveProxyTags { get; set; } public Partial<bool> CaseSensitiveProxyTags { get; set; }
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 override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
@ -35,6 +36,7 @@ public class SystemConfigPatch: PatchObject
.With("case_sensitive_proxy_tags", CaseSensitiveProxyTags) .With("case_sensitive_proxy_tags", CaseSensitiveProxyTags)
.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)
); );
public new void AssertIsValid() public new void AssertIsValid()
@ -93,6 +95,9 @@ public class SystemConfigPatch: PatchObject
if (HidDisplaySplit.IsPresent) if (HidDisplaySplit.IsPresent)
o.Add("hid_display_split", HidDisplaySplit.Value); o.Add("hid_display_split", HidDisplaySplit.Value);
if (HidDisplayCaps.IsPresent)
o.Add("hid_display_caps", HidDisplayCaps.Value);
return o; return o;
} }
@ -127,6 +132,9 @@ public class SystemConfigPatch: PatchObject
if (o.ContainsKey("hid_display_split")) if (o.ContainsKey("hid_display_split"))
patch.HidDisplaySplit = o.Value<bool>("hid_display_split"); patch.HidDisplaySplit = o.Value<bool>("hid_display_split");
if (o.ContainsKey("hid_display_caps"))
patch.HidDisplayCaps = o.Value<bool>("hid_display_caps");
return patch; return patch;
} }
} }

View file

@ -22,6 +22,7 @@ public class SystemConfig
public bool CaseSensitiveProxyTags { get; } public bool CaseSensitiveProxyTags { get; }
public bool ProxyErrorMessageEnabled { get; } public bool ProxyErrorMessageEnabled { get; }
public bool HidDisplaySplit { get; } public bool HidDisplaySplit { get; }
public bool HidDisplayCaps { get; }
} }
public static class SystemConfigExt public static class SystemConfigExt
@ -41,6 +42,7 @@ public static class SystemConfigExt
o.Add("case_sensitive_proxy_tags", cfg.CaseSensitiveProxyTags); o.Add("case_sensitive_proxy_tags", cfg.CaseSensitiveProxyTags);
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("description_templates", JArray.FromObject(cfg.DescriptionTemplates)); o.Add("description_templates", JArray.FromObject(cfg.DescriptionTemplates));