mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-06 22:07:55 +00:00
feat: implement system proxy commands
This commit is contained in:
parent
047bdd870d
commit
cb0a9eaf9f
11 changed files with 93 additions and 29 deletions
|
|
@ -96,6 +96,10 @@ public partial class CommandTree
|
|||
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.SystemDelete(_, var flags) => ctx.Execute<SystemEdit>(SystemDelete, m => m.Delete(ctx, ctx.System, flags.no_export)),
|
||||
Commands.SystemShowProxyCurrent(_, _) => ctx.Execute<SystemEdit>(SystemProxy, m => m.ShowSystemProxy(ctx, ctx.Guild)),
|
||||
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)),
|
||||
_ =>
|
||||
// this should only ever occur when deving if commands are not implemented...
|
||||
ctx.Reply(
|
||||
|
|
@ -167,8 +171,6 @@ public partial class CommandTree
|
|||
if (ctx.Match("proxy"))
|
||||
if (ctx.Match("debug"))
|
||||
return ctx.Execute<Checks>(ProxyCheck, m => m.MessageProxyCheck(ctx));
|
||||
else
|
||||
return ctx.Execute<SystemEdit>(SystemProxy, m => m.SystemProxy(ctx));
|
||||
if (ctx.Match("invite")) return ctx.Execute<Misc>(Invite, m => m.Invite(ctx));
|
||||
if (ctx.Match("mn")) return ctx.Execute<Fun>(null, m => m.Mn(ctx));
|
||||
if (ctx.Match("fire")) return ctx.Execute<Fun>(null, m => m.Fire(ctx));
|
||||
|
|
@ -295,8 +297,6 @@ public partial class CommandTree
|
|||
// todo: these aren't deprecated but also shouldn't be here
|
||||
else if (ctx.Match("webhook", "hook"))
|
||||
await ctx.Execute<Api>(null, m => m.SystemWebhook(ctx));
|
||||
else if (ctx.Match("proxy"))
|
||||
await ctx.Execute<SystemEdit>(SystemProxy, m => m.SystemProxy(ctx));
|
||||
|
||||
// finally, parse commands that *can* take a system target
|
||||
else
|
||||
|
|
|
|||
|
|
@ -213,6 +213,14 @@ public static class ContextEntityArgumentsExt
|
|||
return channel;
|
||||
}
|
||||
|
||||
public static async Task<Guild> ParseGuild(this Context ctx, string input)
|
||||
{
|
||||
if (!ulong.TryParse(input, out var id))
|
||||
return null;
|
||||
|
||||
return await ctx.Rest.GetGuildOrNull(id);
|
||||
}
|
||||
|
||||
public static async Task<Guild> MatchGuild(this Context ctx)
|
||||
{
|
||||
if (!ulong.TryParse(ctx.PeekArgument(), out var id))
|
||||
|
|
|
|||
|
|
@ -59,4 +59,12 @@ public static class ContextParametersExt
|
|||
param => (param as Parameter.Avatar)?.avatar
|
||||
);
|
||||
}
|
||||
|
||||
public static async Task<Myriad.Types.Guild?> ParamResolveGuild(this Context ctx, string param_name)
|
||||
{
|
||||
return await ctx.Parameters.ResolveParameter(
|
||||
ctx, param_name,
|
||||
param => (param as Parameter.GuildRef)?.guild
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ public abstract record Parameter()
|
|||
{
|
||||
public record MemberRef(PKMember member): 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 Toggle(bool value): Parameter;
|
||||
|
|
@ -83,6 +84,8 @@ public class Parameters
|
|||
return new Parameter.Opaque(opaque.raw);
|
||||
case uniffi.commands.Parameter.Avatar avatar:
|
||||
return new Parameter.Avatar(await ctx.GetUserPfp(avatar.avatar) ?? ctx.ParseImage(avatar.avatar));
|
||||
case uniffi.commands.Parameter.GuildRef guildRef:
|
||||
return new Parameter.GuildRef(await ctx.ParseGuild(guildRef.guild) ?? throw new PKError($"Guild {guildRef.guild} not found"));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -830,11 +830,32 @@ public class SystemEdit
|
|||
await ctx.Repository.DeleteSystem(target.Id);
|
||||
}
|
||||
|
||||
public async Task SystemProxy(Context ctx)
|
||||
public async Task ToggleSystemProxy(Context ctx, Guild guildArg, bool newValue)
|
||||
{
|
||||
ctx.CheckSystem();
|
||||
|
||||
var guild = await ctx.MatchGuild() ?? ctx.Guild ??
|
||||
var guild = guildArg ??
|
||||
throw new PKError("You must run this command in a server or pass a server ID.");
|
||||
|
||||
string serverText;
|
||||
if (guild.Id == ctx.Guild?.Id)
|
||||
serverText = $"this server ({guild.Name.EscapeMarkdown()})";
|
||||
else
|
||||
serverText = $"the server {guild.Name.EscapeMarkdown()}";
|
||||
|
||||
await ctx.Repository.UpdateSystemGuild(ctx.System.Id, guild.Id, new SystemGuildPatch { ProxyEnabled = newValue });
|
||||
|
||||
if (newValue)
|
||||
await ctx.Reply($"Message proxying in {serverText} is now **enabled** for your system.");
|
||||
else
|
||||
await ctx.Reply($"Message proxying in {serverText} is now **disabled** for your system.");
|
||||
}
|
||||
|
||||
public async Task ShowSystemProxy(Context ctx, Guild guildArg)
|
||||
{
|
||||
ctx.CheckSystem();
|
||||
|
||||
var guild = guildArg ??
|
||||
throw new PKError("You must run this command in a server or pass a server ID.");
|
||||
|
||||
var gs = await ctx.Repository.GetSystemGuild(guild.Id, ctx.System.Id);
|
||||
|
|
@ -845,25 +866,12 @@ public class SystemEdit
|
|||
else
|
||||
serverText = $"the server {guild.Name.EscapeMarkdown()}";
|
||||
|
||||
if (!ctx.HasNext())
|
||||
{
|
||||
if (gs.ProxyEnabled)
|
||||
await ctx.Reply(
|
||||
$"Proxying in {serverText} is currently **enabled** for your system. To disable it, type `{ctx.DefaultPrefix}system proxy off`.");
|
||||
else
|
||||
await ctx.Reply(
|
||||
$"Proxying in {serverText} is currently **disabled** for your system. To enable it, type `{ctx.DefaultPrefix}system proxy on`.");
|
||||
return;
|
||||
}
|
||||
|
||||
var newValue = ctx.MatchToggle();
|
||||
|
||||
await ctx.Repository.UpdateSystemGuild(ctx.System.Id, guild.Id, new SystemGuildPatch { ProxyEnabled = newValue });
|
||||
|
||||
if (newValue)
|
||||
await ctx.Reply($"Message proxying in {serverText} is now **enabled** for your system.");
|
||||
if (gs.ProxyEnabled)
|
||||
await ctx.Reply(
|
||||
$"Proxying in {serverText} is currently **enabled** for your system. To disable it, type `{ctx.DefaultPrefix}system proxy off`.");
|
||||
else
|
||||
await ctx.Reply($"Message proxying in {serverText} is now **disabled** for your system.");
|
||||
await ctx.Reply(
|
||||
$"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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue