mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
Allow to edit prefixes through redbot --edit (#3486)
* feat: allow to edit prefixes through `redbot --edit` * enhance: allow to setup multiple prefixes * fix: gotta break out of the loop * fix: gotta sort prefixes in reversed order * fix: editing prefix shouldn't save it as token * fix: sort prefixes when using flag too * chore(changelog): add towncrier entry * docs: update help for `--edit` flag
This commit is contained in:
parent
17234ac8fa
commit
64106c771a
1
changelog.d/3481.feature.rst
Normal file
1
changelog.d/3481.feature.rst
Normal file
@ -0,0 +1 @@
|
||||
Allow to edit prefix from command line using ``redbot --edit``.
|
||||
@ -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):
|
||||
|
||||
@ -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",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user