Merge pull request #226 from dev-kittens/confirm-clear
Confirm before clearing entity properties
This commit is contained in:
commit
b8e447274a
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -60,8 +60,13 @@ namespace PluralKit.Bot
|
|||||||
return potentialMatches.Any(potentialMatch => flags.Contains(potentialMatch));
|
return potentialMatches.Any(potentialMatch => flags.Contains(potentialMatch));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool MatchClear(this Context ctx) =>
|
public static async Task<bool> MatchClear(this Context ctx, string toClear = null)
|
||||||
ctx.Match("clear", "reset") || ctx.MatchFlag("c", "clear");
|
{
|
||||||
|
var matched = ctx.Match("clear", "reset") || ctx.MatchFlag("c", "clear");
|
||||||
|
Console.WriteLine(toClear);
|
||||||
|
if (matched && toClear != null) return await ctx.ConfirmClear(toClear);
|
||||||
|
else return matched;
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task<List<PKMember>> ParseMemberList(this Context ctx, SystemId? restrictToSystem)
|
public static async Task<List<PKMember>> ParseMemberList(this Context ctx, SystemId? restrictToSystem)
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -87,7 +87,7 @@ namespace PluralKit.Bot
|
|||||||
|
|
||||||
public async Task GroupDisplayName(Context ctx, PKGroup target)
|
public async Task GroupDisplayName(Context ctx, PKGroup target)
|
||||||
{
|
{
|
||||||
if (ctx.MatchClear())
|
if (await ctx.MatchClear("this group's display name"))
|
||||||
{
|
{
|
||||||
ctx.CheckOwnGroup(target);
|
ctx.CheckOwnGroup(target);
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ namespace PluralKit.Bot
|
|||||||
|
|
||||||
public async Task GroupDescription(Context ctx, PKGroup target)
|
public async Task GroupDescription(Context ctx, PKGroup target)
|
||||||
{
|
{
|
||||||
if (ctx.MatchClear())
|
if (await ctx.MatchClear("this group's description"))
|
||||||
{
|
{
|
||||||
ctx.CheckOwnGroup(target);
|
ctx.CheckOwnGroup(target);
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ namespace PluralKit.Bot
|
|||||||
throw new PKSyntaxError("This group does not have an icon set. Set one by attaching an image to this command, or by passing an image URL or @mention.");
|
throw new PKSyntaxError("This group does not have an icon set. Set one by attaching an image to this command, or by passing an image URL or @mention.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.MatchClear())
|
if (await ctx.MatchClear("this group's icon"))
|
||||||
await ClearIcon();
|
await ClearIcon();
|
||||||
else if (await ctx.MatchImage() is {} img)
|
else if (await ctx.MatchImage() is {} img)
|
||||||
await SetIcon(img);
|
await SetIcon(img);
|
||||||
|
@ -85,7 +85,7 @@ namespace PluralKit.Bot
|
|||||||
private async Task AvatarCommandTree(AvatarLocation location, Context ctx, PKMember target, MemberGuildSettings? guildData)
|
private async Task AvatarCommandTree(AvatarLocation location, Context ctx, PKMember target, MemberGuildSettings? guildData)
|
||||||
{
|
{
|
||||||
// First, see if we need to *clear*
|
// First, see if we need to *clear*
|
||||||
if (ctx.MatchClear())
|
if (await ctx.MatchClear("this member's avatar"))
|
||||||
{
|
{
|
||||||
ctx.CheckSystem().CheckOwnMember(target);
|
ctx.CheckSystem().CheckOwnMember(target);
|
||||||
await AvatarClear(location, ctx, target, guildData);
|
await AvatarClear(location, ctx, target, guildData);
|
||||||
|
@ -64,7 +64,7 @@ namespace PluralKit.Bot
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task Description(Context ctx, PKMember target) {
|
public async Task Description(Context ctx, PKMember target) {
|
||||||
if (ctx.MatchClear())
|
if (await ctx.MatchClear("this member's description"))
|
||||||
{
|
{
|
||||||
CheckEditMemberPermission(ctx, target);
|
CheckEditMemberPermission(ctx, target);
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ namespace PluralKit.Bot
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task Pronouns(Context ctx, PKMember target) {
|
public async Task Pronouns(Context ctx, PKMember target) {
|
||||||
if (ctx.MatchClear())
|
if (await ctx.MatchClear("this member's pronouns"))
|
||||||
{
|
{
|
||||||
CheckEditMemberPermission(ctx, target);
|
CheckEditMemberPermission(ctx, target);
|
||||||
var patch = new MemberPatch {Pronouns = Partial<string>.Null()};
|
var patch = new MemberPatch {Pronouns = Partial<string>.Null()};
|
||||||
@ -145,7 +145,7 @@ namespace PluralKit.Bot
|
|||||||
public async Task Color(Context ctx, PKMember target)
|
public async Task Color(Context ctx, PKMember target)
|
||||||
{
|
{
|
||||||
var color = ctx.RemainderOrNull();
|
var color = ctx.RemainderOrNull();
|
||||||
if (ctx.MatchClear())
|
if (await ctx.MatchClear())
|
||||||
{
|
{
|
||||||
CheckEditMemberPermission(ctx, target);
|
CheckEditMemberPermission(ctx, target);
|
||||||
|
|
||||||
@ -193,7 +193,7 @@ namespace PluralKit.Bot
|
|||||||
}
|
}
|
||||||
public async Task Birthday(Context ctx, PKMember target)
|
public async Task Birthday(Context ctx, PKMember target)
|
||||||
{
|
{
|
||||||
if (ctx.MatchClear())
|
if (await ctx.MatchClear("this member's birthday"))
|
||||||
{
|
{
|
||||||
CheckEditMemberPermission(ctx, target);
|
CheckEditMemberPermission(ctx, target);
|
||||||
|
|
||||||
@ -279,7 +279,7 @@ namespace PluralKit.Bot
|
|||||||
await ctx.Reply(successStr);
|
await ctx.Reply(successStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.MatchClear())
|
if (await ctx.MatchClear("this member's display name"))
|
||||||
{
|
{
|
||||||
CheckEditMemberPermission(ctx, target);
|
CheckEditMemberPermission(ctx, target);
|
||||||
|
|
||||||
@ -313,7 +313,7 @@ namespace PluralKit.Bot
|
|||||||
{
|
{
|
||||||
ctx.CheckGuildContext();
|
ctx.CheckGuildContext();
|
||||||
|
|
||||||
if (ctx.MatchClear())
|
if (await ctx.MatchClear("this member's server name"))
|
||||||
{
|
{
|
||||||
CheckEditMemberPermission(ctx, target);
|
CheckEditMemberPermission(ctx, target);
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Dapper;
|
using Dapper;
|
||||||
@ -46,7 +46,7 @@ namespace PluralKit.Bot
|
|||||||
}
|
}
|
||||||
|
|
||||||
// "Sub"command: clear flag
|
// "Sub"command: clear flag
|
||||||
if (ctx.MatchClear())
|
if (await ctx.MatchClear())
|
||||||
{
|
{
|
||||||
// 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)
|
||||||
|
@ -32,7 +32,7 @@ namespace PluralKit.Bot
|
|||||||
{
|
{
|
||||||
ctx.CheckSystem();
|
ctx.CheckSystem();
|
||||||
|
|
||||||
if (ctx.MatchClear())
|
if (await ctx.MatchClear("your system's name"))
|
||||||
{
|
{
|
||||||
var clearPatch = new SystemPatch {Name = null};
|
var clearPatch = new SystemPatch {Name = null};
|
||||||
await _db.Execute(conn => _repo.UpdateSystem(conn, ctx.System.Id, clearPatch));
|
await _db.Execute(conn => _repo.UpdateSystem(conn, ctx.System.Id, clearPatch));
|
||||||
@ -63,7 +63,7 @@ namespace PluralKit.Bot
|
|||||||
public async Task Description(Context ctx) {
|
public async Task Description(Context ctx) {
|
||||||
ctx.CheckSystem();
|
ctx.CheckSystem();
|
||||||
|
|
||||||
if (ctx.MatchClear())
|
if (await ctx.MatchClear("your system's description"))
|
||||||
{
|
{
|
||||||
var patch = new SystemPatch {Description = null};
|
var patch = new SystemPatch {Description = null};
|
||||||
await _db.Execute(conn => _repo.UpdateSystem(conn, ctx.System.Id, patch));
|
await _db.Execute(conn => _repo.UpdateSystem(conn, ctx.System.Id, patch));
|
||||||
@ -101,7 +101,7 @@ namespace PluralKit.Bot
|
|||||||
{
|
{
|
||||||
ctx.CheckSystem();
|
ctx.CheckSystem();
|
||||||
|
|
||||||
if (ctx.MatchClear())
|
if (await ctx.MatchClear("your system's tag"))
|
||||||
{
|
{
|
||||||
var patch = new SystemPatch {Tag = null};
|
var patch = new SystemPatch {Tag = null};
|
||||||
await _db.Execute(conn => _repo.UpdateSystem(conn, ctx.System.Id, patch));
|
await _db.Execute(conn => _repo.UpdateSystem(conn, ctx.System.Id, patch));
|
||||||
@ -175,7 +175,7 @@ namespace PluralKit.Bot
|
|||||||
throw new PKSyntaxError("This system does not have an icon set. Set one by attaching an image to this command, or by passing an image URL or @mention.");
|
throw new PKSyntaxError("This system does not have an icon set. Set one by attaching an image to this command, or by passing an image URL or @mention.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.MatchClear())
|
if (await ctx.MatchClear("your system's icon"))
|
||||||
await ClearIcon();
|
await ClearIcon();
|
||||||
else if (await ctx.MatchImage() is {} img)
|
else if (await ctx.MatchImage() is {} img)
|
||||||
await SetIcon(img);
|
await SetIcon(img);
|
||||||
@ -226,7 +226,7 @@ namespace PluralKit.Bot
|
|||||||
{
|
{
|
||||||
if (ctx.System == null) throw Errors.NoSystemError;
|
if (ctx.System == null) throw Errors.NoSystemError;
|
||||||
|
|
||||||
if (ctx.MatchClear())
|
if (await ctx.MatchClear())
|
||||||
{
|
{
|
||||||
var clearPatch = new SystemPatch {UiTz = "UTC"};
|
var clearPatch = new SystemPatch {UiTz = "UTC"};
|
||||||
await _db.Execute(conn => _repo.UpdateSystem(conn, ctx.System.Id, clearPatch));
|
await _db.Execute(conn => _repo.UpdateSystem(conn, ctx.System.Id, clearPatch));
|
||||||
|
@ -17,6 +17,12 @@ using PluralKit.Core;
|
|||||||
|
|
||||||
namespace PluralKit.Bot {
|
namespace PluralKit.Bot {
|
||||||
public static class ContextUtils {
|
public static class ContextUtils {
|
||||||
|
public static async Task<bool> ConfirmClear(this Context ctx, string toClear)
|
||||||
|
{
|
||||||
|
if (!(await ctx.PromptYesNo($"{Emojis.Warn} Are you sure you want to clear {toClear}?"))) throw Errors.GenericCancelled();
|
||||||
|
else return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task<bool> PromptYesNo(this Context ctx, String msgString, DiscordUser user = null, Duration? timeout = null, IEnumerable<IMention> mentions = null, bool matchFlag = true)
|
public static async Task<bool> PromptYesNo(this Context ctx, String msgString, DiscordUser user = null, Duration? timeout = null, IEnumerable<IMention> mentions = null, bool matchFlag = true)
|
||||||
{
|
{
|
||||||
DiscordMessage message;
|
DiscordMessage message;
|
||||||
|
Loading…
Reference in New Issue
Block a user