refactor(bot): separate MatchClear from ConfirmClear
This commit is contained in:
parent
f06fdb38ef
commit
f9abcc68c4
@ -88,15 +88,7 @@ public static class ContextArgumentsExt
|
||||
return potentialMatches.Any(potentialMatch => flags.Contains(potentialMatch));
|
||||
}
|
||||
|
||||
public static async Task<bool> MatchClear(this Context ctx, string toClear = null)
|
||||
{
|
||||
var matched = ctx.MatchClearInner();
|
||||
if (matched && toClear != null)
|
||||
return await ctx.ConfirmClear(toClear);
|
||||
return matched;
|
||||
}
|
||||
|
||||
private static bool MatchClearInner(this Context ctx)
|
||||
public static bool MatchClear(this Context ctx)
|
||||
=> ctx.Match("clear", "reset", "default") || ctx.MatchFlag("c", "clear");
|
||||
|
||||
public static bool MatchRaw(this Context ctx) =>
|
||||
@ -111,7 +103,7 @@ public static class ContextArgumentsExt
|
||||
|
||||
public static bool? MatchToggleOrNull(this Context ctx, bool? defaultValue = null)
|
||||
{
|
||||
if (defaultValue != null && ctx.MatchClearInner())
|
||||
if (defaultValue != null && ctx.MatchClear())
|
||||
return defaultValue.Value;
|
||||
|
||||
var yesToggles = new[] { "yes", "on", "enable", "enabled", "true" };
|
||||
|
@ -128,7 +128,7 @@ public class Api
|
||||
return;
|
||||
}
|
||||
|
||||
if (await ctx.MatchClear("your system's webhook URL"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("your system's webhook URL"))
|
||||
{
|
||||
await ctx.Repository.UpdateSystem(ctx.System.Id, new SystemPatch { WebhookUrl = null, WebhookToken = null });
|
||||
|
||||
|
@ -173,7 +173,7 @@ public class Config
|
||||
Duration? newTimeout;
|
||||
Duration overflow = Duration.Zero;
|
||||
if (ctx.Match("off", "stop", "cancel", "no", "disable", "remove")) newTimeout = Duration.Zero;
|
||||
else if (await ctx.MatchClear()) newTimeout = null;
|
||||
else if (ctx.MatchClear()) newTimeout = null;
|
||||
else
|
||||
{
|
||||
var timeoutStr = ctx.RemainderOrNull();
|
||||
@ -204,7 +204,7 @@ public class Config
|
||||
{
|
||||
if (ctx.System == null) throw Errors.NoSystemError;
|
||||
|
||||
if (await ctx.MatchClear())
|
||||
if (ctx.MatchClear())
|
||||
{
|
||||
await ctx.Repository.UpdateSystemConfig(ctx.System.Id, new() { UiTz = "UTC" });
|
||||
|
||||
|
@ -170,7 +170,7 @@ public class Groups
|
||||
|
||||
ctx.CheckOwnGroup(target);
|
||||
|
||||
if (await ctx.MatchClear("this group's display name"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("this group's display name"))
|
||||
{
|
||||
var patch = new GroupPatch { DisplayName = Partial<string>.Null() };
|
||||
await ctx.Repository.UpdateGroup(target.Id, patch);
|
||||
@ -228,7 +228,7 @@ public class Groups
|
||||
|
||||
ctx.CheckOwnGroup(target);
|
||||
|
||||
if (await ctx.MatchClear("this group's description"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("this group's description"))
|
||||
{
|
||||
var patch = new GroupPatch { Description = Partial<string>.Null() };
|
||||
await ctx.Repository.UpdateGroup(target.Id, patch);
|
||||
@ -304,7 +304,7 @@ public class Groups
|
||||
}
|
||||
}
|
||||
|
||||
if (await ctx.MatchClear("this group's icon"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("this group's icon"))
|
||||
await ClearIcon();
|
||||
else if (await ctx.MatchImage() is { } img)
|
||||
await SetIcon(img);
|
||||
@ -368,7 +368,7 @@ public class Groups
|
||||
}
|
||||
}
|
||||
|
||||
if (await ctx.MatchClear("this group's banner image"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("this group's banner image"))
|
||||
await ClearBannerImage();
|
||||
else if (await ctx.MatchImage() is { } img)
|
||||
await SetBannerImage(img);
|
||||
@ -380,7 +380,7 @@ public class Groups
|
||||
{
|
||||
var isOwnSystem = ctx.System?.Id == target.System;
|
||||
var matchedRaw = ctx.MatchRaw();
|
||||
var matchedClear = await ctx.MatchClear();
|
||||
var matchedClear = ctx.MatchClear();
|
||||
|
||||
if (!isOwnSystem || !(ctx.HasNext() || matchedClear))
|
||||
{
|
||||
|
@ -91,7 +91,7 @@ public class MemberAvatar
|
||||
MemberGuildSettings? guildData)
|
||||
{
|
||||
// First, see if we need to *clear*
|
||||
if (await ctx.MatchClear(location == AvatarLocation.Server
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear(location == AvatarLocation.Server
|
||||
? "this member's server avatar"
|
||||
: "this member's avatar"))
|
||||
{
|
||||
|
@ -97,7 +97,7 @@ public class MemberEdit
|
||||
|
||||
ctx.CheckOwnMember(target);
|
||||
|
||||
if (await ctx.MatchClear("this member's description"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("this member's description"))
|
||||
{
|
||||
var patch = new MemberPatch { Description = Partial<string>.Null() };
|
||||
await ctx.Repository.UpdateMember(target.Id, patch);
|
||||
@ -149,7 +149,7 @@ public class MemberEdit
|
||||
|
||||
ctx.CheckOwnMember(target);
|
||||
|
||||
if (await ctx.MatchClear("this member's pronouns"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("this member's pronouns"))
|
||||
{
|
||||
var patch = new MemberPatch { Pronouns = Partial<string>.Null() };
|
||||
await ctx.Repository.UpdateMember(target.Id, patch);
|
||||
@ -217,7 +217,7 @@ public class MemberEdit
|
||||
}
|
||||
}
|
||||
|
||||
if (await ctx.MatchClear("this member's banner image"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("this member's banner image"))
|
||||
await ClearBannerImage();
|
||||
else if (await ctx.MatchImage() is { } img)
|
||||
await SetBannerImage(img);
|
||||
@ -229,7 +229,7 @@ public class MemberEdit
|
||||
{
|
||||
var isOwnSystem = ctx.System?.Id == target.System;
|
||||
var matchedRaw = ctx.MatchRaw();
|
||||
var matchedClear = await ctx.MatchClear();
|
||||
var matchedClear = ctx.MatchClear();
|
||||
|
||||
if (!isOwnSystem || !(ctx.HasNext() || matchedClear))
|
||||
{
|
||||
@ -277,7 +277,7 @@ public class MemberEdit
|
||||
|
||||
public async Task Birthday(Context ctx, PKMember target)
|
||||
{
|
||||
if (await ctx.MatchClear("this member's birthday"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("this member's birthday"))
|
||||
{
|
||||
ctx.CheckOwnMember(target);
|
||||
|
||||
@ -408,7 +408,7 @@ public class MemberEdit
|
||||
|
||||
ctx.CheckOwnMember(target);
|
||||
|
||||
if (await ctx.MatchClear("this member's display name"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("this member's display name"))
|
||||
{
|
||||
var patch = new MemberPatch { DisplayName = Partial<string>.Null() };
|
||||
await ctx.Repository.UpdateMember(target.Id, patch);
|
||||
@ -468,7 +468,7 @@ public class MemberEdit
|
||||
|
||||
ctx.CheckOwnMember(target);
|
||||
|
||||
if (await ctx.MatchClear("this member's server name"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("this member's server name"))
|
||||
{
|
||||
await ctx.Repository.UpdateMemberGuild(target.Id, ctx.Guild.Id, new MemberGuildPatch { DisplayName = null });
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class MemberProxy
|
||||
}
|
||||
|
||||
// "Sub"command: clear flag
|
||||
if (await ctx.MatchClear())
|
||||
if (ctx.MatchClear())
|
||||
{
|
||||
// If we already have multiple tags, this would clear everything, so prompt that
|
||||
if (target.ProxyTags.Count > 1)
|
||||
|
@ -23,7 +23,7 @@ public class ServerConfig
|
||||
await ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");
|
||||
var settings = await ctx.Repository.GetGuild(ctx.Guild.Id);
|
||||
|
||||
if (await ctx.MatchClear("the server log channel"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("the server log channel"))
|
||||
{
|
||||
await ctx.Repository.UpdateGuild(ctx.Guild.Id, new GuildPatch { LogChannel = null });
|
||||
await ctx.Reply($"{Emojis.Success} Proxy logging channel cleared.");
|
||||
|
@ -57,7 +57,7 @@ public class SystemEdit
|
||||
|
||||
ctx.CheckSystem().CheckOwnSystem(target);
|
||||
|
||||
if (await ctx.MatchClear("your system's name"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("your system's name"))
|
||||
{
|
||||
await ctx.Repository.UpdateSystem(target.Id, new SystemPatch { Name = null });
|
||||
|
||||
@ -113,7 +113,7 @@ public class SystemEdit
|
||||
|
||||
ctx.CheckSystem().CheckOwnSystem(target);
|
||||
|
||||
if (await ctx.MatchClear("your system's description"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("your system's description"))
|
||||
{
|
||||
await ctx.Repository.UpdateSystem(target.Id, new SystemPatch { Description = null });
|
||||
|
||||
@ -135,7 +135,7 @@ public class SystemEdit
|
||||
{
|
||||
var isOwnSystem = ctx.System?.Id == target.Id;
|
||||
var matchedRaw = ctx.MatchRaw();
|
||||
var matchedClear = await ctx.MatchClear();
|
||||
var matchedClear = ctx.MatchClear();
|
||||
|
||||
if (!isOwnSystem || !(ctx.HasNext() || matchedClear))
|
||||
{
|
||||
@ -210,7 +210,7 @@ public class SystemEdit
|
||||
|
||||
ctx.CheckSystem().CheckOwnSystem(target);
|
||||
|
||||
if (await ctx.MatchClear("your system's tag"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("your system's tag"))
|
||||
{
|
||||
await ctx.Repository.UpdateSystem(target.Id, new SystemPatch { Tag = null });
|
||||
|
||||
@ -337,7 +337,7 @@ public class SystemEdit
|
||||
return str;
|
||||
}
|
||||
|
||||
if (await ctx.MatchClear("your system's server tag"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("your system's server tag"))
|
||||
await Clear();
|
||||
else if (ctx.Match("disable") || ctx.MatchFlag("disable"))
|
||||
await EnableDisable(false);
|
||||
@ -384,7 +384,7 @@ public class SystemEdit
|
||||
|
||||
ctx.CheckSystem().CheckOwnSystem(target);
|
||||
|
||||
if (await ctx.MatchClear("your system's pronouns"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("your system's pronouns"))
|
||||
{
|
||||
await ctx.Repository.UpdateSystem(target.Id, new SystemPatch { Pronouns = null });
|
||||
|
||||
@ -463,7 +463,7 @@ public class SystemEdit
|
||||
return;
|
||||
}
|
||||
|
||||
if (await ctx.MatchClear("your system's icon"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("your system's icon"))
|
||||
await ClearIcon();
|
||||
else if (await ctx.MatchImage() is { } img)
|
||||
await SetIcon(img);
|
||||
@ -501,7 +501,7 @@ public class SystemEdit
|
||||
|
||||
ctx.CheckSystem().CheckOwnSystem(target);
|
||||
|
||||
if (await ctx.MatchClear("your system's banner image"))
|
||||
if (ctx.MatchClear() && await ctx.ConfirmClear("your system's banner image"))
|
||||
{
|
||||
await ctx.Repository.UpdateSystem(target.Id, new SystemPatch { BannerImage = null });
|
||||
await ctx.Reply($"{Emojis.Success} System banner image cleared.");
|
||||
|
Loading…
Reference in New Issue
Block a user