mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 02:16:09 -05:00
[Core] Add redbot --edit cli flag (replacement for [p]set owner&token) (#3060)
* feat(core): add `redbot --edit` cli flag * chore(changelog): add towncrier entries * refactor(core): clean up `redbot --edit`, few fixes * fix(core): prepare for review * chore(changelog): update towncrier entry to use double ticks :p * style(black): ugh, Sinbad's git hook isn't perfect (using worktrees) * fix: Address Flame's first review
This commit is contained in:
@@ -1,17 +1,42 @@
|
||||
import argparse
|
||||
import asyncio
|
||||
import logging
|
||||
import sys
|
||||
from typing import Optional
|
||||
|
||||
|
||||
def confirm(m=""):
|
||||
return input(m).lower().strip() in ("y", "yes")
|
||||
def confirm(text: str, default: Optional[bool] = None) -> bool:
|
||||
if default is None:
|
||||
options = "y/n"
|
||||
elif default is True:
|
||||
options = "Y/n"
|
||||
elif default is False:
|
||||
options = "y/N"
|
||||
else:
|
||||
raise TypeError(f"expected bool, not {type(default)}")
|
||||
|
||||
while True:
|
||||
try:
|
||||
value = input(f"{text}: [{options}] ").lower().strip()
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
print("\nAborted!")
|
||||
sys.exit(1)
|
||||
if value in ("y", "yes"):
|
||||
return True
|
||||
if value in ("n", "no"):
|
||||
return False
|
||||
if value == "":
|
||||
if default is not None:
|
||||
return default
|
||||
print("Error: invalid input")
|
||||
|
||||
|
||||
def interactive_config(red, token_set, prefix_set):
|
||||
def interactive_config(red, token_set, prefix_set, *, print_header=True):
|
||||
loop = asyncio.get_event_loop()
|
||||
token = ""
|
||||
|
||||
print("Red - Discord Bot | Configuration process\n")
|
||||
if print_header:
|
||||
print("Red - Discord Bot | Configuration process\n")
|
||||
|
||||
if not token_set:
|
||||
print("Please enter a valid token:")
|
||||
@@ -35,8 +60,7 @@ def interactive_config(red, token_set, prefix_set):
|
||||
while not prefix:
|
||||
prefix = input("Prefix> ")
|
||||
if len(prefix) > 10:
|
||||
print("Your prefix seems overly long. Are you sure that it's correct? (y/n)")
|
||||
if not confirm("> "):
|
||||
if not confirm("Your prefix seems overly long. Are you sure that it's correct?"):
|
||||
prefix = ""
|
||||
if prefix:
|
||||
loop.run_until_complete(red._config.prefix.set([prefix]))
|
||||
@@ -54,6 +78,37 @@ def parse_cli_flags(args):
|
||||
action="store_true",
|
||||
help="List all instance names setup with 'redbot-setup'",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--edit",
|
||||
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).",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--edit-instance-name",
|
||||
type=str,
|
||||
help="New name for the instance. This argument only works with --edit argument passed.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--overwrite-existing-instance",
|
||||
action="store_true",
|
||||
help="Confirm overwriting of existing instance when changing name."
|
||||
" This argument only works with --edit argument passed.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--edit-data-path",
|
||||
type=str,
|
||||
help=(
|
||||
"New data path for the instance. This argument only works with --edit argument passed."
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--copy-data",
|
||||
action="store_true",
|
||||
help="Copy data from old location. This argument only works "
|
||||
"with --edit and --edit-data-path arguments passed.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--owner",
|
||||
type=int,
|
||||
@@ -65,7 +120,7 @@ def parse_cli_flags(args):
|
||||
"--co-owner",
|
||||
type=int,
|
||||
default=[],
|
||||
nargs="*",
|
||||
nargs="+",
|
||||
help="ID of a co-owner. Only people who have access "
|
||||
"to the system that is hosting Red should be "
|
||||
"co-owners, as this gives them complete access "
|
||||
@@ -87,7 +142,7 @@ def parse_cli_flags(args):
|
||||
parser.add_argument(
|
||||
"--load-cogs",
|
||||
type=str,
|
||||
nargs="*",
|
||||
nargs="+",
|
||||
help="Force loading specified cogs from the installed packages. "
|
||||
"Can be used with the --no-cogs flag to load these cogs exclusively.",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user