diff --git a/changelog.d/3481.feature.rst b/changelog.d/3481.feature.rst new file mode 100644 index 000000000..3bd9aeab5 --- /dev/null +++ b/changelog.d/3481.feature.rst @@ -0,0 +1 @@ +Allow to edit prefix from command line using ``redbot --edit``. \ No newline at end of file diff --git a/redbot/__main__.py b/redbot/__main__.py index 2bf085f7d..eb3a6af0c 100644 --- a/redbot/__main__.py +++ b/redbot/__main__.py @@ -107,6 +107,7 @@ async def edit_instance(red, cli_flags): no_prompt = cli_flags.no_prompt token = cli_flags.token owner = cli_flags.owner + prefix = cli_flags.prefix old_name = cli_flags.instance_name new_name = cli_flags.edit_instance_name data_path = cli_flags.edit_data_path @@ -119,14 +120,20 @@ async def edit_instance(red, cli_flags): if new_name is None and confirm_overwrite: print("--overwrite-existing-instance can't be used without --edit-instance-name argument") sys.exit(1) - if no_prompt and all(to_change is None for to_change in (token, owner, new_name, data_path)): + if ( + no_prompt + and all(to_change is None for to_change in (token, owner, new_name, data_path)) + and not prefix + ): print( - "No arguments to edit were provided. Available arguments (check help for more " - "information): --edit-instance-name, --edit-data-path, --copy-data, --owner, --token" + "No arguments to edit were provided." + " Available arguments (check help for more information):" + " --edit-instance-name, --edit-data-path, --copy-data, --owner, --token, --prefix" ) sys.exit(1) await _edit_token(red, token, no_prompt) + await _edit_prefix(red, prefix, no_prompt) await _edit_owner(red, owner, no_prompt) data = deepcopy(data_manager.basic_config) @@ -152,6 +159,26 @@ async def _edit_token(red, token, no_prompt): print("Token updated.\n") +async def _edit_prefix(red, prefix, no_prompt): + if prefix: + prefixes = sorted(prefix, reverse=True) + await red._config.prefix.set(prefixes) + elif not no_prompt and confirm("Would you like to change instance's prefixes?", default=False): + print( + "Enter the prefixes, separated by a space (please note " + "that prefixes containing a space will need to be added with [p]set prefix)" + ) + while True: + prefixes = input("> ").strip().split() + if not prefixes: + print("You need to pass at least one prefix!") + continue + prefixes = sorted(prefixes, reverse=True) + await red._config.prefix.set(prefixes) + print("Prefixes updated.\n") + break + + async def _edit_owner(red, owner, no_prompt): if owner: if not (15 <= len(str(owner)) <= 21): diff --git a/redbot/core/cli.py b/redbot/core/cli.py index f638530d1..02da9c854 100644 --- a/redbot/core/cli.py +++ b/redbot/core/cli.py @@ -90,7 +90,7 @@ def parse_cli_flags(args): action="store_true", help="Edit the instance. This can be done without console interaction " "by passing --no-prompt and arguments that you want to change (available arguments: " - "--edit-instance-name, --edit-data-path, --copy-data, --owner, --token).", + "--edit-instance-name, --edit-data-path, --copy-data, --owner, --token, --prefix).", ) parser.add_argument( "--edit-instance-name",