Add -yes flag to CheckYesNo (#198)
This commit is contained in:
parent
6054080dc7
commit
fd0e46f40d
@ -76,7 +76,7 @@ namespace PluralKit.Bot
|
|||||||
issueStr +=
|
issueStr +=
|
||||||
"\n- PluralKit does not support per-member system tags. Since you had multiple members with distinct tags, those tags will be applied to the members' *display names*/nicknames instead.";
|
"\n- PluralKit does not support per-member system tags. Since you had multiple members with distinct tags, those tags will be applied to the members' *display names*/nicknames instead.";
|
||||||
|
|
||||||
var msg = await ctx.Reply($"{issueStr}\n\nDo you want to proceed with the import?");
|
var msg = $"{issueStr}\n\nDo you want to proceed with the import?";
|
||||||
if (!await ctx.PromptYesNo(msg)) throw Errors.ImportCancelled;
|
if (!await ctx.PromptYesNo(msg)) throw Errors.ImportCancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ namespace PluralKit.Bot
|
|||||||
|
|
||||||
if (data.LinkedAccounts != null && !data.LinkedAccounts.Contains(ctx.Author.Id))
|
if (data.LinkedAccounts != null && !data.LinkedAccounts.Contains(ctx.Author.Id))
|
||||||
{
|
{
|
||||||
var msg = await ctx.Reply($"{Emojis.Warn} You seem to importing a system profile belonging to another account. Are you sure you want to proceed?");
|
var msg = $"{Emojis.Warn} You seem to importing a system profile belonging to another account. Are you sure you want to proceed?";
|
||||||
if (!await ctx.PromptYesNo(msg)) throw Errors.ImportCancelled;
|
if (!await ctx.PromptYesNo(msg)) throw Errors.ImportCancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ namespace PluralKit.Bot
|
|||||||
// Warn if there's already a member by this name
|
// Warn if there's already a member by this name
|
||||||
var existingMember = await _data.GetMemberByName(ctx.System, memberName);
|
var existingMember = await _data.GetMemberByName(ctx.System, memberName);
|
||||||
if (existingMember != null) {
|
if (existingMember != null) {
|
||||||
var msg = await ctx.Reply($"{Emojis.Warn} You already have a member in your system with the name \"{existingMember.NameFor(ctx)}\" (with ID `{existingMember.Hid}`). Do you want to create another member with the same name?");
|
var msg = $"{Emojis.Warn} You already have a member in your system with the name \"{existingMember.NameFor(ctx)}\" (with ID `{existingMember.Hid}`). Do you want to create another member with the same name?";
|
||||||
if (!await ctx.PromptYesNo(msg)) throw new PKError("Member creation cancelled.");
|
if (!await ctx.PromptYesNo(msg)) throw new PKError("Member creation cancelled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ namespace PluralKit.Bot
|
|||||||
// Warn if there's already a member by this name
|
// Warn if there's already a member by this name
|
||||||
var existingMember = await _data.GetMemberByName(ctx.System, newName);
|
var existingMember = await _data.GetMemberByName(ctx.System, newName);
|
||||||
if (existingMember != null) {
|
if (existingMember != null) {
|
||||||
var msg = await ctx.Reply($"{Emojis.Warn} You already have a member in your system with the name \"{existingMember.NameFor(ctx)}\" (`{existingMember.Hid}`). Do you want to rename this member to that name too?");
|
var msg = $"{Emojis.Warn} You already have a member in your system with the name \"{existingMember.NameFor(ctx)}\" (`{existingMember.Hid}`). Do you want to rename this member to that name too?";
|
||||||
if (!await ctx.PromptYesNo(msg)) throw new PKError("Member renaming cancelled.");
|
if (!await ctx.PromptYesNo(msg)) throw new PKError("Member renaming cancelled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,8 +39,7 @@ namespace PluralKit.Bot
|
|||||||
if (conflicts.Count <= 0) return true;
|
if (conflicts.Count <= 0) return true;
|
||||||
|
|
||||||
var conflictList = conflicts.Select(m => $"- **{m.NameFor(ctx)}**");
|
var conflictList = conflicts.Select(m => $"- **{m.NameFor(ctx)}**");
|
||||||
var msg = await ctx.Reply(
|
var msg = $"{Emojis.Warn} The following members have conflicting proxy tags:\n{string.Join('\n', conflictList)}\nDo you want to proceed anyway?";
|
||||||
$"{Emojis.Warn} The following members have conflicting proxy tags:\n{string.Join('\n', conflictList)}\nDo you want to proceed anyway?");
|
|
||||||
return await ctx.PromptYesNo(msg);
|
return await ctx.PromptYesNo(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,8 +49,7 @@ namespace PluralKit.Bot
|
|||||||
// If we already have multiple tags, this would clear everything, so prompt that
|
// If we already have multiple tags, this would clear everything, so prompt that
|
||||||
if (target.ProxyTags.Count > 1)
|
if (target.ProxyTags.Count > 1)
|
||||||
{
|
{
|
||||||
var msg = await ctx.Reply(
|
var msg = $"{Emojis.Warn} You already have multiple proxy tags set: {target.ProxyTagsString()}\nDo you want to clear them all?";
|
||||||
$"{Emojis.Warn} You already have multiple proxy tags set: {target.ProxyTagsString()}\nDo you want to clear them all?");
|
|
||||||
if (!await ctx.PromptYesNo(msg))
|
if (!await ctx.PromptYesNo(msg))
|
||||||
throw Errors.GenericCancelled();
|
throw Errors.GenericCancelled();
|
||||||
}
|
}
|
||||||
@ -119,7 +117,7 @@ namespace PluralKit.Bot
|
|||||||
// already more than one proxy tag.
|
// already more than one proxy tag.
|
||||||
if (target.ProxyTags.Count > 1)
|
if (target.ProxyTags.Count > 1)
|
||||||
{
|
{
|
||||||
var msg = await ctx.Reply($"This member already has more than one proxy tag set: {target.ProxyTagsString()}\nDo you want to replace them?");
|
var msg = $"This member already has more than one proxy tag set: {target.ProxyTagsString()}\nDo you want to replace them?";
|
||||||
if (!await ctx.PromptYesNo(msg))
|
if (!await ctx.PromptYesNo(msg))
|
||||||
throw Errors.GenericCancelled();
|
throw Errors.GenericCancelled();
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ namespace PluralKit.Bot
|
|||||||
var newSwitchDeltaStr = (SystemClock.Instance.GetCurrentInstant() - time.ToInstant()).FormatDuration();
|
var newSwitchDeltaStr = (SystemClock.Instance.GetCurrentInstant() - time.ToInstant()).FormatDuration();
|
||||||
|
|
||||||
// yeet
|
// yeet
|
||||||
var msg = await ctx.Reply($"{Emojis.Warn} This will move the latest switch ({lastSwitchMemberStr}) from {lastSwitchTimeStr} ({lastSwitchDeltaStr} ago) to {newSwitchTimeStr} ({newSwitchDeltaStr} ago). Is this OK?");
|
var msg = $"{Emojis.Warn} This will move the latest switch ({lastSwitchMemberStr}) from {lastSwitchTimeStr} ({lastSwitchDeltaStr} ago) to {newSwitchTimeStr} ({newSwitchDeltaStr} ago). Is this OK?";
|
||||||
if (!await ctx.PromptYesNo(msg)) throw Errors.SwitchMoveCancelled;
|
if (!await ctx.PromptYesNo(msg)) throw Errors.SwitchMoveCancelled;
|
||||||
|
|
||||||
// aaaand *now* we do the move
|
// aaaand *now* we do the move
|
||||||
@ -110,7 +110,7 @@ namespace PluralKit.Bot
|
|||||||
if (ctx.Match("all", "clear"))
|
if (ctx.Match("all", "clear"))
|
||||||
{
|
{
|
||||||
// Subcommand: "delete all"
|
// Subcommand: "delete all"
|
||||||
var purgeMsg = await ctx.Reply($"{Emojis.Warn} This will delete *all registered switches* in your system. Are you sure you want to proceed?");
|
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))
|
if (!await ctx.PromptYesNo(purgeMsg))
|
||||||
throw Errors.GenericCancelled();
|
throw Errors.GenericCancelled();
|
||||||
await _data.DeleteAllSwitches(ctx.System);
|
await _data.DeleteAllSwitches(ctx.System);
|
||||||
@ -126,19 +126,17 @@ namespace PluralKit.Bot
|
|||||||
var lastSwitchMemberStr = string.Join(", ", await lastSwitchMembers.Select(m => m.NameFor(ctx)).ToListAsync());
|
var lastSwitchMemberStr = string.Join(", ", await lastSwitchMembers.Select(m => m.NameFor(ctx)).ToListAsync());
|
||||||
var lastSwitchDeltaStr = (SystemClock.Instance.GetCurrentInstant() - lastTwoSwitches[0].Timestamp).FormatDuration();
|
var lastSwitchDeltaStr = (SystemClock.Instance.GetCurrentInstant() - lastTwoSwitches[0].Timestamp).FormatDuration();
|
||||||
|
|
||||||
DiscordMessage msg;
|
string msg;
|
||||||
if (lastTwoSwitches.Count == 1)
|
if (lastTwoSwitches.Count == 1)
|
||||||
{
|
{
|
||||||
msg = await ctx.Reply(
|
msg = $"{Emojis.Warn} This will delete the latest switch ({lastSwitchMemberStr}, {lastSwitchDeltaStr} ago). You have no other switches logged. Is this okay?";
|
||||||
$"{Emojis.Warn} This will delete the latest switch ({lastSwitchMemberStr}, {lastSwitchDeltaStr} ago). You have no other switches logged. Is this okay?");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var secondSwitchMembers = _data.GetSwitchMembers(lastTwoSwitches[1]);
|
var secondSwitchMembers = _data.GetSwitchMembers(lastTwoSwitches[1]);
|
||||||
var secondSwitchMemberStr = string.Join(", ", await secondSwitchMembers.Select(m => m.NameFor(ctx)).ToListAsync());
|
var secondSwitchMemberStr = string.Join(", ", await secondSwitchMembers.Select(m => m.NameFor(ctx)).ToListAsync());
|
||||||
var secondSwitchDeltaStr = (SystemClock.Instance.GetCurrentInstant() - lastTwoSwitches[1].Timestamp).FormatDuration();
|
var secondSwitchDeltaStr = (SystemClock.Instance.GetCurrentInstant() - lastTwoSwitches[1].Timestamp).FormatDuration();
|
||||||
msg = await ctx.Reply(
|
msg = $"{Emojis.Warn} This will delete the latest switch ({lastSwitchMemberStr}, {lastSwitchDeltaStr} ago). The next latest switch is {secondSwitchMemberStr} ({secondSwitchDeltaStr} ago). Is this okay?";
|
||||||
$"{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)) throw Errors.SwitchDeleteCancelled;
|
if (!await ctx.PromptYesNo(msg)) throw Errors.SwitchDeleteCancelled;
|
||||||
|
@ -249,8 +249,7 @@ namespace PluralKit.Bot
|
|||||||
if (zone == null) throw Errors.InvalidTimeZone(zoneStr);
|
if (zone == null) throw Errors.InvalidTimeZone(zoneStr);
|
||||||
|
|
||||||
var currentTime = SystemClock.Instance.GetCurrentInstant().InZone(zone);
|
var currentTime = SystemClock.Instance.GetCurrentInstant().InZone(zone);
|
||||||
var msg = await ctx.Reply(
|
var msg = $"This will change the system time zone to **{zone.Id}**. The current time is **{currentTime.FormatZoned()}**. Is this correct?";
|
||||||
$"This will change the system time zone to **{zone.Id}**. The current time is **{currentTime.FormatZoned()}**. Is this correct?");
|
|
||||||
if (!await ctx.PromptYesNo(msg)) throw Errors.TimezoneChangeCancelled;
|
if (!await ctx.PromptYesNo(msg)) throw Errors.TimezoneChangeCancelled;
|
||||||
|
|
||||||
var patch = new SystemPatch {UiTz = zone.Id};
|
var patch = new SystemPatch {UiTz = zone.Id};
|
||||||
|
@ -27,9 +27,9 @@ namespace PluralKit.Bot
|
|||||||
var existingAccount = await _data.GetSystemByAccount(account.Id);
|
var existingAccount = await _data.GetSystemByAccount(account.Id);
|
||||||
if (existingAccount != null) throw Errors.AccountInOtherSystem(existingAccount);
|
if (existingAccount != null) throw Errors.AccountInOtherSystem(existingAccount);
|
||||||
|
|
||||||
var msg = await ctx.Reply($"{account.Mention}, please confirm the link by clicking the {Emojis.Success} reaction on this message.",
|
var msg = $"{account.Mention}, please confirm the link by clicking the {Emojis.Success} reaction on this message.";
|
||||||
mentions: new IMention[] { new UserMention(account) });
|
var mentions = new IMention[] { new UserMention(account) };
|
||||||
if (!await ctx.PromptYesNo(msg, user: account)) throw Errors.MemberLinkCancelled;
|
if (!await ctx.PromptYesNo(msg, user: account, mentions: mentions)) throw Errors.MemberLinkCancelled;
|
||||||
await _data.AddAccount(ctx.System, account.Id);
|
await _data.AddAccount(ctx.System, account.Id);
|
||||||
await ctx.Reply($"{Emojis.Success} Account linked to system.");
|
await ctx.Reply($"{Emojis.Success} Account linked to system.");
|
||||||
}
|
}
|
||||||
@ -48,8 +48,7 @@ namespace PluralKit.Bot
|
|||||||
if (!accountIds.Contains(id)) throw Errors.AccountNotLinked;
|
if (!accountIds.Contains(id)) throw Errors.AccountNotLinked;
|
||||||
if (accountIds.Count == 1) throw Errors.UnlinkingLastAccount;
|
if (accountIds.Count == 1) throw Errors.UnlinkingLastAccount;
|
||||||
|
|
||||||
var msg = await ctx.Reply(
|
var msg = $"Are you sure you want to unlink <@{id}> from your system?";
|
||||||
$"Are you sure you want to unlink <@{id}> from your system?");
|
|
||||||
if (!await ctx.PromptYesNo(msg)) throw Errors.MemberUnlinkCancelled;
|
if (!await ctx.PromptYesNo(msg)) throw Errors.MemberUnlinkCancelled;
|
||||||
|
|
||||||
await _data.RemoveAccount(ctx.System, id);
|
await _data.RemoveAccount(ctx.System, id);
|
||||||
|
@ -17,8 +17,11 @@ using PluralKit.Core;
|
|||||||
|
|
||||||
namespace PluralKit.Bot {
|
namespace PluralKit.Bot {
|
||||||
public static class ContextUtils {
|
public static class ContextUtils {
|
||||||
public static async Task<bool> PromptYesNo(this Context ctx, DiscordMessage message, DiscordUser user = null, Duration? timeout = null)
|
public static async Task<bool> PromptYesNo(this Context ctx, String msgString, DiscordUser user = null, Duration? timeout = null, IEnumerable<IMention> mentions = null)
|
||||||
{
|
{
|
||||||
|
DiscordMessage message;
|
||||||
|
if (ctx.MatchFlag("y", "yes")) return true;
|
||||||
|
else message = await ctx.Reply(msgString, mentions: mentions);
|
||||||
var cts = new CancellationTokenSource();
|
var cts = new CancellationTokenSource();
|
||||||
if (user == null) user = ctx.Author;
|
if (user == null) user = ctx.Author;
|
||||||
if (timeout == null) timeout = Duration.FromMinutes(5);
|
if (timeout == null) timeout = Duration.FromMinutes(5);
|
||||||
|
Loading…
Reference in New Issue
Block a user