mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-14 01:30:13 +00:00
remove rest of the parsing in csharp bot
This commit is contained in:
parent
15ffd16c01
commit
479e0a59b5
35 changed files with 242 additions and 409 deletions
|
|
@ -57,14 +57,14 @@ public class Switch
|
|||
$"{Emojis.Success} Switch registered. Current fronters are now {string.Join(", ", members.Select(m => m.NameFor(ctx)))}.");
|
||||
}
|
||||
|
||||
public async Task SwitchMove(Context ctx, string timeToMove)
|
||||
public async Task SwitchMove(Context ctx, string str, bool confirmYes = false)
|
||||
{
|
||||
ctx.CheckSystem();
|
||||
|
||||
var tz = TzdbDateTimeZoneSource.Default.ForId(ctx.Config?.UiTz ?? "UTC");
|
||||
|
||||
var result = DateUtils.ParseDateTime(timeToMove, true, tz);
|
||||
if (result == null) throw Errors.InvalidDateTime(timeToMove);
|
||||
var result = DateUtils.ParseDateTime(str, true, tz);
|
||||
if (result == null) throw Errors.InvalidDateTime(str);
|
||||
|
||||
|
||||
var time = result.Value;
|
||||
|
|
@ -95,14 +95,14 @@ public class Switch
|
|||
// yeet
|
||||
var msg =
|
||||
$"{Emojis.Warn} This will move the latest switch ({lastSwitchMemberStr}) from <t:{lastSwitchTime}> ({lastSwitchDeltaStr} ago) to <t:{newSwitchTime}> ({newSwitchDeltaStr} ago). Is this OK?";
|
||||
if (!await ctx.PromptYesNo(msg, "Move Switch")) throw Errors.SwitchMoveCancelled;
|
||||
if (!await ctx.PromptYesNo(msg, "Move Switch", flagValue: confirmYes)) throw Errors.SwitchMoveCancelled;
|
||||
|
||||
// aaaand *now* we do the move
|
||||
await ctx.Repository.MoveSwitch(lastTwoSwitches[0].Id, time.ToInstant());
|
||||
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, bool confirmYes = false)
|
||||
{
|
||||
ctx.CheckSystem();
|
||||
|
||||
|
|
@ -131,7 +131,7 @@ public class Switch
|
|||
await DoSwitchCommand(ctx, newMembers);
|
||||
}
|
||||
else
|
||||
await DoEditCommand(ctx, newMembers);
|
||||
await DoEditCommand(ctx, newMembers, confirmYes);
|
||||
}
|
||||
|
||||
public List<PKMember> PrependToSwitch(List<PKMember> members, List<PKMember> currentSwitchMembers)
|
||||
|
|
@ -167,13 +167,13 @@ public class Switch
|
|||
return members;
|
||||
}
|
||||
|
||||
public async Task SwitchEditOut(Context ctx)
|
||||
public async Task SwitchEditOut(Context ctx, bool confirmYes)
|
||||
{
|
||||
ctx.CheckSystem();
|
||||
await DoEditCommand(ctx, []);
|
||||
await DoEditCommand(ctx, [], confirmYes);
|
||||
}
|
||||
|
||||
public async Task DoEditCommand(Context ctx, ICollection<PKMember>? members)
|
||||
public async Task DoEditCommand(Context ctx, ICollection<PKMember>? members, bool confirmYes)
|
||||
{
|
||||
if (members == null) members = new List<PKMember>();
|
||||
|
||||
|
|
@ -203,7 +203,7 @@ public class Switch
|
|||
msg = $"{Emojis.Warn} This will turn the latest switch ({lastSwitchMemberStr}, {lastSwitchDeltaStr} ago) into a switch-out. Is this okay?";
|
||||
else
|
||||
msg = $"{Emojis.Warn} This will change the latest switch ({lastSwitchMemberStr}, {lastSwitchDeltaStr} ago) to {newSwitchMemberStr}. Is this okay?";
|
||||
if (!await ctx.PromptYesNo(msg, "Edit")) throw Errors.SwitchEditCancelled;
|
||||
if (!await ctx.PromptYesNo(msg, "Edit", flagValue: confirmYes)) throw Errors.SwitchEditCancelled;
|
||||
|
||||
// Actually edit the switch
|
||||
await ctx.Repository.EditSwitch(conn, lastSwitch.Id, members.Select(m => m.Id).ToList());
|
||||
|
|
@ -217,7 +217,7 @@ public class Switch
|
|||
await ctx.Reply($"{Emojis.Success} Switch edited. Current fronters are now {newSwitchMemberStr}.");
|
||||
}
|
||||
|
||||
public async Task SwitchDelete(Context ctx, bool all)
|
||||
public async Task SwitchDelete(Context ctx, bool all = false, bool confirmYes = false)
|
||||
{
|
||||
ctx.CheckSystem();
|
||||
|
||||
|
|
@ -226,7 +226,7 @@ public class Switch
|
|||
// Subcommand: "delete all"
|
||||
var purgeMsg =
|
||||
$"{Emojis.Warn} This will delete *all registered switches* in your system. Are you sure you want to proceed?";
|
||||
if (!await ctx.PromptYesNo(purgeMsg, "Clear Switches"))
|
||||
if (!await ctx.PromptYesNo(purgeMsg, "Clear Switches", flagValue: confirmYes))
|
||||
throw Errors.GenericCancelled();
|
||||
await ctx.Repository.DeleteAllSwitches(ctx.System.Id);
|
||||
await ctx.Reply($"{Emojis.Success} Cleared system switches!");
|
||||
|
|
@ -258,7 +258,7 @@ public class Switch
|
|||
msg = $"{Emojis.Warn} This will delete the latest switch ({lastSwitchMemberStr}, {lastSwitchDeltaStr} ago). The next latest switch is {secondSwitchMemberStr} ({secondSwitchDeltaStr} ago). Is this okay?";
|
||||
}
|
||||
|
||||
if (!await ctx.PromptYesNo(msg, "Delete Switch")) throw Errors.SwitchDeleteCancelled;
|
||||
if (!await ctx.PromptYesNo(msg, "Delete Switch", flagValue: confirmYes)) throw Errors.SwitchDeleteCancelled;
|
||||
await ctx.Repository.DeleteSwitch(lastTwoSwitches[0].Id);
|
||||
|
||||
await ctx.Reply($"{Emojis.Success} Switch deleted.");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue