mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-07 14:27:54 +00:00
implement random commands, dont keep the subcommands only the flags
This commit is contained in:
parent
c00ff2f371
commit
c92c3f84f0
13 changed files with 82 additions and 24 deletions
|
|
@ -147,13 +147,9 @@ public static class ContextEntityArgumentsExt
|
|||
return member;
|
||||
}
|
||||
|
||||
public static async Task<PKGroup> PeekGroup(this Context ctx, SystemId? restrictToSystem = null)
|
||||
public static async Task<PKGroup> ParseGroup(this Context ctx, string input, bool byId, SystemId? restrictToSystem = null)
|
||||
{
|
||||
var input = ctx.PeekArgument();
|
||||
|
||||
// see PeekMember for an explanation of the logic used here
|
||||
|
||||
if (ctx.System != null && !ctx.MatchFlag("id", "by-id"))
|
||||
if (ctx.System != null && !byId)
|
||||
{
|
||||
if (await ctx.Repository.GetGroupByName(ctx.System.Id, input) is { } byName)
|
||||
return byName;
|
||||
|
|
@ -170,6 +166,11 @@ public static class ContextEntityArgumentsExt
|
|||
return null;
|
||||
}
|
||||
|
||||
public static async Task<PKGroup> PeekGroup(this Context ctx, SystemId? restrictToSystem = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static async Task<PKGroup> MatchGroup(this Context ctx, SystemId? restrictToSystem = null)
|
||||
{
|
||||
var group = await ctx.PeekGroup(restrictToSystem);
|
||||
|
|
|
|||
|
|
@ -28,6 +28,14 @@ public static class ContextParametersExt
|
|||
);
|
||||
}
|
||||
|
||||
public static async Task<PKGroup?> ParamResolveGroup(this Context ctx, string param_name)
|
||||
{
|
||||
return await ctx.Parameters.ResolveParameter(
|
||||
ctx, param_name,
|
||||
param => (param as Parameter.GroupRef)?.group
|
||||
);
|
||||
}
|
||||
|
||||
public static async Task<PKSystem?> ParamResolveSystem(this Context ctx, string param_name)
|
||||
{
|
||||
return await ctx.Parameters.ResolveParameter(
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ public abstract record Parameter()
|
|||
{
|
||||
public record MemberRef(PKMember member): Parameter;
|
||||
public record MemberRefs(List<PKMember> members): Parameter;
|
||||
public record GroupRef(PKGroup group): Parameter;
|
||||
public record SystemRef(PKSystem system): Parameter;
|
||||
public record GuildRef(Guild guild): Parameter;
|
||||
public record MemberPrivacyTarget(MemberPrivacySubject target): Parameter;
|
||||
|
|
@ -73,6 +74,11 @@ public class Parameters
|
|||
?? throw new PKError(ctx.CreateNotFoundError("Member", m, byId))
|
||||
).ToListAsync()
|
||||
);
|
||||
case uniffi.commands.Parameter.GroupRef groupRef:
|
||||
return new Parameter.GroupRef(
|
||||
await ctx.ParseGroup(groupRef.group, byId)
|
||||
?? throw new PKError(ctx.CreateNotFoundError("Group", groupRef.group))
|
||||
);
|
||||
case uniffi.commands.Parameter.SystemRef systemRef:
|
||||
// todo: do we need byId here?
|
||||
return new Parameter.SystemRef(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue