mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-09 15:27:54 +00:00
better parameters handling, implement import export
This commit is contained in:
parent
e4f38c76a9
commit
5198f7d83b
19 changed files with 250 additions and 174 deletions
|
|
@ -31,9 +31,9 @@ public class ImportExport
|
|||
_dmCache = dmCache;
|
||||
}
|
||||
|
||||
public async Task Import(Context ctx)
|
||||
public async Task Import(Context ctx, string? inputUrl)
|
||||
{
|
||||
var inputUrl = ctx.RemainderOrNull() ?? ctx.Message.Attachments.FirstOrDefault()?.Url;
|
||||
inputUrl = inputUrl ?? ctx.Message.Attachments.FirstOrDefault()?.Url;
|
||||
if (inputUrl == null) throw Errors.NoImportFilePassed;
|
||||
|
||||
if (!Core.MiscUtils.TryMatchUri(inputUrl, out var url))
|
||||
|
|
|
|||
|
|
@ -23,8 +23,9 @@ public class Switch
|
|||
await DoSwitchCommand(ctx, []);
|
||||
}
|
||||
|
||||
private async Task DoSwitchCommand(Context ctx, ICollection<PKMember> members)
|
||||
private async Task DoSwitchCommand(Context ctx, ICollection<PKMember>? members)
|
||||
{
|
||||
if (members == null) members = new List<PKMember>();
|
||||
// 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;
|
||||
|
|
@ -101,10 +102,12 @@ public class Switch
|
|||
await ctx.Reply($"{Emojis.Success} Switch moved to <t:{newSwitchTime}> ({newSwitchDeltaStr} ago).");
|
||||
}
|
||||
|
||||
public async Task SwitchEdit(Context ctx, List<PKMember> newMembers, bool newSwitch = false, bool first = false, bool remove = false, bool append = false, bool prepend = false)
|
||||
public async Task SwitchEdit(Context ctx, List<PKMember>? newMembers, bool newSwitch = false, bool first = false, bool remove = false, bool append = false, bool prepend = false)
|
||||
{
|
||||
ctx.CheckSystem();
|
||||
|
||||
if (newMembers == null) newMembers = new List<PKMember>();
|
||||
|
||||
await using var conn = await ctx.Database.Obtain();
|
||||
var currentSwitch = await ctx.Repository.GetLatestSwitch(ctx.System.Id);
|
||||
if (currentSwitch == null)
|
||||
|
|
@ -170,8 +173,10 @@ public class Switch
|
|||
await DoEditCommand(ctx, []);
|
||||
}
|
||||
|
||||
public async Task DoEditCommand(Context ctx, ICollection<PKMember> members)
|
||||
public async Task DoEditCommand(Context ctx, ICollection<PKMember>? members)
|
||||
{
|
||||
if (members == null) members = new List<PKMember>();
|
||||
|
||||
// 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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue