implement show-embed flags

This commit is contained in:
dusk 2025-09-26 18:47:54 +00:00
parent 02a99025dc
commit c00ff2f371
No known key found for this signature in database
8 changed files with 24 additions and 20 deletions

View file

@ -8,12 +8,12 @@ public partial class CommandTree
{ {
return command switch return command switch
{ {
Commands.Help => ctx.Execute<Help>(Help, m => m.HelpRoot(ctx)), Commands.Help(_, var flags) => ctx.Execute<Help>(Help, m => m.HelpRoot(ctx, flags.show_embed)),
Commands.HelpCommands => ctx.Reply( Commands.HelpCommands => ctx.Reply(
"For the list of commands, see the website: <https://pluralkit.me/commands>"), "For the list of commands, see the website: <https://pluralkit.me/commands>"),
Commands.HelpProxy => ctx.Reply( Commands.HelpProxy => ctx.Reply(
"The proxy help page has been moved! See the website: https://pluralkit.me/guide#proxying"), "The proxy help page has been moved! See the website: https://pluralkit.me/guide#proxying"),
Commands.MemberShow(var param, _) => ctx.Execute<Member>(MemberInfo, m => m.ViewMember(ctx, param.target)), Commands.MemberShow(var param, var flags) => ctx.Execute<Member>(MemberInfo, m => m.ViewMember(ctx, param.target, flags.show_embed)),
Commands.MemberNew(var param, _) => ctx.Execute<Member>(MemberNew, m => m.NewMember(ctx, param.name)), Commands.MemberNew(var param, _) => ctx.Execute<Member>(MemberNew, m => m.NewMember(ctx, param.name)),
Commands.MemberSoulscream(var param, _) => ctx.Execute<Member>(MemberInfo, m => m.Soulscream(ctx, param.target)), Commands.MemberSoulscream(var param, _) => ctx.Execute<Member>(MemberInfo, m => m.Soulscream(ctx, param.target)),
Commands.MemberAvatarShow(var param, var flags) => ctx.Execute<MemberAvatar>(MemberAvatar, m => m.ShowAvatar(ctx, param.target, flags.GetReplyFormat())), Commands.MemberAvatarShow(var param, var flags) => ctx.Execute<MemberAvatar>(MemberAvatar, m => m.ShowAvatar(ctx, param.target, flags.GetReplyFormat())),

View file

@ -517,10 +517,10 @@ public class Groups
return title.ToString(); return title.ToString();
} }
public async Task ShowGroupCard(Context ctx, PKGroup target) public async Task ShowGroupCard(Context ctx, PKGroup target, bool showEmbed = false)
{ {
var system = await GetGroupSystem(ctx, target); var system = await GetGroupSystem(ctx, target);
if (ctx.MatchFlag("show-embed", "se")) if (showEmbed)
{ {
await ctx.Reply(text: EmbedService.LEGACY_EMBED_WARNING, embed: await _embeds.CreateGroupEmbed(ctx, system, target)); await ctx.Reply(text: EmbedService.LEGACY_EMBED_WARNING, embed: await _embeds.CreateGroupEmbed(ctx, system, target));
return; return;

View file

@ -7,9 +7,9 @@ namespace PluralKit.Bot;
public class Help public class Help
{ {
public Task HelpRoot(Context ctx) public Task HelpRoot(Context ctx, bool showEmbed = false)
{ {
if (ctx.MatchFlag("show-embed", "se")) if (showEmbed)
return HelpRootOld(ctx); return HelpRootOld(ctx);
return ctx.Reply(BuildComponents(ctx.Author.Id, Help.Description.Replace("{prefix}", ctx.DefaultPrefix), -1)); return ctx.Reply(BuildComponents(ctx.Author.Id, Help.Description.Replace("{prefix}", ctx.DefaultPrefix), -1));

View file

@ -120,10 +120,10 @@ public class Member
await ctx.Reply(replyStr); await ctx.Reply(replyStr);
} }
public async Task ViewMember(Context ctx, PKMember target) public async Task ViewMember(Context ctx, PKMember target, bool showEmbed = false)
{ {
var system = await ctx.Repository.GetSystem(target.System); var system = await ctx.Repository.GetSystem(target.System);
if (ctx.MatchFlag("show-embed", "se")) if (showEmbed)
{ {
await ctx.Reply( await ctx.Reply(
text: EmbedService.LEGACY_EMBED_WARNING, text: EmbedService.LEGACY_EMBED_WARNING,

View file

@ -15,7 +15,7 @@ public class Random
// todo: get postgresql to return one random member/group instead of querying all members/groups // todo: get postgresql to return one random member/group instead of querying all members/groups
public async Task Member(Context ctx, PKSystem target) public async Task Member(Context ctx, PKSystem target, bool showEmbed = false)
{ {
if (target == null) if (target == null)
throw Errors.NoSystemError(ctx.DefaultPrefix); throw Errors.NoSystemError(ctx.DefaultPrefix);
@ -37,7 +37,7 @@ public class Random
var randInt = randGen.Next(members.Count); var randInt = randGen.Next(members.Count);
if (ctx.MatchFlag("show-embed", "se")) if (showEmbed)
{ {
await ctx.Reply( await ctx.Reply(
text: EmbedService.LEGACY_EMBED_WARNING, text: EmbedService.LEGACY_EMBED_WARNING,
@ -49,7 +49,7 @@ public class Random
components: await _embeds.CreateMemberMessageComponents(target, members[randInt], ctx.Guild, ctx.Config, ctx.LookupContextFor(target.Id), ctx.Zone)); components: await _embeds.CreateMemberMessageComponents(target, members[randInt], ctx.Guild, ctx.Config, ctx.LookupContextFor(target.Id), ctx.Zone));
} }
public async Task Group(Context ctx, PKSystem target) public async Task Group(Context ctx, PKSystem target, bool showEmbed = false)
{ {
if (target == null) if (target == null)
throw Errors.NoSystemError(ctx.DefaultPrefix); throw Errors.NoSystemError(ctx.DefaultPrefix);
@ -70,7 +70,7 @@ public class Random
var randInt = randGen.Next(groups.Count()); var randInt = randGen.Next(groups.Count());
if (ctx.MatchFlag("show-embed", "se")) if (showEmbed)
{ {
await ctx.Reply( await ctx.Reply(
text: EmbedService.LEGACY_EMBED_WARNING, text: EmbedService.LEGACY_EMBED_WARNING,
@ -82,7 +82,7 @@ public class Random
components: await _embeds.CreateGroupMessageComponents(ctx, target, groups.ToArray()[randInt])); components: await _embeds.CreateGroupMessageComponents(ctx, target, groups.ToArray()[randInt]));
} }
public async Task GroupMember(Context ctx, PKGroup group) public async Task GroupMember(Context ctx, PKGroup group, bool showEmbed = false)
{ {
ctx.CheckSystemPrivacy(group.System, group.ListPrivacy); ctx.CheckSystemPrivacy(group.System, group.ListPrivacy);
@ -112,7 +112,7 @@ public class Random
var randInt = randGen.Next(ms.Count); var randInt = randGen.Next(ms.Count);
if (ctx.MatchFlag("show-embed", "se")) if (showEmbed)
{ {
await ctx.Reply( await ctx.Reply(
text: EmbedService.LEGACY_EMBED_WARNING, text: EmbedService.LEGACY_EMBED_WARNING,

View file

@ -14,16 +14,16 @@ public class System
_embeds = embeds; _embeds = embeds;
} }
public async Task Query(Context ctx, PKSystem system, bool all, bool @public, bool @private) public async Task Query(Context ctx, PKSystem system, bool all, bool @public, bool @private, bool showEmbed = false)
{ {
if (system == null) throw Errors.NoSystemError(ctx.DefaultPrefix); if (system == null) throw Errors.NoSystemError(ctx.DefaultPrefix);
if (ctx.MatchFlag("show-embed", "se")) if (showEmbed)
{ {
await ctx.Reply(text: EmbedService.LEGACY_EMBED_WARNING, embed: await _embeds.CreateSystemEmbed(ctx, system, ctx.LookupContextFor(system.Id), all)); await ctx.Reply(text: EmbedService.LEGACY_EMBED_WARNING, embed: await _embeds.CreateSystemEmbed(ctx, system, ctx.LookupContextFor(system.Id), all));
return; return;
} }
await ctx.Reply(components: await _embeds.CreateSystemMessageComponents(ctx, system, ctx.LookupContextFor(system.Id))); await ctx.Reply(components: await _embeds.CreateSystemMessageComponents(ctx, system, ctx.LookupContextFor(system.Id), all));
} }
public async Task New(Context ctx, string? systemName) public async Task New(Context ctx, string? systemName)

View file

@ -43,7 +43,7 @@ public class EmbedService
return Task.WhenAll(ids.Select(Inner)); return Task.WhenAll(ids.Select(Inner));
} }
public async Task<MessageComponent[]> CreateSystemMessageComponents(Context cctx, PKSystem system, LookupContext ctx) public async Task<MessageComponent[]> CreateSystemMessageComponents(Context cctx, PKSystem system, LookupContext ctx, bool countctxByOwner)
{ {
// Fetch/render info for all accounts simultaneously // Fetch/render info for all accounts simultaneously
var accounts = await _repo.GetSystemAccounts(system.Id); var accounts = await _repo.GetSystemAccounts(system.Id);
@ -55,7 +55,7 @@ public class EmbedService
}; };
var countctx = LookupContext.ByNonOwner; var countctx = LookupContext.ByNonOwner;
if (cctx.MatchFlag("a", "all")) if (countctxByOwner)
{ {
if (system.Id == cctx.System?.Id) if (system.Id == cctx.System?.Id)
countctx = LookupContext.ByOwner; countctx = LookupContext.ByOwner;

View file

@ -27,7 +27,11 @@ pub fn all() -> impl Iterator<Item = Command> {
.chain(config::cmds()) .chain(config::cmds())
.chain(fun::cmds()) .chain(fun::cmds())
.chain(switch::cmds()) .chain(switch::cmds())
.map(|cmd| cmd.flag(("plaintext", ["pt"])).flag(("raw", ["r"]))) .map(|cmd| {
cmd.flag(("plaintext", ["pt"]))
.flag(("raw", ["r"]))
.flag(("show-embed", ["se"]))
})
} }
pub const RESET: (&str, [&str; 2]) = ("reset", ["clear", "default"]); pub const RESET: (&str, [&str; 2]) = ("reset", ["clear", "default"]);