Disallow switching to member in another system

This commit is contained in:
Ske 2019-07-10 00:25:47 +02:00
parent 802eeb8d39
commit de9554810a
2 changed files with 7 additions and 1 deletions

View File

@ -27,6 +27,11 @@ namespace PluralKit.Bot.Commands
private async Task DoSwitchCommand(ICollection<PKMember> 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;

View File

@ -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.");