mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +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
|
|
@ -162,6 +162,15 @@ public partial class CommandTree
|
|||
Commands.SystemFronter(var param, var flags) => ctx.Execute<SystemFront>(SystemFronter, m => m.Fronter(ctx, param.target)),
|
||||
Commands.SystemFronterHistory(var param, var flags) => ctx.Execute<SystemFront>(SystemFrontHistory, m => m.FrontHistory(ctx, param.target, flags.clear)),
|
||||
Commands.SystemFronterPercent(var param, var flags) => ctx.Execute<SystemFront>(SystemFrontPercent, m => m.FrontPercent(ctx, param.target, flags.duration, flags.fronters_only, flags.flat)),
|
||||
Commands.RandomSelf(_, var flags) =>
|
||||
flags.group
|
||||
? ctx.Execute<Random>(GroupRandom, m => m.Group(ctx, ctx.System, flags.all, flags.show_embed))
|
||||
: ctx.Execute<Random>(MemberRandom, m => m.Member(ctx, ctx.System, flags.all, flags.show_embed)),
|
||||
Commands.SystemRandom(var param, var flags) =>
|
||||
flags.group
|
||||
? ctx.Execute<Random>(GroupRandom, m => m.Group(ctx, param.target, flags.all, flags.show_embed))
|
||||
: ctx.Execute<Random>(MemberRandom, m => m.Member(ctx, param.target, flags.all, flags.show_embed)),
|
||||
Commands.GroupRandomMember(var param, var flags) => ctx.Execute<Random>(GroupMemberRandom, m => m.GroupMember(ctx, param.target, flags.all, flags.show_embed)),
|
||||
_ =>
|
||||
// this should only ever occur when deving if commands are not implemented...
|
||||
ctx.Reply(
|
||||
|
|
@ -252,11 +261,6 @@ public partial class CommandTree
|
|||
return HandleDebugCommand(ctx);
|
||||
if (ctx.Match("admin"))
|
||||
return HandleAdminCommand(ctx);
|
||||
if (ctx.Match("random", "rand", "r"))
|
||||
if (ctx.Match("group", "g") || ctx.MatchFlag("group", "g"))
|
||||
return ctx.Execute<Random>(GroupRandom, r => r.Group(ctx, ctx.System));
|
||||
else
|
||||
return ctx.Execute<Random>(MemberRandom, m => m.Member(ctx, ctx.System));
|
||||
if (ctx.Match("dashboard", "dash"))
|
||||
return ctx.Execute<Help>(Dashboard, m => m.Dashboard(ctx));
|
||||
}
|
||||
|
|
@ -416,11 +420,6 @@ public partial class CommandTree
|
|||
await ctx.CheckSystem(target).Execute<Groups>(GroupList, g => g.ListSystemGroups(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"))
|
||||
if (ctx.Match("group", "g") || ctx.MatchFlag("group", "g"))
|
||||
await ctx.CheckSystem(target).Execute<Random>(GroupRandom, r => r.Group(ctx, target));
|
||||
else
|
||||
await ctx.CheckSystem(target).Execute<Random>(MemberRandom, m => m.Member(ctx, target));
|
||||
}
|
||||
|
||||
private async Task HandleMemberCommand(Context ctx)
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class Random
|
|||
|
||||
// todo: get postgresql to return one random member/group instead of querying all members/groups
|
||||
|
||||
public async Task Member(Context ctx, PKSystem target, bool showEmbed = false)
|
||||
public async Task Member(Context ctx, PKSystem target, bool all, bool showEmbed = false)
|
||||
{
|
||||
if (target == null)
|
||||
throw Errors.NoSystemError(ctx.DefaultPrefix);
|
||||
|
|
@ -24,7 +24,7 @@ public class Random
|
|||
|
||||
var members = await ctx.Repository.GetSystemMembers(target.Id).ToListAsync();
|
||||
|
||||
if (!ctx.MatchFlag("all", "a"))
|
||||
if (!all)
|
||||
members = members.Where(m => m.MemberVisibility == PrivacyLevel.Public).ToList();
|
||||
else
|
||||
ctx.CheckOwnSystem(target);
|
||||
|
|
@ -49,7 +49,7 @@ public class Random
|
|||
components: await _embeds.CreateMemberMessageComponents(target, members[randInt], ctx.Guild, ctx.Config, ctx.LookupContextFor(target.Id), ctx.Zone));
|
||||
}
|
||||
|
||||
public async Task Group(Context ctx, PKSystem target, bool showEmbed = false)
|
||||
public async Task Group(Context ctx, PKSystem target, bool all, bool showEmbed = false)
|
||||
{
|
||||
if (target == null)
|
||||
throw Errors.NoSystemError(ctx.DefaultPrefix);
|
||||
|
|
@ -57,7 +57,7 @@ public class Random
|
|||
ctx.CheckSystemPrivacy(target.Id, target.GroupListPrivacy);
|
||||
|
||||
var groups = await ctx.Repository.GetSystemGroups(target.Id).ToListAsync();
|
||||
if (!ctx.MatchFlag("all", "a"))
|
||||
if (!all)
|
||||
groups = groups.Where(g => g.Visibility == PrivacyLevel.Public).ToList();
|
||||
else
|
||||
ctx.CheckOwnSystem(target);
|
||||
|
|
@ -82,7 +82,7 @@ public class Random
|
|||
components: await _embeds.CreateGroupMessageComponents(ctx, target, groups.ToArray()[randInt]));
|
||||
}
|
||||
|
||||
public async Task GroupMember(Context ctx, PKGroup group, bool showEmbed = false)
|
||||
public async Task GroupMember(Context ctx, PKGroup group, bool all, bool showEmbed = false)
|
||||
{
|
||||
ctx.CheckSystemPrivacy(group.System, group.ListPrivacy);
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ public class Random
|
|||
"This group has no members!"
|
||||
+ (ctx.System?.Id == group.System ? " Please add at least one member to this group before using this command." : ""));
|
||||
|
||||
if (!ctx.MatchFlag("all", "a"))
|
||||
if (!all)
|
||||
members = members.Where(g => g.MemberVisibility == PrivacyLevel.Public);
|
||||
else
|
||||
ctx.CheckOwnGroup(group);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue