mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-11 08:10:10 +00:00
feat: implement system delete command
This commit is contained in:
parent
9e74835e4b
commit
047bdd870d
4 changed files with 19 additions and 12 deletions
|
|
@ -95,6 +95,7 @@ public partial class CommandTree
|
||||||
Commands.SystemShowBanner(var param, var flags) => ctx.Execute<SystemEdit>(SystemBannerImage, m => m.ShowBannerImage(ctx, param.target, flags.GetReplyFormat())),
|
Commands.SystemShowBanner(var param, var flags) => ctx.Execute<SystemEdit>(SystemBannerImage, m => m.ShowBannerImage(ctx, param.target, flags.GetReplyFormat())),
|
||||||
Commands.SystemClearBanner(var param, var flags) => ctx.Execute<SystemEdit>(SystemBannerImage, m => m.ClearBannerImage(ctx, ctx.System, flags.yes)),
|
Commands.SystemClearBanner(var param, var flags) => ctx.Execute<SystemEdit>(SystemBannerImage, m => m.ClearBannerImage(ctx, ctx.System, flags.yes)),
|
||||||
Commands.SystemChangeBanner(var param, _) => ctx.Execute<SystemEdit>(SystemBannerImage, m => m.ChangeBannerImage(ctx, ctx.System, param.banner)),
|
Commands.SystemChangeBanner(var param, _) => ctx.Execute<SystemEdit>(SystemBannerImage, m => m.ChangeBannerImage(ctx, ctx.System, param.banner)),
|
||||||
|
Commands.SystemDelete(_, var flags) => ctx.Execute<SystemEdit>(SystemDelete, m => m.Delete(ctx, ctx.System, flags.no_export)),
|
||||||
_ =>
|
_ =>
|
||||||
// this should only ever occur when deving if commands are not implemented...
|
// this should only ever occur when deving if commands are not implemented...
|
||||||
ctx.Reply(
|
ctx.Reply(
|
||||||
|
|
@ -364,8 +365,6 @@ public partial class CommandTree
|
||||||
await ctx.CheckSystem(target).Execute<Groups>(GroupList, g => g.ListSystemGroups(ctx, target));
|
await ctx.CheckSystem(target).Execute<Groups>(GroupList, g => g.ListSystemGroups(ctx, target));
|
||||||
else if (ctx.Match("privacy"))
|
else if (ctx.Match("privacy"))
|
||||||
await ctx.CheckSystem(target).Execute<SystemEdit>(SystemPrivacy, m => m.SystemPrivacy(ctx, target));
|
await ctx.CheckSystem(target).Execute<SystemEdit>(SystemPrivacy, m => m.SystemPrivacy(ctx, target));
|
||||||
else if (ctx.Match("delete", "remove", "destroy", "erase", "yeet"))
|
|
||||||
await ctx.CheckSystem(target).Execute<SystemEdit>(SystemDelete, m => m.Delete(ctx, target));
|
|
||||||
else if (ctx.Match("id"))
|
else if (ctx.Match("id"))
|
||||||
await ctx.CheckSystem(target).Execute<System>(SystemId, m => m.DisplayId(ctx, target));
|
await ctx.CheckSystem(target).Execute<System>(SystemId, m => m.DisplayId(ctx, target));
|
||||||
else if (ctx.Match("random", "rand", "r"))
|
else if (ctx.Match("random", "rand", "r"))
|
||||||
|
|
|
||||||
|
|
@ -774,10 +774,9 @@ public class SystemEdit
|
||||||
: ctx.Reply(msg));
|
: ctx.Reply(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Delete(Context ctx, PKSystem target)
|
public async Task Delete(Context ctx, PKSystem target, bool noExport)
|
||||||
{
|
{
|
||||||
ctx.CheckSystem().CheckOwnSystem(target);
|
ctx.CheckSystem().CheckOwnSystem(target);
|
||||||
var noExport = ctx.MatchFlag("ne", "no-export");
|
|
||||||
|
|
||||||
var warnMsg = $"{Emojis.Warn} Are you sure you want to delete your system? If so, reply to this message with your system's ID (`{target.DisplayHid(ctx.Config)}`).\n";
|
var warnMsg = $"{Emojis.Warn} Are you sure you want to delete your system? If so, reply to this message with your system's ID (`{target.DisplayHid(ctx.Config)}`).\n";
|
||||||
if (!noExport)
|
if (!noExport)
|
||||||
|
|
|
||||||
|
|
@ -159,8 +159,10 @@ pub fn edit() -> impl Iterator<Item = Command> {
|
||||||
.into_iter();
|
.into_iter();
|
||||||
|
|
||||||
let system_server_avatar = tokens!(system_target, ("serveravatar", ["spfp"]));
|
let system_server_avatar = tokens!(system_target, ("serveravatar", ["spfp"]));
|
||||||
let system_server_avatar_cmd = [command!(system_server_avatar => "system_show_server_avatar")
|
let system_server_avatar_cmd = [
|
||||||
.help("Shows the system's server avatar")]
|
command!(system_server_avatar => "system_show_server_avatar")
|
||||||
|
.help("Shows the system's server avatar"),
|
||||||
|
]
|
||||||
.into_iter();
|
.into_iter();
|
||||||
|
|
||||||
let system_server_avatar_self = tokens!(system, ("serveravatar", ["spfp"]));
|
let system_server_avatar_self = tokens!(system, ("serveravatar", ["spfp"]));
|
||||||
|
|
@ -192,6 +194,12 @@ pub fn edit() -> impl Iterator<Item = Command> {
|
||||||
]
|
]
|
||||||
.into_iter();
|
.into_iter();
|
||||||
|
|
||||||
|
let system_delete = std::iter::once(
|
||||||
|
command!(system, ("delete", ["erase", "remove", "yeet"]) => "system_delete")
|
||||||
|
.flag(("no-export", ["ne"]))
|
||||||
|
.help("Deletes the system"),
|
||||||
|
);
|
||||||
|
|
||||||
system_new_cmd
|
system_new_cmd
|
||||||
.chain(system_name_self_cmd)
|
.chain(system_name_self_cmd)
|
||||||
.chain(system_server_name_self_cmd)
|
.chain(system_server_name_self_cmd)
|
||||||
|
|
@ -203,6 +211,7 @@ pub fn edit() -> impl Iterator<Item = Command> {
|
||||||
.chain(system_avatar_self_cmd)
|
.chain(system_avatar_self_cmd)
|
||||||
.chain(system_server_avatar_self_cmd)
|
.chain(system_server_avatar_self_cmd)
|
||||||
.chain(system_banner_self_cmd)
|
.chain(system_banner_self_cmd)
|
||||||
|
.chain(system_delete)
|
||||||
.chain(system_name_cmd)
|
.chain(system_name_cmd)
|
||||||
.chain(system_server_name_cmd)
|
.chain(system_server_name_cmd)
|
||||||
.chain(system_description_cmd)
|
.chain(system_description_cmd)
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
writeln!(
|
writeln!(
|
||||||
&mut command_params_init,
|
&mut command_params_init,
|
||||||
r#"@{name} = await ctx.ParamResolve{extract_fn_name}("{name}") ?? throw new PKError("this is a bug"),"#,
|
r#"@{name} = await ctx.ParamResolve{extract_fn_name}("{name}") ?? throw new PKError("this is a bug"),"#,
|
||||||
name = param.name(),
|
name = param.name().replace("-", "_"),
|
||||||
extract_fn_name = get_param_param_ty(param.kind()),
|
extract_fn_name = get_param_param_ty(param.kind()),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
@ -44,14 +44,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
writeln!(
|
writeln!(
|
||||||
&mut command_flags_init,
|
&mut command_flags_init,
|
||||||
r#"@{name} = await ctx.FlagResolve{extract_fn_name}("{name}"),"#,
|
r#"@{name} = await ctx.FlagResolve{extract_fn_name}("{name}"),"#,
|
||||||
name = flag.get_name(),
|
name = flag.get_name().replace("-", "_"),
|
||||||
extract_fn_name = get_param_param_ty(kind),
|
extract_fn_name = get_param_param_ty(kind),
|
||||||
)?;
|
)?;
|
||||||
} else {
|
} else {
|
||||||
writeln!(
|
writeln!(
|
||||||
&mut command_flags_init,
|
&mut command_flags_init,
|
||||||
r#"@{name} = ctx.Parameters.HasFlag("{name}"),"#,
|
r#"@{name} = ctx.Parameters.HasFlag("{name}"),"#,
|
||||||
name = flag.get_name(),
|
name = flag.get_name().replace("-", "_"),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +92,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
writeln!(
|
writeln!(
|
||||||
&mut command_params_fields,
|
&mut command_params_fields,
|
||||||
r#"public required {ty} @{name};"#,
|
r#"public required {ty} @{name};"#,
|
||||||
name = param.name(),
|
name = param.name().replace("-", "_"),
|
||||||
ty = get_param_ty(param.kind()),
|
ty = get_param_ty(param.kind()),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
@ -102,14 +102,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
writeln!(
|
writeln!(
|
||||||
&mut command_flags_fields,
|
&mut command_flags_fields,
|
||||||
r#"public {ty}? @{name};"#,
|
r#"public {ty}? @{name};"#,
|
||||||
name = flag.get_name(),
|
name = flag.get_name().replace("-", "_"),
|
||||||
ty = get_param_ty(kind),
|
ty = get_param_ty(kind),
|
||||||
)?;
|
)?;
|
||||||
} else {
|
} else {
|
||||||
writeln!(
|
writeln!(
|
||||||
&mut command_flags_fields,
|
&mut command_flags_fields,
|
||||||
r#"public required bool @{name};"#,
|
r#"public required bool @{name};"#,
|
||||||
name = flag.get_name(),
|
name = flag.get_name().replace("-", "_"),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue