From 4c62c67fd40f18dd509a75e6c8f9f9b9e4456cbe Mon Sep 17 00:00:00 2001 From: Vexed Date: Fri, 19 Jun 2020 15:16:22 +0100 Subject: [PATCH] [redbot.setup] Ask for confirmation when passed instance name contains hyphens + allow to use dots (#3920) * Change regex and the error message * few changes see ^^^ GH comment if it doesn't pass the RegEx `[a-zA-Z0-9_\.]*` then: - if on Linux and contains a "-" anywhere, not allowed - if it contains a space or starts with a "-", not allowed - if the top two don't trigger, then `confirm()` with the user. * black why * 3.3.9 * fk * ty aika * review :aha: * oopsie Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * this is just vexed tries and jack fixes Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * quite sad really Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> --- redbot/setup.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/redbot/setup.py b/redbot/setup.py index 077ad8800..15e1f8ecf 100644 --- a/redbot/setup.py +++ b/redbot/setup.py @@ -12,6 +12,7 @@ from typing import Dict, Any, Optional, Union import appdirs import click +from redbot.core.cli import confirm from redbot.core.utils._internal_utils import safe_delete, create_backup as red_create_backup from redbot.core import config, data_manager, drivers from redbot.core.drivers import BackendType, IdentifierData @@ -128,16 +129,23 @@ def get_name() -> str: print( "Please enter a name for your instance," " it will be used to run your bot from here on out.\n" - "This name is case-sensitive and can only include characters" - " A-z, numbers, underscores, and hyphens." + "This name is case-sensitive and should only include characters" + " A-z, numbers, underscores (_) and periods (.)." ) name = input("> ") - if re.fullmatch(r"[a-zA-Z0-9_\-]*", name) is None: + if re.fullmatch(r"[A-Za-z0-9_\.\-]*", name) is None: print( - "ERROR: Instance name can only include" - " characters A-z, numbers, underscores, and hyphens!" + "ERROR: Instance names can only include characters A-z, numbers, " + "underscores (_) and periods (.)." ) name = "" + elif "-" in name and not confirm( + "Hyphens (-) in instance names may cause issues. Are you sure you want to continue with this instance name?", + default=False, + ): + name = "" + + print() # new line for aesthetics return name