diff --git a/PluralKit.Bot/Commands/MemberCommands.cs b/PluralKit.Bot/Commands/MemberCommands.cs index 3339bd78..322f43b1 100644 --- a/PluralKit.Bot/Commands/MemberCommands.cs +++ b/PluralKit.Bot/Commands/MemberCommands.cs @@ -1,4 +1,5 @@ using System; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Discord.Commands; @@ -63,7 +64,7 @@ namespace PluralKit.Bot.Commands if (!await Context.PromptYesNo(msg)) throw new PKError("Member renaming cancelled."); } - // Rename the mebmer + // Rename the member ContextEntity.Name = newName; await Members.Save(ContextEntity); @@ -73,10 +74,10 @@ namespace PluralKit.Bot.Commands [Command("description")] [Alias("info", "bio", "text")] - [Remarks("member description description ")] [MustPassOwnMember] public async Task MemberDescription([Remainder] string description = null) { - if (description.Length > Limits.MaxDescriptionLength) throw Errors.DescriptionTooLongError(description.Length); + if (description.IsLongerThan(Limits.MaxDescriptionLength)) throw Errors.DescriptionTooLongError(description.Length); ContextEntity.Description = description; await Members.Save(ContextEntity); @@ -86,10 +87,10 @@ namespace PluralKit.Bot.Commands [Command("pronouns")] [Alias("pronoun")] - [Remarks("member pronouns pronouns ")] [MustPassOwnMember] public async Task MemberPronouns([Remainder] string pronouns = null) { - if (pronouns.Length > Limits.MaxPronounsLength) throw Errors.MemberPronounsTooLongError(pronouns.Length); + if (pronouns.IsLongerThan(Limits.MaxPronounsLength)) throw Errors.MemberPronounsTooLongError(pronouns.Length); ContextEntity.Pronouns = pronouns; await Members.Save(ContextEntity); @@ -97,6 +98,24 @@ namespace PluralKit.Bot.Commands await Context.Channel.SendMessageAsync($"{Emojis.Success} Member pronouns {(pronouns == null ? "cleared" : "changed")}."); } + [Command("color")] + [Alias("colour")] + [Remarks("member color ")] + [MustPassOwnMember] + public async Task MemberColor([Remainder] string color = null) + { + if (color != null) + { + if (color.StartsWith("#")) color = color.Substring(1); + if (!Regex.IsMatch(color, "[0-9a-f]{6}")) throw Errors.InvalidColorError(color); + } + + ContextEntity.Color = color; + await Members.Save(ContextEntity); + + await Context.Channel.SendMessageAsync($"{Emojis.Success} Member color {(color == null ? "cleared" : "changed")}."); + } + public override async Task ReadContextParameterAsync(string value) { var res = await new PKMemberTypeReader().ReadAsync(Context, value, _services); diff --git a/PluralKit.Bot/Commands/SystemCommands.cs b/PluralKit.Bot/Commands/SystemCommands.cs index 851c5968..82b16e11 100644 --- a/PluralKit.Bot/Commands/SystemCommands.cs +++ b/PluralKit.Bot/Commands/SystemCommands.cs @@ -30,7 +30,7 @@ namespace PluralKit.Bot.Commands public async Task New([Remainder] string systemName = null) { if (ContextEntity != null) throw Errors.NotOwnSystemError; - if (Context.SenderSystem != null) throw Errors.NoSystemError; + if (Context.SenderSystem != null) throw Errors.ExistingSystemError; var system = await Systems.Create(systemName); await Systems.Link(system, Context.User.Id); diff --git a/PluralKit.Bot/Errors.cs b/PluralKit.Bot/Errors.cs index 7508fce9..f4caee3c 100644 --- a/PluralKit.Bot/Errors.cs +++ b/PluralKit.Bot/Errors.cs @@ -5,7 +5,7 @@ namespace PluralKit.Bot { public static PKError NotOwnSystemError => new PKError($"You can only run this command on your own system."); public static PKError NotOwnMemberError => new PKError($"You can only run this command on your own member."); public static PKError NoSystemError => new PKError("You do not have a system registered with PluralKit. To create one, type `pk;system new`."); - public static PKError ExistinSystemError => new PKError("You already have a system registered with PluralKit. To view it, type `pk;system`. If you'd like to delete your system and start anew, type `pk;system delete`, or if you'd like to unlink this account from it, type `pk;unlink`."); + public static PKError ExistingSystemError => new PKError("You already have a system registered with PluralKit. To view it, type `pk;system`. If you'd like to delete your system and start anew, type `pk;system delete`, or if you'd like to unlink this account from it, type `pk;unlink`."); public static PKError MissingMemberError => new PKSyntaxError("You need to specify a member to run this command on."); public static PKError SystemNameTooLongError(int length) => new PKError($"System name too long ({length}/{Limits.MaxSystemNameLength} characters)."); @@ -13,5 +13,7 @@ namespace PluralKit.Bot { public static PKError DescriptionTooLongError(int length) => new PKError($"Description too long ({length}/{Limits.MaxDescriptionLength} characters)."); public static PKError MemberNameTooLongError(int length) => new PKError($"Member name too long ({length}/{Limits.MaxMemberNameLength} characters)."); public static PKError MemberPronounsTooLongError(int length) => new PKError($"Member pronouns too long ({length}/{Limits.MaxMemberNameLength} characters)."); + + public static PKError InvalidColorError(string color) => new PKError($"{color} is not a valid color. Color must be in hex format (eg. #ff0000)."); } } \ No newline at end of file diff --git a/PluralKit.Core/Utils.cs b/PluralKit.Core/Utils.cs index efffffe1..a4afe474 100644 --- a/PluralKit.Core/Utils.cs +++ b/PluralKit.Core/Utils.cs @@ -21,6 +21,12 @@ namespace PluralKit if (str.Length < maxLength) return str; return str.Substring(0, maxLength - ellipsis.Length) + ellipsis; } + + public static bool IsLongerThan(this string str, int length) + { + if (str != null) return str.Length > length; + return false; + } } public static class Emojis {