diff --git a/PluralKit.Bot/Commands/SwitchCommands.cs b/PluralKit.Bot/Commands/SwitchCommands.cs index d313263a..cb630754 100644 --- a/PluralKit.Bot/Commands/SwitchCommands.cs +++ b/PluralKit.Bot/Commands/SwitchCommands.cs @@ -27,10 +27,15 @@ namespace PluralKit.Bot.Commands private async Task DoSwitchCommand(ICollection members) { + // Make sure all the members *are actually in the system* + // PKMember parameters won't let this happen if they resolve by name + // but they can if they resolve with ID + if (members.Any(m => m.System != Context.SenderSystem.Id)) throw Errors.SwitchMemberNotInSystem; + // Make sure there are no dupes in the list // We do this by checking if removing duplicate member IDs results in a list of different length if (members.Select(m => m.Id).Distinct().Count() != members.Count) throw Errors.DuplicateSwitchMembers; - + // Find the last switch and its members if applicable var lastSwitch = await Switches.GetLatestSwitch(Context.SenderSystem); if (lastSwitch != null) diff --git a/PluralKit.Bot/Errors.cs b/PluralKit.Bot/Errors.cs index 6e346fe7..5ff000e5 100644 --- a/PluralKit.Bot/Errors.cs +++ b/PluralKit.Bot/Errors.cs @@ -49,6 +49,7 @@ namespace PluralKit.Bot { } public static PKError DuplicateSwitchMembers => new PKError("Duplicate members in member list."); + public static PKError SwitchMemberNotInSystem => new PKError("One or more switch members aren't in your own system."); public static PKError InvalidDateTime(string str) => new PKError($"Could not parse '{str}' as a valid date/time."); public static PKError SwitchTimeInFuture => new PKError("Can't move switch to a time in the future.");