Disallow switching to member in another system
This commit is contained in:
parent
802eeb8d39
commit
de9554810a
@ -27,10 +27,15 @@ namespace PluralKit.Bot.Commands
|
|||||||
|
|
||||||
private async Task DoSwitchCommand(ICollection<PKMember> members)
|
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
|
// 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
|
// 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;
|
if (members.Select(m => m.Id).Distinct().Count() != members.Count) throw Errors.DuplicateSwitchMembers;
|
||||||
|
|
||||||
// Find the last switch and its members if applicable
|
// Find the last switch and its members if applicable
|
||||||
var lastSwitch = await Switches.GetLatestSwitch(Context.SenderSystem);
|
var lastSwitch = await Switches.GetLatestSwitch(Context.SenderSystem);
|
||||||
if (lastSwitch != null)
|
if (lastSwitch != null)
|
||||||
|
@ -49,6 +49,7 @@ namespace PluralKit.Bot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static PKError DuplicateSwitchMembers => new PKError("Duplicate members in member list.");
|
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 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.");
|
public static PKError SwitchTimeInFuture => new PKError("Can't move switch to a time in the future.");
|
||||||
|
Loading…
Reference in New Issue
Block a user