diff --git a/PluralKit.Bot/Commands/Groups.cs b/PluralKit.Bot/Commands/Groups.cs index 4b92f369..eb47d19c 100644 --- a/PluralKit.Bot/Commands/Groups.cs +++ b/PluralKit.Bot/Commands/Groups.cs @@ -374,38 +374,39 @@ public class Groups public async Task GroupColor(Context ctx, PKGroup target) { - var color = ctx.RemainderOrNull(); - if (await ctx.MatchClear()) - { - ctx.CheckOwnGroup(target); + var isOwnSystem = ctx.System?.Id == target.System; + var matchedRaw = ctx.MatchRaw(); + var matchedClear = await ctx.MatchClear(); - var patch = new GroupPatch { Color = Partial.Null() }; - await ctx.Repository.UpdateGroup(target.Id, patch); - - await ctx.Reply($"{Emojis.Success} Group color cleared."); - } - else if (!ctx.HasNext()) + if (!isOwnSystem || !(ctx.HasNext() || matchedClear)) { if (target.Color == null) - if (ctx.System?.Id == target.System) - await ctx.Reply( - $"This group does not have a color set. To set one, type `pk;group {target.Reference(ctx)} color `."); - else - await ctx.Reply("This group does not have a color set."); + await ctx.Reply( + "This group does not have a color set." + (isOwnSystem ? $" To set one, type `pk;group {target.Reference(ctx)} color `." : "")); + else if (matchedRaw) + await ctx.Reply("```\n#" + target.Color + "\n```"); else await ctx.Reply(embed: new EmbedBuilder() .Title("Group color") .Color(target.Color.ToDiscordColor()) .Thumbnail(new Embed.EmbedThumbnail($"https://fakeimg.pl/256x256/{target.Color}/?text=%20")) .Description($"This group's color is **#{target.Color}**." - + (ctx.System?.Id == target.System - ? $" To clear it, type `pk;group {target.Reference(ctx)} color -clear`." - : "")) + + (isOwnSystem ? $" To clear it, type `pk;group {target.Reference(ctx)} color -clear`." : "")) .Build()); + return; + } + + ctx.CheckSystem().CheckOwnGroup(target); + + if (matchedClear) + { + await ctx.Repository.UpdateGroup(target.Id, new() { Color = Partial.Null() }); + + await ctx.Reply($"{Emojis.Success} Group color cleared."); } else { - ctx.CheckOwnGroup(target); + var color = ctx.RemainderOrNull(); if (color.StartsWith("#")) color = color.Substring(1); if (!Regex.IsMatch(color, "^[0-9a-fA-F]{6}$")) throw Errors.InvalidColorError(color); diff --git a/PluralKit.Bot/Commands/MemberEdit.cs b/PluralKit.Bot/Commands/MemberEdit.cs index 2d027145..ed02dfba 100644 --- a/PluralKit.Bot/Commands/MemberEdit.cs +++ b/PluralKit.Bot/Commands/MemberEdit.cs @@ -225,41 +225,39 @@ public class MemberEdit public async Task Color(Context ctx, PKMember target) { - var color = ctx.RemainderOrNull(); - if (await ctx.MatchClear()) + var isOwnSystem = ctx.System?.Id == target.System; + var matchedRaw = ctx.MatchRaw(); + var matchedClear = await ctx.MatchClear(); + + if (!isOwnSystem || !(ctx.HasNext() || matchedClear)) { - ctx.CheckOwnMember(target); - - var patch = new MemberPatch { Color = Partial.Null() }; - await ctx.Repository.UpdateMember(target.Id, patch); - - await ctx.Reply($"{Emojis.Success} Member color cleared."); - } - else if (!ctx.HasNext()) - { - // if (!target.ColorPrivacy.CanAccess(ctx.LookupContextFor(target.System))) - // throw Errors.LookupNotAllowed; - if (target.Color == null) - if (ctx.System?.Id == target.System) - await ctx.Reply( - $"This member does not have a color set. To set one, type `pk;member {target.Reference(ctx)} color `."); - else - await ctx.Reply("This member does not have a color set."); + await ctx.Reply( + "This member does not have a color set." + (isOwnSystem ? $" To set one, type `pk;member {target.Reference(ctx)} color `." : "")); + else if (matchedRaw) + await ctx.Reply("```\n#" + target.Color + "\n```"); else await ctx.Reply(embed: new EmbedBuilder() .Title("Member color") .Color(target.Color.ToDiscordColor()) .Thumbnail(new Embed.EmbedThumbnail($"https://fakeimg.pl/256x256/{target.Color}/?text=%20")) .Description($"This member's color is **#{target.Color}**." - + (ctx.System?.Id == target.System - ? $" To clear it, type `pk;member {target.Reference(ctx)} color -clear`." - : "")) + + (isOwnSystem ? $" To clear it, type `pk;member {target.Reference(ctx)} color -clear`." : "")) .Build()); + return; + } + + ctx.CheckSystem().CheckOwnMember(target); + + if (matchedClear) + { + await ctx.Repository.UpdateMember(target.Id, new() { Color = Partial.Null() }); + + await ctx.Reply($"{Emojis.Success} Member color cleared."); } else { - ctx.CheckOwnMember(target); + var color = ctx.RemainderOrNull(); if (color.StartsWith("#")) color = color.Substring(1); if (!Regex.IsMatch(color, "^[0-9a-fA-F]{6}$")) throw Errors.InvalidColorError(color); diff --git a/PluralKit.Bot/Commands/SystemEdit.cs b/PluralKit.Bot/Commands/SystemEdit.cs index ae78fd40..32097be6 100644 --- a/PluralKit.Bot/Commands/SystemEdit.cs +++ b/PluralKit.Bot/Commands/SystemEdit.cs @@ -132,12 +132,16 @@ public class SystemEdit public async Task Color(Context ctx, PKSystem target) { var isOwnSystem = ctx.System?.Id == target.Id; + var matchedRaw = ctx.MatchRaw(); + var matchedClear = await ctx.MatchClear(); - if (!isOwnSystem || !ctx.HasNext(false)) + if (!isOwnSystem || !(ctx.HasNext() || matchedClear)) { if (target.Color == null) await ctx.Reply( "This system does not have a color set." + (isOwnSystem ? " To set one, type `pk;system color `." : "")); + else if (matchedRaw) + await ctx.Reply("```\n#" + target.Color + "\n```"); else await ctx.Reply(embed: new EmbedBuilder() .Title("System color") @@ -151,7 +155,7 @@ public class SystemEdit ctx.CheckSystem().CheckOwnSystem(target); - if (await ctx.MatchClear()) + if (matchedClear) { await ctx.Repository.UpdateSystem(target.Id, new SystemPatch { Color = Partial.Null() });