feat: don't try to match other systems' members in switch / group add commands
This commit is contained in:
@@ -104,14 +104,12 @@ namespace PluralKit.Bot
|
||||
while (ctx.HasNext())
|
||||
{
|
||||
// and attempt to match a member
|
||||
var member = await ctx.MatchMember();
|
||||
var member = await ctx.MatchMember(restrictToSystem);
|
||||
|
||||
if (member == null)
|
||||
// if we can't, big error. Every member name must be valid.
|
||||
throw new PKError(ctx.CreateMemberNotFoundError(ctx.PopArgument()));
|
||||
|
||||
if (restrictToSystem != null && member.System != restrictToSystem)
|
||||
throw Errors.NotOwnMemberError; // TODO: name *which* member?
|
||||
|
||||
members.Add(member); // Then add to the final output list
|
||||
}
|
||||
if (members.Count == 0) throw new PKSyntaxError($"You must input at least one member.");
|
||||
@@ -127,7 +125,7 @@ namespace PluralKit.Bot
|
||||
while (ctx.HasNext())
|
||||
{
|
||||
// and attempt to match a group
|
||||
var group = await ctx.MatchGroup();
|
||||
var group = await ctx.MatchGroup(restrictToSystem);
|
||||
if (group == null)
|
||||
// if we can't, big error. Every group name must be valid.
|
||||
throw new PKError(ctx.CreateGroupNotFoundError(ctx.PopArgument()));
|
||||
|
@@ -60,7 +60,7 @@ namespace PluralKit.Bot
|
||||
return system;
|
||||
}
|
||||
|
||||
public static async Task<PKMember> PeekMember(this Context ctx)
|
||||
public static async Task<PKMember> PeekMember(this Context ctx, SystemId? restrictToSystem = null)
|
||||
{
|
||||
var input = ctx.PeekArgument();
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace PluralKit.Bot
|
||||
return memberByName;
|
||||
|
||||
// Then, try member HID parsing:
|
||||
if (await ctx.Repository.GetMemberByHid(conn, input) is PKMember memberByHid)
|
||||
if (await ctx.Repository.GetMemberByHid(conn, input, restrictToSystem) is PKMember memberByHid)
|
||||
return memberByHid;
|
||||
|
||||
// And if that again fails, we try finding a member with a display name matching the argument from the system
|
||||
@@ -91,10 +91,10 @@ namespace PluralKit.Bot
|
||||
/// Attempts to pop a member descriptor from the stack, returning it if present. If a member could not be
|
||||
/// resolved by the next word in the argument stack, does *not* touch the stack, and returns null.
|
||||
/// </summary>
|
||||
public static async Task<PKMember> MatchMember(this Context ctx)
|
||||
public static async Task<PKMember> MatchMember(this Context ctx, SystemId? restrictToSystem = null)
|
||||
{
|
||||
// First, peek a member
|
||||
var member = await ctx.PeekMember();
|
||||
var member = await ctx.PeekMember(restrictToSystem);
|
||||
|
||||
// If the peek was successful, we've used up the next argument, so we pop that just to get rid of it.
|
||||
if (member != null) ctx.PopArgument();
|
||||
@@ -103,14 +103,14 @@ namespace PluralKit.Bot
|
||||
return member;
|
||||
}
|
||||
|
||||
public static async Task<PKGroup> PeekGroup(this Context ctx)
|
||||
public static async Task<PKGroup> PeekGroup(this Context ctx, SystemId? restrictToSystem = null)
|
||||
{
|
||||
var input = ctx.PeekArgument();
|
||||
|
||||
await using var conn = await ctx.Database.Obtain();
|
||||
if (ctx.System != null && await ctx.Repository.GetGroupByName(conn, ctx.System.Id, input) is { } byName)
|
||||
return byName;
|
||||
if (await ctx.Repository.GetGroupByHid(conn, input) is { } byHid)
|
||||
if (await ctx.Repository.GetGroupByHid(conn, input, restrictToSystem) is { } byHid)
|
||||
return byHid;
|
||||
if (await ctx.Repository.GetGroupByDisplayName(conn, ctx.System.Id, input) is { } byDisplayName)
|
||||
return byDisplayName;
|
||||
@@ -118,9 +118,9 @@ namespace PluralKit.Bot
|
||||
return null;
|
||||
}
|
||||
|
||||
public static async Task<PKGroup> MatchGroup(this Context ctx)
|
||||
public static async Task<PKGroup> MatchGroup(this Context ctx, SystemId? restrictToSystem = null)
|
||||
{
|
||||
var group = await ctx.PeekGroup();
|
||||
var group = await ctx.PeekGroup(restrictToSystem);
|
||||
if (group != null) ctx.PopArgument();
|
||||
return group;
|
||||
}
|
||||
|
Reference in New Issue
Block a user