mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-11 16:20:13 +00:00
feat: initial 6-character HID rework
This commit is contained in:
parent
73f43b8cb3
commit
9f56697241
30 changed files with 208 additions and 91 deletions
|
|
@ -29,9 +29,9 @@ public class Admin
|
|||
if (target == null)
|
||||
throw new PKError("Unknown system.");
|
||||
|
||||
var newHid = ctx.PopArgument();
|
||||
if (!Regex.IsMatch(newHid, "^[a-z]{5}$"))
|
||||
throw new PKError($"Invalid new system ID `{newHid}`.");
|
||||
var input = ctx.PopArgument();
|
||||
if (!input.TryParseHid(out var newHid))
|
||||
throw new PKError($"Invalid new system ID `{input}`.");
|
||||
|
||||
var existingSystem = await ctx.Repository.GetSystemByHid(newHid);
|
||||
if (existingSystem != null)
|
||||
|
|
@ -52,9 +52,9 @@ public class Admin
|
|||
if (target == null)
|
||||
throw new PKError("Unknown member.");
|
||||
|
||||
var newHid = ctx.PopArgument();
|
||||
if (!Regex.IsMatch(newHid, "^[a-z]{5}$"))
|
||||
throw new PKError($"Invalid new member ID `{newHid}`.");
|
||||
var input = ctx.PopArgument();
|
||||
if (!input.TryParseHid(out var newHid))
|
||||
throw new PKError($"Invalid new member ID `{input}`.");
|
||||
|
||||
var existingMember = await ctx.Repository.GetMemberByHid(newHid);
|
||||
if (existingMember != null)
|
||||
|
|
@ -78,9 +78,9 @@ public class Admin
|
|||
if (target == null)
|
||||
throw new PKError("Unknown group.");
|
||||
|
||||
var newHid = ctx.PopArgument();
|
||||
if (!Regex.IsMatch(newHid, "^[a-z]{5}$"))
|
||||
throw new PKError($"Invalid new group ID `{newHid}`.");
|
||||
var input = ctx.PopArgument();
|
||||
if (!input.TryParseHid(out var newHid))
|
||||
throw new PKError($"Invalid new group ID `{input}`.");
|
||||
|
||||
var existingGroup = await ctx.Repository.GetGroupByHid(newHid);
|
||||
if (existingGroup != null)
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ public class Autoproxy
|
|||
{
|
||||
if (relevantMember == null)
|
||||
throw new ArgumentException("Attempted to print member autoproxy status, but the linked member ID wasn't found in the database. Should be handled appropriately.");
|
||||
eb.Description($"Autoproxy is currently set to **front mode** in this server. The current (first) fronter is **{relevantMember.NameFor(ctx).EscapeMarkdown()}** (`{relevantMember.Hid}`). To disable, type `pk;autoproxy off`.");
|
||||
eb.Description($"Autoproxy is currently set to **front mode** in this server. The current (first) fronter is **{relevantMember.NameFor(ctx).EscapeMarkdown()}** (`{relevantMember.DisplayHid(ctx.Config)}`). To disable, type `pk;autoproxy off`.");
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -142,7 +142,7 @@ public class Autoproxy
|
|||
// ideally we would set it to off in the database though...
|
||||
eb.Description($"Autoproxy is currently **off** in this server. To enable it, use one of the following commands:\n{commandList}");
|
||||
else
|
||||
eb.Description($"Autoproxy is active for member **{relevantMember.NameFor(ctx)}** (`{relevantMember.Hid}`) in this server. To disable, type `pk;autoproxy off`.");
|
||||
eb.Description($"Autoproxy is active for member **{relevantMember.NameFor(ctx)}** (`{relevantMember.DisplayHid(ctx.Config)}`) in this server. To disable, type `pk;autoproxy off`.");
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -150,7 +150,7 @@ public class Autoproxy
|
|||
if (relevantMember == null)
|
||||
eb.Description("Autoproxy is currently set to **latch mode**, meaning the *last-proxied member* will be autoproxied. **No member is currently latched.** To disable, type `pk;autoproxy off`.");
|
||||
else
|
||||
eb.Description($"Autoproxy is currently set to **latch mode**, meaning the *last-proxied member* will be autoproxied. The currently latched member is **{relevantMember.NameFor(ctx)}** (`{relevantMember.Hid}`). To disable, type `pk;autoproxy off`.");
|
||||
eb.Description($"Autoproxy is currently set to **latch mode**, meaning the *last-proxied member* will be autoproxied. The currently latched member is **{relevantMember.NameFor(ctx)}** (`{relevantMember.DisplayHid(ctx.Config)}`). To disable, type `pk;autoproxy off`.");
|
||||
|
||||
break;
|
||||
|
||||
|
|
|
|||
|
|
@ -102,6 +102,13 @@ public class Config
|
|||
"enabled"
|
||||
));
|
||||
|
||||
items.Add(new(
|
||||
"Split IDs",
|
||||
"Whether to display 6-character IDs split with a hyphen, to ease readability",
|
||||
EnabledDisabled(ctx.Config.HidDisplaySplit),
|
||||
"disabled"
|
||||
));
|
||||
|
||||
await ctx.Paginate<PaginatedConfigItem>(
|
||||
items.ToAsyncEnumerable(),
|
||||
items.Count,
|
||||
|
|
@ -443,4 +450,18 @@ public class Config
|
|||
await ctx.Reply("Proxy error messages are now disabled. Messages that fail to proxy (due to message or attachment size) will not throw an error message.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task HidDisplaySplit(Context ctx)
|
||||
{
|
||||
if (!ctx.HasNext())
|
||||
{
|
||||
var msg = $"Splitting of 6-character IDs with a hyphen is currently **{EnabledDisabled(ctx.Config.HidDisplaySplit)}**.";
|
||||
await ctx.Reply(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
var newVal = ctx.MatchToggle(true);
|
||||
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)}.");
|
||||
}
|
||||
}
|
||||
|
|
@ -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.Hid}`] **{g.DisplayName ?? g.Name}**"));
|
||||
description = string.Join("\n", groups.Select(g => $"[`{g.DisplayHid(ctx.Config)}`] **{g.DisplayName ?? g.Name}**"));
|
||||
|
||||
if (pctx == LookupContext.ByOwner)
|
||||
{
|
||||
|
|
@ -130,23 +130,23 @@ public class GroupMember
|
|||
var opts = ctx.ParseListOptions(ctx.DirectLookupContextFor(target.System));
|
||||
opts.GroupFilter = target.Id;
|
||||
|
||||
var title = new StringBuilder($"Members of {target.DisplayName ?? target.Name} (`{target.Hid}`) in ");
|
||||
var title = new StringBuilder($"Members of {target.DisplayName ?? target.Name} (`{target.DisplayHid(ctx.Config)}`) in ");
|
||||
if (ctx.Guild != null)
|
||||
{
|
||||
var guildSettings = await ctx.Repository.GetSystemGuild(ctx.Guild.Id, targetSystem.Id);
|
||||
if (guildSettings.DisplayName != null)
|
||||
title.Append($"{guildSettings.DisplayName} (`{targetSystem.Hid}`)");
|
||||
title.Append($"{guildSettings.DisplayName} (`{targetSystem.DisplayHid(ctx.Config)}`)");
|
||||
else if (targetSystem.NameFor(ctx) != null)
|
||||
title.Append($"{targetSystem.NameFor(ctx)} (`{targetSystem.Hid}`)");
|
||||
title.Append($"{targetSystem.NameFor(ctx)} (`{targetSystem.DisplayHid(ctx.Config)}`)");
|
||||
else
|
||||
title.Append($"`{targetSystem.Hid}`");
|
||||
title.Append($"`{targetSystem.DisplayHid(ctx.Config)}`");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (targetSystem.NameFor(ctx) != null)
|
||||
title.Append($"{targetSystem.NameFor(ctx)} (`{targetSystem.Hid}`)");
|
||||
title.Append($"{targetSystem.NameFor(ctx)} (`{targetSystem.DisplayHid(ctx.Config)}`)");
|
||||
else
|
||||
title.Append($"`{targetSystem.Hid}`");
|
||||
title.Append($"`{targetSystem.DisplayHid(ctx.Config)}`");
|
||||
}
|
||||
if (opts.Search != null)
|
||||
title.Append($" matching **{opts.Search.Truncate(100)}**");
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class Groups
|
|||
if (existingGroup != null)
|
||||
{
|
||||
var msg =
|
||||
$"{Emojis.Warn} You already have a group in your system with the name \"{existingGroup.Name}\" (with ID `{existingGroup.Hid}`). Do you want to create another group with the same name?";
|
||||
$"{Emojis.Warn} You already have a group in your system with the name \"{existingGroup.Name}\" (with ID `{existingGroup.DisplayHid(ctx.Config)}`). Do you want to create another group with the same name?";
|
||||
if (!await ctx.PromptYesNo(msg, "Create"))
|
||||
throw new PKError("Group creation cancelled.");
|
||||
}
|
||||
|
|
@ -83,7 +83,7 @@ public class Groups
|
|||
|
||||
var eb = new EmbedBuilder()
|
||||
.Description(
|
||||
$"Your new group, **{groupName}**, has been created, with the group ID **`{newGroup.Hid}`**.\nBelow are a couple of useful commands:")
|
||||
$"Your new group, **{groupName}**, has been created, with the group ID **`{newGroup.DisplayHid(ctx.Config)}`**.\nBelow are a couple of useful commands:")
|
||||
.Field(new Embed.Field("View the group card", $"> pk;group **{reference}**"))
|
||||
.Field(new Embed.Field("Add members to the group",
|
||||
$"> pk;group **{reference}** add **MemberName**\n> pk;group **{reference}** add **Member1** **Member2** **Member3** (and so on...)"))
|
||||
|
|
@ -113,7 +113,7 @@ public class Groups
|
|||
if (existingGroup != null && existingGroup.Id != target.Id)
|
||||
{
|
||||
var msg =
|
||||
$"{Emojis.Warn} You already have a group in your system with the name \"{existingGroup.Name}\" (with ID `{existingGroup.Hid}`). Do you want to rename this group to that name too?";
|
||||
$"{Emojis.Warn} You already have a group in your system with the name \"{existingGroup.Name}\" (with ID `{existingGroup.DisplayHid(ctx.Config)}`). Do you want to rename this group to that name too?";
|
||||
if (!await ctx.PromptYesNo(msg, "Rename"))
|
||||
throw new PKError("Group rename cancelled.");
|
||||
}
|
||||
|
|
@ -450,20 +450,20 @@ public class Groups
|
|||
await ctx.RenderGroupList(
|
||||
ctx.LookupContextFor(system.Id),
|
||||
system.Id,
|
||||
GetEmbedTitle(system, opts),
|
||||
GetEmbedTitle(ctx, system, opts),
|
||||
system.Color,
|
||||
opts
|
||||
);
|
||||
}
|
||||
|
||||
private string GetEmbedTitle(PKSystem target, ListOptions opts)
|
||||
private string GetEmbedTitle(Context ctx, PKSystem target, ListOptions opts)
|
||||
{
|
||||
var title = new StringBuilder("Groups of ");
|
||||
|
||||
if (target.Name != null)
|
||||
title.Append($"{target.Name} (`{target.Hid}`)");
|
||||
title.Append($"{target.Name} (`{target.DisplayHid(ctx.Config)}`)");
|
||||
else
|
||||
title.Append($"`{target.Hid}`");
|
||||
title.Append($"`{target.DisplayHid(ctx.Config)}`");
|
||||
|
||||
if (opts.Search != null)
|
||||
title.Append($" matching **{opts.Search}**");
|
||||
|
|
@ -586,7 +586,7 @@ public class Groups
|
|||
|
||||
public async Task DisplayId(Context ctx, PKGroup target)
|
||||
{
|
||||
await ctx.Reply(target.Hid);
|
||||
await ctx.Reply(target.DisplayHid(ctx.Config));
|
||||
}
|
||||
|
||||
private async Task<PKSystem> GetGroupSystem(Context ctx, PKGroup target)
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ public static class ContextListExt
|
|||
// so run it through a helper that "makes it work" :)
|
||||
eb.WithSimpleLineContent(page.Select(m =>
|
||||
{
|
||||
var ret = $"[`{m.Hid}`] **{m.NameFor(ctx)}** ";
|
||||
var ret = $"[`{m.DisplayHid(ctx.Config)}`] **{m.NameFor(ctx)}** ";
|
||||
|
||||
if (opts.IncludeMessageCount && m.MessageCountFor(lookupCtx) is { } count)
|
||||
ret += $"({count} messages)";
|
||||
|
|
@ -162,7 +162,7 @@ public static class ContextListExt
|
|||
{
|
||||
foreach (var m in page)
|
||||
{
|
||||
var profile = new StringBuilder($"**ID**: {m.Hid}");
|
||||
var profile = new StringBuilder($"**ID**: {m.DisplayHid(ctx.Config)}");
|
||||
|
||||
if (m.DisplayName != null && m.NamePrivacy.CanAccess(lookupCtx))
|
||||
profile.Append($"\n**Display name**: {m.DisplayName}");
|
||||
|
|
@ -238,7 +238,7 @@ public static class ContextListExt
|
|||
// so run it through a helper that "makes it work" :)
|
||||
eb.WithSimpleLineContent(page.Select(g =>
|
||||
{
|
||||
var ret = $"[`{g.Hid}`] **{g.NameFor(ctx)}** ";
|
||||
var ret = $"[`{g.DisplayHid(ctx.Config)}`] **{g.NameFor(ctx)}** ";
|
||||
|
||||
switch (opts.SortProperty)
|
||||
{
|
||||
|
|
@ -308,7 +308,7 @@ public static class ContextListExt
|
|||
{
|
||||
foreach (var g in page)
|
||||
{
|
||||
var profile = new StringBuilder($"**ID**: {g.Hid}");
|
||||
var profile = new StringBuilder($"**ID**: {g.DisplayHid(ctx.Config)}");
|
||||
|
||||
if (g.DisplayName != null && g.NamePrivacy.CanAccess(lookupCtx))
|
||||
profile.Append($"\n**Display name**: {g.DisplayName}");
|
||||
|
|
|
|||
|
|
@ -101,12 +101,12 @@ public class Member
|
|||
|
||||
// Send confirmation and space hint
|
||||
await ctx.Reply(
|
||||
$"{Emojis.Success} Member \"{memberName}\" (`{member.Hid}`) registered! Check out the getting started page for how to get a member up and running: https://pluralkit.me/start#create-a-member");
|
||||
$"{Emojis.Success} Member \"{memberName}\" (`{member.DisplayHid(ctx.Config)}`) registered! Check out the getting started page for how to get a member up and running: https://pluralkit.me/start#create-a-member");
|
||||
// todo: move this to ModelRepository
|
||||
if (await ctx.Database.Execute(conn => conn.QuerySingleAsync<bool>("select has_private_members(@System)",
|
||||
new { System = ctx.System.Id })) && !ctx.Config.MemberDefaultPrivate) //if has private members
|
||||
await ctx.Reply(
|
||||
$"{Emojis.Warn} This member is currently **public**. To change this, use `pk;member {member.Hid} private`.");
|
||||
$"{Emojis.Warn} This member is currently **public**. To change this, use `pk;member {member.DisplayHid(ctx.Config)} private`.");
|
||||
if (avatarArg != null)
|
||||
if (imageMatchError == null)
|
||||
await ctx.Reply(
|
||||
|
|
@ -115,7 +115,7 @@ public class Member
|
|||
await ctx.Reply($"{Emojis.Error} Couldn't set avatar: {imageMatchError.Message}");
|
||||
if (memberName.Contains(" "))
|
||||
await ctx.Reply(
|
||||
$"{Emojis.Note} Note that this member's name contains spaces. You will need to surround it with \"double quotes\" when using commands referring to it, or just use the member's 5-character ID (which is `{member.Hid}`).");
|
||||
$"{Emojis.Note} Note that this member's name contains spaces. You will need to surround it with \"double quotes\" when using commands referring to it, or just use the member's short ID (which is `{member.DisplayHid(ctx.Config)}`).");
|
||||
if (memberCount >= memberLimit)
|
||||
await ctx.Reply(
|
||||
$"{Emojis.Warn} You have reached the per-system member limit ({memberLimit}). If you need to add more members, you can either delete existing members, or ask for your limit to be raised in the PluralKit support server: <https://discord.gg/PczBt78>");
|
||||
|
|
@ -128,7 +128,7 @@ public class Member
|
|||
{
|
||||
var system = await ctx.Repository.GetSystem(target.System);
|
||||
await ctx.Reply(
|
||||
embed: await _embeds.CreateMemberEmbed(system, target, ctx.Guild, ctx.LookupContextFor(system.Id), ctx.Zone));
|
||||
embed: await _embeds.CreateMemberEmbed(system, target, ctx.Guild, ctx.Config, ctx.LookupContextFor(system.Id), ctx.Zone));
|
||||
}
|
||||
|
||||
public async Task Soulscream(Context ctx, PKMember target)
|
||||
|
|
@ -156,6 +156,6 @@ public class Member
|
|||
|
||||
public async Task DisplayId(Context ctx, PKMember target)
|
||||
{
|
||||
await ctx.Reply(target.Hid);
|
||||
await ctx.Reply(target.DisplayHid(ctx.Config));
|
||||
}
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ public class MemberEdit
|
|||
if (existingMember != null && existingMember.Id != target.Id)
|
||||
{
|
||||
var msg =
|
||||
$"{Emojis.Warn} You already have a member in your system with the name \"{existingMember.NameFor(ctx)}\" (`{existingMember.Hid}`). Do you want to rename this member to that name too?";
|
||||
$"{Emojis.Warn} You already have a member in your system with the name \"{existingMember.NameFor(ctx)}\" (`{existingMember.DisplayHid(ctx.Config)}`). Do you want to rename this member to that name too?";
|
||||
if (!await ctx.PromptYesNo(msg, "Rename")) throw new PKError("Member renaming cancelled.");
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ public class MemberEdit
|
|||
await ctx.Reply($"{Emojis.Success} Member renamed (using {newName.Length}/{Limits.MaxMemberNameLength} characters).");
|
||||
if (newName.Contains(" "))
|
||||
await ctx.Reply(
|
||||
$"{Emojis.Note} Note that this member's name now contains spaces. You will need to surround it with \"double quotes\" when using commands referring to it, or just use the member's 5-character ID (which is `{target.Hid}`).");
|
||||
$"{Emojis.Note} Note that this member's name now contains spaces. You will need to surround it with \"double quotes\" when using commands referring to it, or just use the member's short ID (which is `{target.DisplayHid(ctx.Config)}`).");
|
||||
if (target.DisplayName != null)
|
||||
await ctx.Reply(
|
||||
$"{Emojis.Note} Note that this member has a display name set ({target.DisplayName}), and will be proxied using that name instead.");
|
||||
|
|
@ -211,7 +211,7 @@ public class MemberEdit
|
|||
var eb = new EmbedBuilder()
|
||||
.Title($"{target.NameFor(ctx)}'s banner image")
|
||||
.Image(new Embed.EmbedImage(target.BannerImage))
|
||||
.Description($"To clear, use `pk;member {target.Hid} banner clear`.");
|
||||
.Description($"To clear, use `pk;member {target.Reference(ctx)} banner clear`.");
|
||||
await ctx.Reply(embed: eb.Build());
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class Random
|
|||
|
||||
var randInt = randGen.Next(members.Count);
|
||||
await ctx.Reply(embed: await _embeds.CreateMemberEmbed(target, members[randInt], ctx.Guild,
|
||||
ctx.LookupContextFor(target.Id), ctx.Zone));
|
||||
ctx.Config, ctx.LookupContextFor(target.Id), ctx.Zone));
|
||||
}
|
||||
|
||||
public async Task Group(Context ctx, PKSystem target)
|
||||
|
|
@ -93,6 +93,6 @@ public class Random
|
|||
|
||||
var randInt = randGen.Next(ms.Count);
|
||||
await ctx.Reply(embed: await _embeds.CreateMemberEmbed(system, ms[randInt], ctx.Guild,
|
||||
ctx.LookupContextFor(group.System), ctx.Zone));
|
||||
ctx.Config, ctx.LookupContextFor(group.System), ctx.Zone));
|
||||
}
|
||||
}
|
||||
|
|
@ -39,6 +39,6 @@ public class System
|
|||
if (target == null)
|
||||
throw Errors.NoSystemError;
|
||||
|
||||
await ctx.Reply(target.Hid);
|
||||
await ctx.Reply(target.DisplayHid(ctx.Config));
|
||||
}
|
||||
}
|
||||
|
|
@ -33,11 +33,11 @@ public class SystemList
|
|||
|
||||
var systemGuildSettings = ctx.Guild != null ? await ctx.Repository.GetSystemGuild(ctx.Guild.Id, target.Id) : null;
|
||||
if (systemGuildSettings != null && systemGuildSettings.DisplayName != null)
|
||||
title.Append($"{systemGuildSettings.DisplayName} (`{target.Hid}`)");
|
||||
title.Append($"{systemGuildSettings.DisplayName} (`{target.DisplayHid(ctx.Config)}`)");
|
||||
else if (target.NameFor(ctx) != null)
|
||||
title.Append($"{target.NameFor(ctx)} (`{target.Hid}`)");
|
||||
title.Append($"{target.NameFor(ctx)} (`{target.DisplayHid(ctx.Config)}`)");
|
||||
else
|
||||
title.Append($"`{target.Hid}`");
|
||||
title.Append($"`{target.DisplayHid(ctx.Config)}`");
|
||||
|
||||
if (opts.Search != null)
|
||||
title.Append($" matching **{opts.Search.Truncate(100)}**");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue