From 1556b119f30608aab723f8f96681f7c4ca618fd1 Mon Sep 17 00:00:00 2001 From: dusk Date: Wed, 1 Oct 2025 12:27:06 +0000 Subject: [PATCH] implement rest of commands for system --- PluralKit.Bot/CommandMeta/CommandTree.cs | 99 +----------------------- crates/command_definitions/src/system.rs | 11 +++ 2 files changed, 14 insertions(+), 96 deletions(-) diff --git a/PluralKit.Bot/CommandMeta/CommandTree.cs b/PluralKit.Bot/CommandMeta/CommandTree.cs index e5d89931..c3107953 100644 --- a/PluralKit.Bot/CommandMeta/CommandTree.cs +++ b/PluralKit.Bot/CommandMeta/CommandTree.cs @@ -165,6 +165,9 @@ public partial class CommandTree Commands.SystemFronter(var param, var flags) => ctx.Execute(SystemFronter, m => m.Fronter(ctx, param.target)), Commands.SystemFronterHistory(var param, var flags) => ctx.Execute(SystemFrontHistory, m => m.FrontHistory(ctx, param.target, flags.clear)), Commands.SystemFronterPercent(var param, var flags) => ctx.Execute(SystemFrontPercent, m => m.FrontPercent(ctx, param.target, flags.duration, flags.fronters_only, flags.flat)), + Commands.SystemDisplayId(var param, _) => ctx.Execute(SystemId, m => m.DisplayId(ctx, param.target)), + Commands.SystemDisplayIdSelf => ctx.Execute(SystemId, m => m.DisplayId(ctx, ctx.System)), + Commands.SystemWebhook => ctx.Execute(null, m => m.SystemWebhook(ctx)), Commands.RandomSelf(_, var flags) => flags.group ? ctx.Execute(GroupRandom, m => m.Group(ctx, ctx.System, flags.all, flags.show_embed)) @@ -223,14 +226,6 @@ public partial class CommandTree ctx.Reply( $"{Emojis.Error} Parsed command {ctx.Parameters.Callback().AsCode()} not implemented in PluralKit.Bot!"), }; - if (ctx.Match("system", "s", "account", "acc")) - return HandleSystemCommand(ctx); - if (ctx.Match("member", "m")) - return HandleMemberCommand(ctx); - if (ctx.Match("group", "g")) - return HandleGroupCommand(ctx); - if (ctx.Match("switch", "sw")) - return HandleSwitchCommand(ctx); if (ctx.Match("commands", "cmd", "c")) return CommandHelpRoot(ctx); if (ctx.Match("ap", "autoproxy", "auto")) @@ -398,94 +393,6 @@ public partial class CommandTree $"{Emojis.Error} Unknown debug command {ctx.PeekArgument().AsCode()}. {availableCommandsStr}"); } - private async Task HandleSystemCommand(Context ctx) - { - if (ctx.Match("commands", "help")) - await PrintCommandList(ctx, "systems", SystemCommands); - - // todo: these aren't deprecated but also shouldn't be here - else if (ctx.Match("webhook", "hook")) - await ctx.Execute(null, m => m.SystemWebhook(ctx)); - - // finally, parse commands that *can* take a system target - else - { - // TODO: actually implement this - // // try matching a system ID - // var target = await ctx.MatchSystem(); - // var previousPtr = ctx.Parameters._ptr; - - // // if we have a parsed target and no more commands, don't bother with the command flow - // // we skip the `target != null` check here since the argument isn't be popped if it's not a system - // if (!ctx.HasNext()) - // { - // await ctx.Execute(SystemInfo, m => m.Query(ctx, target ?? ctx.System)); - // return; - // } - - // // hacky, but we need to CheckSystem(target) which throws a PKError - // // normally PKErrors are only handled in ctx.Execute - // try - // { - // await HandleSystemCommandTargeted(ctx, target ?? ctx.System); - // } - // catch (PKError e) - // { - // await ctx.Reply($"{Emojis.Error} {e.Message}"); - // return; - // } - - // // if we *still* haven't matched anything, the user entered an invalid command name or system reference - // if (ctx.Parameters._ptr == previousPtr) - // { - // if (!ctx.Parameters.Peek().TryParseHid(out _) && !ctx.Parameters.Peek().TryParseMention(out _)) - // { - // await PrintCommandNotFoundError(ctx, SystemCommands); - // return; - // } - - // var list = CreatePotentialCommandList(ctx.DefaultPrefix, SystemCommands); - // await ctx.Reply($"{Emojis.Error} {await CreateSystemNotFoundError(ctx)}\n\n" - // + $"Perhaps you meant to use one of the following commands?\n{list}"); - // } - } - } - - private async Task HandleSystemCommandTargeted(Context ctx, PKSystem target) - { - if (ctx.Match("id")) - await ctx.CheckSystem(target).Execute(SystemId, m => m.DisplayId(ctx, target)); - } - - private async Task HandleMemberCommand(Context ctx) - { - if (ctx.Match("commands", "help")) - await PrintCommandList(ctx, "members", MemberCommands); - else if (!ctx.HasNext()) - await PrintCommandExpectedError(ctx, MemberNew, MemberInfo, MemberRename, MemberDisplayName, - MemberServerName, MemberDesc, MemberPronouns, - MemberColor, MemberBirthday, MemberProxy, MemberDelete, MemberAvatar); - else - await ctx.Reply($"{Emojis.Error} {ctx.CreateNotFoundError("Member", ctx.PopArgument())}"); - } - - private async Task HandleGroupCommand(Context ctx) - { - // Commands with no group argument - if (ctx.Match("commands", "help")) - await PrintCommandList(ctx, "groups", GroupCommands); - else if (!ctx.HasNext()) - await PrintCommandExpectedError(ctx, GroupCommands); - else - await ctx.Reply($"{Emojis.Error} {ctx.CreateNotFoundError("Group", ctx.PopArgument())}"); - } - - private async Task HandleSwitchCommand(Context ctx) - { - await PrintCommandNotFoundError(ctx, Switch, SwitchOut, SwitchMove, SwitchEdit, SwitchEditOut, - SwitchDelete, SwitchCopy, SystemFronter, SystemFrontHistory); - } - private async Task CommandHelpRoot(Context ctx) { if (!ctx.HasNext()) diff --git a/crates/command_definitions/src/system.rs b/crates/command_definitions/src/system.rs index 86fcf55e..1d90398c 100644 --- a/crates/command_definitions/src/system.rs +++ b/crates/command_definitions/src/system.rs @@ -28,6 +28,10 @@ pub fn edit() -> impl Iterator { ] .into_iter(); + let system_webhook_cmd = [command!(system, ("webhook", ["hook"]) => "system_webhook") + .help("Creates a webhook for your system")] + .into_iter(); + let system_info_cmd = [ command!(system => "system_info_self").help("Shows information about your system"), command!(system_target, ("info", ["show", "view"]) => "system_info") @@ -281,7 +285,12 @@ pub fn edit() -> impl Iterator { .into_iter() .map(add_list_flags); + let system_display_id_self_cmd = + [command!(system, "id" => "system_display_id_self")].into_iter(); + let system_display_id_cmd = [command!(system_target, "id" => "system_display_id")].into_iter(); + system_new_cmd + .chain(system_webhook_cmd) .chain(system_name_self_cmd) .chain(system_server_name_self_cmd) .chain(system_description_self_cmd) @@ -293,6 +302,7 @@ pub fn edit() -> impl Iterator { .chain(system_server_avatar_self_cmd) .chain(system_banner_self_cmd) .chain(system_list_self_cmd) + .chain(system_display_id_self_cmd) .chain(system_delete) .chain(system_privacy_cmd) .chain(system_proxy_cmd) @@ -311,4 +321,5 @@ pub fn edit() -> impl Iterator { .chain(system_link) .chain(system_list_cmd) .chain(system_groups_cmd) + .chain(system_display_id_cmd) }