mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-15 18:20:11 +00:00
fix(bot): make deletion ID checks accept hyphens/caps
This commit is contained in:
parent
eccab602d5
commit
7965e15282
4 changed files with 20 additions and 15 deletions
|
|
@ -574,10 +574,10 @@ public class Groups
|
||||||
ctx.CheckOwnGroup(target);
|
ctx.CheckOwnGroup(target);
|
||||||
|
|
||||||
await ctx.Reply(
|
await ctx.Reply(
|
||||||
$"{Emojis.Warn} Are you sure you want to delete this group? If so, reply to this message with the group's ID (`{target.Hid}`).\n**Note: this action is permanent.**");
|
$"{Emojis.Warn} Are you sure you want to delete this group? If so, reply to this message with the group's ID (`{target.DisplayHid(ctx.Config)}`).\n**Note: this action is permanent.**");
|
||||||
if (!await ctx.ConfirmWithReply(target.Hid))
|
if (!await ctx.ConfirmWithReply(target.Hid, treatAsHid: true))
|
||||||
throw new PKError(
|
throw new PKError(
|
||||||
$"Group deletion cancelled. Note that you must reply with your group ID (`{target.Hid}`) *verbatim*.");
|
$"Group deletion cancelled. Note that you must reply with your group ID (`{target.DisplayHid(ctx.Config)}`) *verbatim*.");
|
||||||
|
|
||||||
await ctx.Repository.DeleteGroup(target.Id);
|
await ctx.Repository.DeleteGroup(target.Id);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -816,8 +816,8 @@ public class MemberEdit
|
||||||
ctx.CheckSystem().CheckOwnMember(target);
|
ctx.CheckSystem().CheckOwnMember(target);
|
||||||
|
|
||||||
await ctx.Reply(
|
await ctx.Reply(
|
||||||
$"{Emojis.Warn} Are you sure you want to delete \"{target.NameFor(ctx)}\"? If so, reply to this message with the member's ID (`{target.Hid}`). __***This cannot be undone!***__");
|
$"{Emojis.Warn} Are you sure you want to delete \"{target.NameFor(ctx)}\"? If so, reply to this message with the member's ID (`{target.DisplayHid(ctx.Config)}`). __***This cannot be undone!***__");
|
||||||
if (!await ctx.ConfirmWithReply(target.Hid)) throw Errors.MemberDeleteCancelled;
|
if (!await ctx.ConfirmWithReply(target.Hid, treatAsHid: true)) throw Errors.MemberDeleteCancelled;
|
||||||
|
|
||||||
await ctx.Repository.DeleteMember(target.Id);
|
await ctx.Repository.DeleteMember(target.Id);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -670,19 +670,20 @@ public class SystemEdit
|
||||||
public async Task Delete(Context ctx, PKSystem target)
|
public async Task Delete(Context ctx, PKSystem target)
|
||||||
{
|
{
|
||||||
ctx.CheckSystem().CheckOwnSystem(target);
|
ctx.CheckSystem().CheckOwnSystem(target);
|
||||||
|
var noExport = ctx.MatchFlag("ne", "no-export");
|
||||||
|
|
||||||
await ctx.Reply(
|
var warnMsg = $"{Emojis.Warn} Are you sure you want to delete your system? If so, reply to this message with your system's ID (`{target.DisplayHid(ctx.Config)}`).\n";
|
||||||
$"{Emojis.Warn} Are you sure you want to delete your system? If so, reply to this message with your system's ID (`{target.Hid}`).\n"
|
if (!noExport)
|
||||||
+ $"**Note: this action is permanent,** but you will get a copy of your system's data that can be re-imported into PluralKit at a later date sent to you in DMs."
|
warnMsg += "**Note: this action is permanent,** but you will get a copy of your system's data that can be re-imported into PluralKit at a later date sent to you in DMs."
|
||||||
+ " If you don't want this to happen, use `pk;s delete -no-export` instead.");
|
+ " If you don't want this to happen, use `pk;s delete -no-export` instead.";
|
||||||
if (!await ctx.ConfirmWithReply(target.Hid))
|
|
||||||
|
await ctx.Reply(warnMsg);
|
||||||
|
if (!await ctx.ConfirmWithReply(target.Hid, treatAsHid: true))
|
||||||
throw new PKError(
|
throw new PKError(
|
||||||
$"System deletion cancelled. Note that you must reply with your system ID (`{target.Hid}`) *verbatim*.");
|
$"System deletion cancelled. Note that you must reply with your system ID (`{target.DisplayHid(ctx.Config)}`) *verbatim*.");
|
||||||
|
|
||||||
// If the user confirms the deletion, export their system and send them the export file before actually
|
// If the user confirms the deletion, export their system and send them the export file before actually
|
||||||
// deleting their system, unless they specifically tell us not to do an export.
|
// deleting their system, unless they specifically tell us not to do an export.
|
||||||
|
|
||||||
var noExport = ctx.MatchFlag("ne", "no-export");
|
|
||||||
if (!noExport)
|
if (!noExport)
|
||||||
{
|
{
|
||||||
var json = await ctx.BusyIndicator(async () =>
|
var json = await ctx.BusyIndicator(async () =>
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ public static class ContextUtils
|
||||||
.WaitFor(ReactionPredicate, timeout);
|
.WaitFor(ReactionPredicate, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<bool> ConfirmWithReply(this Context ctx, string expectedReply)
|
public static async Task<bool> ConfirmWithReply(this Context ctx, string expectedReply, bool treatAsHid = false)
|
||||||
{
|
{
|
||||||
bool Predicate(MessageCreateEvent e) =>
|
bool Predicate(MessageCreateEvent e) =>
|
||||||
e.Author.Id == ctx.Author.Id && e.ChannelId == ctx.Channel.Id;
|
e.Author.Id == ctx.Author.Id && e.ChannelId == ctx.Channel.Id;
|
||||||
|
|
@ -63,7 +63,11 @@ public static class ContextUtils
|
||||||
var msg = await ctx.Services.Resolve<HandlerQueue<MessageCreateEvent>>()
|
var msg = await ctx.Services.Resolve<HandlerQueue<MessageCreateEvent>>()
|
||||||
.WaitFor(Predicate, Duration.FromMinutes(1));
|
.WaitFor(Predicate, Duration.FromMinutes(1));
|
||||||
|
|
||||||
return string.Equals(msg.Content, expectedReply, StringComparison.InvariantCultureIgnoreCase);
|
var content = msg.Content;
|
||||||
|
if (treatAsHid)
|
||||||
|
content = content.ToLower().Replace("-", null);
|
||||||
|
|
||||||
|
return string.Equals(content, expectedReply, StringComparison.InvariantCultureIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task Paginate<T>(this Context ctx, IAsyncEnumerable<T> items, int totalCount,
|
public static async Task Paginate<T>(this Context ctx, IAsyncEnumerable<T> items, int totalCount,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue