feat: add '-raw' flag to color commands
This commit is contained in:
parent
69ed7e4925
commit
b30e2a01e3
@ -374,38 +374,39 @@ public class Groups
|
|||||||
|
|
||||||
public async Task GroupColor(Context ctx, PKGroup target)
|
public async Task GroupColor(Context ctx, PKGroup target)
|
||||||
{
|
{
|
||||||
var color = ctx.RemainderOrNull();
|
var isOwnSystem = ctx.System?.Id == target.System;
|
||||||
if (await ctx.MatchClear())
|
var matchedRaw = ctx.MatchRaw();
|
||||||
{
|
var matchedClear = await ctx.MatchClear();
|
||||||
ctx.CheckOwnGroup(target);
|
|
||||||
|
|
||||||
var patch = new GroupPatch { Color = Partial<string>.Null() };
|
if (!isOwnSystem || !(ctx.HasNext() || matchedClear))
|
||||||
await ctx.Repository.UpdateGroup(target.Id, patch);
|
|
||||||
|
|
||||||
await ctx.Reply($"{Emojis.Success} Group color cleared.");
|
|
||||||
}
|
|
||||||
else if (!ctx.HasNext())
|
|
||||||
{
|
{
|
||||||
if (target.Color == null)
|
if (target.Color == null)
|
||||||
if (ctx.System?.Id == target.System)
|
await ctx.Reply(
|
||||||
await ctx.Reply(
|
"This group does not have a color set." + (isOwnSystem ? $" To set one, type `pk;group {target.Reference(ctx)} color <color>`." : ""));
|
||||||
$"This group does not have a color set. To set one, type `pk;group {target.Reference(ctx)} color <color>`.");
|
else if (matchedRaw)
|
||||||
else
|
await ctx.Reply("```\n#" + target.Color + "\n```");
|
||||||
await ctx.Reply("This group does not have a color set.");
|
|
||||||
else
|
else
|
||||||
await ctx.Reply(embed: new EmbedBuilder()
|
await ctx.Reply(embed: new EmbedBuilder()
|
||||||
.Title("Group color")
|
.Title("Group color")
|
||||||
.Color(target.Color.ToDiscordColor())
|
.Color(target.Color.ToDiscordColor())
|
||||||
.Thumbnail(new Embed.EmbedThumbnail($"https://fakeimg.pl/256x256/{target.Color}/?text=%20"))
|
.Thumbnail(new Embed.EmbedThumbnail($"https://fakeimg.pl/256x256/{target.Color}/?text=%20"))
|
||||||
.Description($"This group's color is **#{target.Color}**."
|
.Description($"This group's color is **#{target.Color}**."
|
||||||
+ (ctx.System?.Id == target.System
|
+ (isOwnSystem ? $" To clear it, type `pk;group {target.Reference(ctx)} color -clear`." : ""))
|
||||||
? $" To clear it, type `pk;group {target.Reference(ctx)} color -clear`."
|
|
||||||
: ""))
|
|
||||||
.Build());
|
.Build());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.CheckSystem().CheckOwnGroup(target);
|
||||||
|
|
||||||
|
if (matchedClear)
|
||||||
|
{
|
||||||
|
await ctx.Repository.UpdateGroup(target.Id, new() { Color = Partial<string>.Null() });
|
||||||
|
|
||||||
|
await ctx.Reply($"{Emojis.Success} Group color cleared.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ctx.CheckOwnGroup(target);
|
var color = ctx.RemainderOrNull();
|
||||||
|
|
||||||
if (color.StartsWith("#")) color = color.Substring(1);
|
if (color.StartsWith("#")) color = color.Substring(1);
|
||||||
if (!Regex.IsMatch(color, "^[0-9a-fA-F]{6}$")) throw Errors.InvalidColorError(color);
|
if (!Regex.IsMatch(color, "^[0-9a-fA-F]{6}$")) throw Errors.InvalidColorError(color);
|
||||||
|
@ -225,41 +225,39 @@ public class MemberEdit
|
|||||||
|
|
||||||
public async Task Color(Context ctx, PKMember target)
|
public async Task Color(Context ctx, PKMember target)
|
||||||
{
|
{
|
||||||
var color = ctx.RemainderOrNull();
|
var isOwnSystem = ctx.System?.Id == target.System;
|
||||||
if (await ctx.MatchClear())
|
var matchedRaw = ctx.MatchRaw();
|
||||||
|
var matchedClear = await ctx.MatchClear();
|
||||||
|
|
||||||
|
if (!isOwnSystem || !(ctx.HasNext() || matchedClear))
|
||||||
{
|
{
|
||||||
ctx.CheckOwnMember(target);
|
|
||||||
|
|
||||||
var patch = new MemberPatch { Color = Partial<string>.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 (target.Color == null)
|
||||||
if (ctx.System?.Id == target.System)
|
await ctx.Reply(
|
||||||
await ctx.Reply(
|
"This member does not have a color set." + (isOwnSystem ? $" To set one, type `pk;member {target.Reference(ctx)} color <color>`." : ""));
|
||||||
$"This member does not have a color set. To set one, type `pk;member {target.Reference(ctx)} color <color>`.");
|
else if (matchedRaw)
|
||||||
else
|
await ctx.Reply("```\n#" + target.Color + "\n```");
|
||||||
await ctx.Reply("This member does not have a color set.");
|
|
||||||
else
|
else
|
||||||
await ctx.Reply(embed: new EmbedBuilder()
|
await ctx.Reply(embed: new EmbedBuilder()
|
||||||
.Title("Member color")
|
.Title("Member color")
|
||||||
.Color(target.Color.ToDiscordColor())
|
.Color(target.Color.ToDiscordColor())
|
||||||
.Thumbnail(new Embed.EmbedThumbnail($"https://fakeimg.pl/256x256/{target.Color}/?text=%20"))
|
.Thumbnail(new Embed.EmbedThumbnail($"https://fakeimg.pl/256x256/{target.Color}/?text=%20"))
|
||||||
.Description($"This member's color is **#{target.Color}**."
|
.Description($"This member's color is **#{target.Color}**."
|
||||||
+ (ctx.System?.Id == target.System
|
+ (isOwnSystem ? $" To clear it, type `pk;member {target.Reference(ctx)} color -clear`." : ""))
|
||||||
? $" To clear it, type `pk;member {target.Reference(ctx)} color -clear`."
|
|
||||||
: ""))
|
|
||||||
.Build());
|
.Build());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.CheckSystem().CheckOwnMember(target);
|
||||||
|
|
||||||
|
if (matchedClear)
|
||||||
|
{
|
||||||
|
await ctx.Repository.UpdateMember(target.Id, new() { Color = Partial<string>.Null() });
|
||||||
|
|
||||||
|
await ctx.Reply($"{Emojis.Success} Member color cleared.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ctx.CheckOwnMember(target);
|
var color = ctx.RemainderOrNull();
|
||||||
|
|
||||||
if (color.StartsWith("#")) color = color.Substring(1);
|
if (color.StartsWith("#")) color = color.Substring(1);
|
||||||
if (!Regex.IsMatch(color, "^[0-9a-fA-F]{6}$")) throw Errors.InvalidColorError(color);
|
if (!Regex.IsMatch(color, "^[0-9a-fA-F]{6}$")) throw Errors.InvalidColorError(color);
|
||||||
|
@ -132,12 +132,16 @@ public class SystemEdit
|
|||||||
public async Task Color(Context ctx, PKSystem target)
|
public async Task Color(Context ctx, PKSystem target)
|
||||||
{
|
{
|
||||||
var isOwnSystem = ctx.System?.Id == target.Id;
|
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)
|
if (target.Color == null)
|
||||||
await ctx.Reply(
|
await ctx.Reply(
|
||||||
"This system does not have a color set." + (isOwnSystem ? " To set one, type `pk;system color <color>`." : ""));
|
"This system does not have a color set." + (isOwnSystem ? " To set one, type `pk;system color <color>`." : ""));
|
||||||
|
else if (matchedRaw)
|
||||||
|
await ctx.Reply("```\n#" + target.Color + "\n```");
|
||||||
else
|
else
|
||||||
await ctx.Reply(embed: new EmbedBuilder()
|
await ctx.Reply(embed: new EmbedBuilder()
|
||||||
.Title("System color")
|
.Title("System color")
|
||||||
@ -151,7 +155,7 @@ public class SystemEdit
|
|||||||
|
|
||||||
ctx.CheckSystem().CheckOwnSystem(target);
|
ctx.CheckSystem().CheckOwnSystem(target);
|
||||||
|
|
||||||
if (await ctx.MatchClear())
|
if (matchedClear)
|
||||||
{
|
{
|
||||||
await ctx.Repository.UpdateSystem(target.Id, new SystemPatch { Color = Partial<string>.Null() });
|
await ctx.Repository.UpdateSystem(target.Id, new SystemPatch { Color = Partial<string>.Null() });
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user