From d7e8be97ff6fd0409487374e22b28b5baebbb449 Mon Sep 17 00:00:00 2001 From: defnotken Date: Tue, 9 Sep 2025 19:01:41 +0200 Subject: [PATCH] make lower limit 3 characters. add forbidden words. (#4) Co-authored-by: defnotken Reviewed-on: https://git.lightless-sync.org/Lightless-Sync/LightlessServer/pulls/4 --- .../Discord/MareWizardModule.Vanity.cs | 13 +++++++++++-- .../Discord/MareWizardModule.cs | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/LightlessSyncServer/LightlessSyncServices/Discord/MareWizardModule.Vanity.cs b/LightlessSyncServer/LightlessSyncServices/Discord/MareWizardModule.Vanity.cs index c926bc4..917dafc 100644 --- a/LightlessSyncServer/LightlessSyncServices/Discord/MareWizardModule.Vanity.cs +++ b/LightlessSyncServer/LightlessSyncServices/Discord/MareWizardModule.Vanity.cs @@ -92,13 +92,22 @@ public partial class LightlessWizardModule var desiredVanityUid = modal.DesiredVanityUID; using var db = await GetDbContext().ConfigureAwait(false); bool canAddVanityId = !db.Users.Any(u => u.UID == modal.DesiredVanityUID || u.Alias == modal.DesiredVanityUID); + var forbiddenWords = new[] { "null", "nil" }; - Regex rgx = new(@"^[_\-a-zA-Z0-9]{5,15}$", RegexOptions.ECMAScript); + Regex rgx = new(@"^[_\-a-zA-Z0-9]{3,15}$", RegexOptions.ECMAScript); if (!rgx.Match(desiredVanityUid).Success) { eb.WithColor(Color.Red); eb.WithTitle("Invalid Vanity UID"); - eb.WithDescription("A Vanity UID must be between 5 and 15 characters long and only contain the letters A-Z, numbers 0-9, dashes (-) and underscores (_)."); + eb.WithDescription("A Vanity UID must be between 3 and 15 characters long and only contain the letters A-Z, numbers 0-9, dashes (-) and underscores (_)."); + cb.WithButton("Cancel", "wizard-vanity", ButtonStyle.Secondary, emote: new Emoji("❌")); + cb.WithButton("Pick Different UID", "wizard-vanity-uid-set:" + uid, ButtonStyle.Primary, new Emoji("💅")); + } + else if (forbiddenWords.Contains(desiredVanityUid.Trim().ToLowerInvariant())) + { + eb.WithColor(Color.Red); + eb.WithTitle("Invalid Vanity UID"); + eb.WithDescription("You cannot use 'Null' or 'Nil' (any case) as a Vanity UID. Please pick a different one."); cb.WithButton("Cancel", "wizard-vanity", ButtonStyle.Secondary, emote: new Emoji("❌")); cb.WithButton("Pick Different UID", "wizard-vanity-uid-set:" + uid, ButtonStyle.Primary, new Emoji("💅")); } diff --git a/LightlessSyncServer/LightlessSyncServices/Discord/MareWizardModule.cs b/LightlessSyncServer/LightlessSyncServices/Discord/MareWizardModule.cs index b474ee6..2dc4a70 100644 --- a/LightlessSyncServer/LightlessSyncServices/Discord/MareWizardModule.cs +++ b/LightlessSyncServer/LightlessSyncServices/Discord/MareWizardModule.cs @@ -194,7 +194,7 @@ public partial class LightlessWizardModule : InteractionModuleBase public string Title => "Set Vanity UID"; [InputLabel("Set your Vanity UID")] - [ModalTextInput("vanity_uid", TextInputStyle.Short, "5-15 characters, underscore, dash", 5, 15)] + [ModalTextInput("vanity_uid", TextInputStyle.Short, "3-15 characters, underscore, dash", 3, 15)] public string DesiredVanityUID { get; set; } }