mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-05 05:17:54 +00:00
feat: implement system privacy commands (yay system edit done)
This commit is contained in:
parent
cb0a9eaf9f
commit
3eece261fd
10 changed files with 154 additions and 75 deletions
|
|
@ -100,6 +100,9 @@ public partial class CommandTree
|
|||
Commands.SystemShowProxy(var param, _) => ctx.Execute<SystemEdit>(SystemProxy, m => m.ShowSystemProxy(ctx, param.target)),
|
||||
Commands.SystemToggleProxyCurrent(var param, _) => ctx.Execute<SystemEdit>(SystemProxy, m => m.ToggleSystemProxy(ctx, ctx.Guild, param.toggle)),
|
||||
Commands.SystemToggleProxy(var param, _) => ctx.Execute<SystemEdit>(SystemProxy, m => m.ToggleSystemProxy(ctx, param.target, param.toggle)),
|
||||
Commands.SystemShowPrivacy(var param, _) => ctx.Execute<SystemEdit>(SystemPrivacy, m => m.ShowSystemPrivacy(ctx, ctx.System)),
|
||||
Commands.SystemChangePrivacyAll(var param, _) => ctx.Execute<SystemEdit>(SystemPrivacy, m => m.ChangeSystemPrivacyAll(ctx, ctx.System, param.level)),
|
||||
Commands.SystemChangePrivacy(var param, _) => ctx.Execute<SystemEdit>(SystemPrivacy, m => m.ChangeSystemPrivacy(ctx, ctx.System, param.privacy, param.level)),
|
||||
_ =>
|
||||
// this should only ever occur when deving if commands are not implemented...
|
||||
ctx.Reply(
|
||||
|
|
@ -363,8 +366,6 @@ public partial class CommandTree
|
|||
await ctx.CheckSystem(target).Execute<SystemFront>(SystemFrontPercent, m => m.FrontPercent(ctx, system: target));
|
||||
else if (ctx.Match("groups", "gs"))
|
||||
await ctx.CheckSystem(target).Execute<Groups>(GroupList, g => g.ListSystemGroups(ctx, target));
|
||||
else if (ctx.Match("privacy"))
|
||||
await ctx.CheckSystem(target).Execute<SystemEdit>(SystemPrivacy, m => m.SystemPrivacy(ctx, target));
|
||||
else if (ctx.Match("id"))
|
||||
await ctx.CheckSystem(target).Execute<System>(SystemId, m => m.DisplayId(ctx, target));
|
||||
else if (ctx.Match("random", "rand", "r"))
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ public static class ContextFlagsExt
|
|||
);
|
||||
}
|
||||
|
||||
public static async Task<string?> FlagResolvePrivacyLevel(this Context ctx, string param_name)
|
||||
public static async Task<PrivacyLevel?> FlagResolvePrivacyLevel(this Context ctx, string param_name)
|
||||
{
|
||||
return await ctx.Parameters.ResolveFlag(
|
||||
ctx, param_name,
|
||||
|
|
|
|||
|
|
@ -36,7 +36,15 @@ public static class ContextParametersExt
|
|||
);
|
||||
}
|
||||
|
||||
public static async Task<string?> ParamResolvePrivacyLevel(this Context ctx, string param_name)
|
||||
public static async Task<SystemPrivacySubject?> ParamResolveSystemPrivacyTarget(this Context ctx, string param_name)
|
||||
{
|
||||
return await ctx.Parameters.ResolveParameter(
|
||||
ctx, param_name,
|
||||
param => (param as Parameter.SystemPrivacyTarget)?.target
|
||||
);
|
||||
}
|
||||
|
||||
public static async Task<PrivacyLevel?> ParamResolvePrivacyLevel(this Context ctx, string param_name)
|
||||
{
|
||||
return await ctx.Parameters.ResolveParameter(
|
||||
ctx, param_name,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
using System.Diagnostics;
|
||||
using Myriad.Types;
|
||||
using PluralKit.Core;
|
||||
using uniffi.commands;
|
||||
|
|
@ -12,7 +11,8 @@ public abstract record Parameter()
|
|||
public record SystemRef(PKSystem system): Parameter;
|
||||
public record GuildRef(Guild guild): Parameter;
|
||||
public record MemberPrivacyTarget(MemberPrivacySubject target): Parameter;
|
||||
public record PrivacyLevel(string level): Parameter;
|
||||
public record SystemPrivacyTarget(SystemPrivacySubject target): Parameter;
|
||||
public record PrivacyLevel(Core.PrivacyLevel level): Parameter;
|
||||
public record Toggle(bool value): Parameter;
|
||||
public record Opaque(string value): Parameter;
|
||||
public record Avatar(ParsedImage avatar): Parameter;
|
||||
|
|
@ -72,12 +72,16 @@ public class Parameters
|
|||
);
|
||||
case uniffi.commands.Parameter.MemberPrivacyTarget memberPrivacyTarget:
|
||||
// this should never really fail...
|
||||
// todo: we shouldn't have *three* different MemberPrivacyTarget types (rust, ffi, c#) syncing the cases will be annoying...
|
||||
if (!MemberPrivacyUtils.TryParseMemberPrivacy(memberPrivacyTarget.target, out var target))
|
||||
if (!MemberPrivacyUtils.TryParseMemberPrivacy(memberPrivacyTarget.target, out var memberPrivacy))
|
||||
throw new PKError($"Invalid member privacy target {memberPrivacyTarget.target}");
|
||||
return new Parameter.MemberPrivacyTarget(target);
|
||||
return new Parameter.MemberPrivacyTarget(memberPrivacy);
|
||||
case uniffi.commands.Parameter.SystemPrivacyTarget systemPrivacyTarget:
|
||||
// this should never really fail...
|
||||
if (!SystemPrivacyUtils.TryParseSystemPrivacy(systemPrivacyTarget.target, out var systemPrivacy))
|
||||
throw new PKError($"Invalid system privacy target {systemPrivacyTarget.target}");
|
||||
return new Parameter.SystemPrivacyTarget(systemPrivacy);
|
||||
case uniffi.commands.Parameter.PrivacyLevel privacyLevel:
|
||||
return new Parameter.PrivacyLevel(privacyLevel.level);
|
||||
return new Parameter.PrivacyLevel(privacyLevel.level == "public" ? PrivacyLevel.Public : privacyLevel.level == "private" ? PrivacyLevel.Private : throw new PKError($"Invalid privacy level {privacyLevel.level}"));
|
||||
case uniffi.commands.Parameter.Toggle toggle:
|
||||
return new Parameter.Toggle(toggle.toggle);
|
||||
case uniffi.commands.Parameter.OpaqueString opaque:
|
||||
|
|
|
|||
|
|
@ -874,79 +874,72 @@ public class SystemEdit
|
|||
$"Proxying in {serverText} is currently **disabled** for your system. To enable it, type `{ctx.DefaultPrefix}system proxy on`.");
|
||||
}
|
||||
|
||||
public async Task SystemPrivacy(Context ctx, PKSystem target)
|
||||
public async Task ShowSystemPrivacy(Context ctx, PKSystem target)
|
||||
{
|
||||
ctx.CheckSystem().CheckOwnSystem(target);
|
||||
|
||||
Task PrintEmbed()
|
||||
var eb = new EmbedBuilder()
|
||||
.Title("Current privacy settings for your system")
|
||||
.Field(new Embed.Field("Name", target.NamePrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Avatar", target.AvatarPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Description", target.DescriptionPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Banner", target.BannerPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Pronouns", target.PronounPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Member list", target.MemberListPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Group list", target.GroupListPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Current fronter(s)", target.FrontPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Front/switch history", target.FrontHistoryPrivacy.Explanation()))
|
||||
.Description(
|
||||
$"To edit privacy settings, use the command:\n`{ctx.DefaultPrefix}system privacy <subject> <level>`\n\n- `subject` is one of `name`, `avatar`, `description`, `banner`, `pronouns`, `list`, `front`, `fronthistory`, `groups`, or `all` \n- `level` is either `public` or `private`.");
|
||||
await ctx.Reply(embed: eb.Build());
|
||||
}
|
||||
|
||||
public async Task ChangeSystemPrivacy(Context ctx, PKSystem target, SystemPrivacySubject subject, PrivacyLevel level)
|
||||
{
|
||||
ctx.CheckSystem().CheckOwnSystem(target);
|
||||
|
||||
await ctx.Repository.UpdateSystem(target.Id, new SystemPatch().WithPrivacy(subject, level));
|
||||
|
||||
var levelExplanation = level switch
|
||||
{
|
||||
var eb = new EmbedBuilder()
|
||||
.Title("Current privacy settings for your system")
|
||||
.Field(new Embed.Field("Name", target.NamePrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Avatar", target.AvatarPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Description", target.DescriptionPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Banner", target.BannerPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Pronouns", target.PronounPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Member list", target.MemberListPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Group list", target.GroupListPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Current fronter(s)", target.FrontPrivacy.Explanation()))
|
||||
.Field(new Embed.Field("Front/switch history", target.FrontHistoryPrivacy.Explanation()))
|
||||
.Description(
|
||||
$"To edit privacy settings, use the command:\n`{ctx.DefaultPrefix}system privacy <subject> <level>`\n\n- `subject` is one of `name`, `avatar`, `description`, `banner`, `pronouns`, `list`, `front`, `fronthistory`, `groups`, or `all` \n- `level` is either `public` or `private`.");
|
||||
return ctx.Reply(embed: eb.Build());
|
||||
}
|
||||
PrivacyLevel.Public => "be able to query",
|
||||
PrivacyLevel.Private => "*not* be able to query",
|
||||
_ => ""
|
||||
};
|
||||
|
||||
async Task SetLevel(SystemPrivacySubject subject, PrivacyLevel level)
|
||||
var subjectStr = subject switch
|
||||
{
|
||||
await ctx.Repository.UpdateSystem(target.Id, new SystemPatch().WithPrivacy(subject, level));
|
||||
SystemPrivacySubject.Name => "name",
|
||||
SystemPrivacySubject.Avatar => "avatar",
|
||||
SystemPrivacySubject.Description => "description",
|
||||
SystemPrivacySubject.Banner => "banner",
|
||||
SystemPrivacySubject.Pronouns => "pronouns",
|
||||
SystemPrivacySubject.Front => "front",
|
||||
SystemPrivacySubject.FrontHistory => "front history",
|
||||
SystemPrivacySubject.MemberList => "member list",
|
||||
SystemPrivacySubject.GroupList => "group list",
|
||||
_ => ""
|
||||
};
|
||||
|
||||
var levelExplanation = level switch
|
||||
{
|
||||
PrivacyLevel.Public => "be able to query",
|
||||
PrivacyLevel.Private => "*not* be able to query",
|
||||
_ => ""
|
||||
};
|
||||
var msg = $"System {subjectStr} privacy has been set to **{level.LevelName()}**. Other accounts will now {levelExplanation} your system {subjectStr}.";
|
||||
await ctx.Reply($"{Emojis.Success} {msg}");
|
||||
}
|
||||
|
||||
var subjectStr = subject switch
|
||||
{
|
||||
SystemPrivacySubject.Name => "name",
|
||||
SystemPrivacySubject.Avatar => "avatar",
|
||||
SystemPrivacySubject.Description => "description",
|
||||
SystemPrivacySubject.Banner => "banner",
|
||||
SystemPrivacySubject.Pronouns => "pronouns",
|
||||
SystemPrivacySubject.Front => "front",
|
||||
SystemPrivacySubject.FrontHistory => "front history",
|
||||
SystemPrivacySubject.MemberList => "member list",
|
||||
SystemPrivacySubject.GroupList => "group list",
|
||||
_ => ""
|
||||
};
|
||||
public async Task ChangeSystemPrivacyAll(Context ctx, PKSystem target, PrivacyLevel level)
|
||||
{
|
||||
ctx.CheckSystem().CheckOwnSystem(target);
|
||||
|
||||
var msg =
|
||||
$"System {subjectStr} privacy has been set to **{level.LevelName()}**. Other accounts will now {levelExplanation} your system {subjectStr}.";
|
||||
await ctx.Reply($"{Emojis.Success} {msg}");
|
||||
}
|
||||
await ctx.Repository.UpdateSystem(target.Id, new SystemPatch().WithAllPrivacy(level));
|
||||
|
||||
async Task SetAll(PrivacyLevel level)
|
||||
var msg = level switch
|
||||
{
|
||||
await ctx.Repository.UpdateSystem(target.Id, new SystemPatch().WithAllPrivacy(level));
|
||||
PrivacyLevel.Private =>
|
||||
$"All system privacy settings have been set to **{level.LevelName()}**. Other accounts will now not be able to view your member list, group list, front history, or system description.",
|
||||
PrivacyLevel.Public =>
|
||||
$"All system privacy settings have been set to **{level.LevelName()}**. Other accounts will now be able to view everything.",
|
||||
_ => ""
|
||||
};
|
||||
|
||||
var msg = level switch
|
||||
{
|
||||
PrivacyLevel.Private =>
|
||||
$"All system privacy settings have been set to **{level.LevelName()}**. Other accounts will now not be able to view your member list, group list, front history, or system description.",
|
||||
PrivacyLevel.Public =>
|
||||
$"All system privacy settings have been set to **{level.LevelName()}**. Other accounts will now be able to view everything.",
|
||||
_ => ""
|
||||
};
|
||||
|
||||
await ctx.Reply($"{Emojis.Success} {msg}");
|
||||
}
|
||||
|
||||
if (!ctx.HasNext())
|
||||
await PrintEmbed();
|
||||
else if (ctx.Match("all"))
|
||||
await SetAll(ctx.PopPrivacyLevel());
|
||||
else
|
||||
await SetLevel(ctx.PopSystemPrivacySubject(), ctx.PopPrivacyLevel());
|
||||
await ctx.Reply($"{Emojis.Success} {msg}");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue