mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-09 23:37:54 +00:00
implement rest of group and member commands
This commit is contained in:
parent
95fc7e9f60
commit
1943687c70
13 changed files with 705 additions and 443 deletions
|
|
@ -127,16 +127,6 @@ public static class ContextArgumentsExt
|
|||
ctx.PopArgument();
|
||||
return (messageId, channelId);
|
||||
}
|
||||
|
||||
public static async Task<List<PKMember>> ParseMemberList(this Context ctx, SystemId? restrictToSystem)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static async Task<List<PKGroup>> ParseGroupList(this Context ctx, SystemId? restrictToSystem)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public enum ReplyFormat
|
||||
|
|
|
|||
|
|
@ -36,6 +36,14 @@ public static class ContextParametersExt
|
|||
);
|
||||
}
|
||||
|
||||
public static async Task<List<PKGroup>> ParamResolveGroups(this Context ctx, string param_name)
|
||||
{
|
||||
return await ctx.Parameters.ResolveParameter(
|
||||
ctx, param_name,
|
||||
param => (param as Parameter.GroupRefs)?.groups
|
||||
);
|
||||
}
|
||||
|
||||
public static async Task<PKSystem?> ParamResolveSystem(this Context ctx, string param_name)
|
||||
{
|
||||
return await ctx.Parameters.ResolveParameter(
|
||||
|
|
@ -52,6 +60,14 @@ public static class ContextParametersExt
|
|||
);
|
||||
}
|
||||
|
||||
public static async Task<GroupPrivacySubject?> ParamResolveGroupPrivacyTarget(this Context ctx, string param_name)
|
||||
{
|
||||
return await ctx.Parameters.ResolveParameter(
|
||||
ctx, param_name,
|
||||
param => (param as Parameter.GroupPrivacyTarget)?.target
|
||||
);
|
||||
}
|
||||
|
||||
public static async Task<SystemPrivacySubject?> ParamResolveSystemPrivacyTarget(this Context ctx, string param_name)
|
||||
{
|
||||
return await ctx.Parameters.ResolveParameter(
|
||||
|
|
|
|||
|
|
@ -11,9 +11,11 @@ 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 GroupRefs(List<PKGroup> groups): Parameter;
|
||||
public record SystemRef(PKSystem system): Parameter;
|
||||
public record GuildRef(Guild guild): Parameter;
|
||||
public record MemberPrivacyTarget(MemberPrivacySubject target): Parameter;
|
||||
public record GroupPrivacyTarget(GroupPrivacySubject target): Parameter;
|
||||
public record SystemPrivacyTarget(SystemPrivacySubject target): Parameter;
|
||||
public record PrivacyLevel(Core.PrivacyLevel level): Parameter;
|
||||
public record Toggle(bool value): Parameter;
|
||||
|
|
@ -79,17 +81,30 @@ public class Parameters
|
|||
await ctx.ParseGroup(groupRef.group, byId)
|
||||
?? throw new PKError(ctx.CreateNotFoundError("Group", groupRef.group))
|
||||
);
|
||||
case uniffi.commands.Parameter.GroupRefs groupRefs:
|
||||
return new Parameter.GroupRefs(
|
||||
await groupRefs.groups.ToAsyncEnumerable().SelectAwait(async g =>
|
||||
await ctx.ParseGroup(g, byId)
|
||||
?? throw new PKError(ctx.CreateNotFoundError("Group", g, byId))
|
||||
).ToListAsync()
|
||||
);
|
||||
case uniffi.commands.Parameter.SystemRef systemRef:
|
||||
// todo: do we need byId here?
|
||||
return new Parameter.SystemRef(
|
||||
await ctx.ParseSystem(systemRef.system)
|
||||
?? throw new PKError(ctx.CreateNotFoundError("System", systemRef.system))
|
||||
);
|
||||
// todo(dusk): ideally generate enums for these from rust code in the cs glue
|
||||
case uniffi.commands.Parameter.MemberPrivacyTarget memberPrivacyTarget:
|
||||
// this should never really fail...
|
||||
if (!MemberPrivacyUtils.TryParseMemberPrivacy(memberPrivacyTarget.target, out var memberPrivacy))
|
||||
throw new PKError($"Invalid member privacy target {memberPrivacyTarget.target}");
|
||||
return new Parameter.MemberPrivacyTarget(memberPrivacy);
|
||||
case uniffi.commands.Parameter.GroupPrivacyTarget groupPrivacyTarget:
|
||||
// this should never really fail...
|
||||
if (!GroupPrivacyUtils.TryParseGroupPrivacy(groupPrivacyTarget.target, out var groupPrivacy))
|
||||
throw new PKError($"Invalid group privacy target {groupPrivacyTarget.target}");
|
||||
return new Parameter.GroupPrivacyTarget(groupPrivacy);
|
||||
case uniffi.commands.Parameter.SystemPrivacyTarget systemPrivacyTarget:
|
||||
// this should never really fail...
|
||||
if (!SystemPrivacyUtils.TryParseSystemPrivacy(systemPrivacyTarget.target, out var systemPrivacy))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue