v3.3.0 #159
@ -11,6 +11,8 @@ except ImportError:
|
|||||||
from ._utils import supports_argument
|
from ._utils import supports_argument
|
||||||
from .sync._nested import nested_delete, nested_set
|
from .sync._nested import nested_delete, nested_set
|
||||||
|
|
||||||
|
DEFAULT_CONFIG_LOCATION: str = "config.json"
|
||||||
|
|
||||||
|
|
||||||
async def json_read(path: Union[str, Path]) -> Any:
|
async def json_read(path: Union[str, Path]) -> Any:
|
||||||
"""Read contents of a JSON file
|
"""Read contents of a JSON file
|
||||||
@ -43,7 +45,7 @@ async def json_write(data: Any, path: Union[str, Path]) -> None:
|
|||||||
|
|
||||||
|
|
||||||
async def config_get(
|
async def config_get(
|
||||||
key: str, *path: str, config_file: Union[str, Path] = "config.json"
|
key: str, *path: str, config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION
|
||||||
) -> Any:
|
) -> Any:
|
||||||
"""Get a value of the config key by its path provided
|
"""Get a value of the config key by its path provided
|
||||||
For example, `foo.bar.key` has a path of `"foo", "bar"` and the key `"key"`
|
For example, `foo.bar.key` has a path of `"foo", "bar"` and the key `"key"`
|
||||||
@ -83,7 +85,7 @@ async def config_get(
|
|||||||
|
|
||||||
|
|
||||||
async def config_set(
|
async def config_set(
|
||||||
key: str, value: Any, *path: str, config_file: Union[str, Path] = "config.json"
|
key: str, value: Any, *path: str, config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set config's key by its path to the value
|
"""Set config's key by its path to the value
|
||||||
|
|
||||||
@ -99,14 +101,13 @@ async def config_set(
|
|||||||
await json_write(
|
await json_write(
|
||||||
nested_set(await json_read(config_file), value, *(*path, key)), config_file
|
nested_set(await json_read(config_file), value, *(*path, key)), config_file
|
||||||
)
|
)
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
async def config_delete(
|
async def config_delete(
|
||||||
key: str,
|
key: str,
|
||||||
*path: str,
|
*path: str,
|
||||||
missing_ok: bool = False,
|
missing_ok: bool = False,
|
||||||
config_file: Union[str, Path] = "config.json",
|
config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set config's key by its path
|
"""Set config's key by its path
|
||||||
|
|
||||||
|
@ -358,7 +358,8 @@ class PyroClient(Client):
|
|||||||
]
|
]
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"Registering commands %s with a default scope 'BotCommandScopeDefault'"
|
"Registering commands %s with a default scope 'BotCommandScopeDefault'",
|
||||||
|
commands
|
||||||
)
|
)
|
||||||
|
|
||||||
await self.set_bot_commands(commands)
|
await self.set_bot_commands(commands)
|
||||||
|
@ -9,6 +9,8 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from json import dumps, loads
|
from json import dumps, loads
|
||||||
|
|
||||||
|
DEFAULT_CONFIG_LOCATION: str = "config.json"
|
||||||
|
|
||||||
|
|
||||||
def json_read(path: Union[str, Path]) -> Any:
|
def json_read(path: Union[str, Path]) -> Any:
|
||||||
"""Read contents of a JSON file
|
"""Read contents of a JSON file
|
||||||
@ -41,7 +43,7 @@ def json_write(data: Any, path: Union[str, Path]) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def config_get(
|
def config_get(
|
||||||
key: str, *path: str, config_file: Union[str, Path] = "config.json"
|
key: str, *path: str, config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION
|
||||||
) -> Any:
|
) -> Any:
|
||||||
"""Get a value of the config key by its path provided
|
"""Get a value of the config key by its path provided
|
||||||
For example, `foo.bar.key` has a path of `"foo", "bar"` and the key `"key"`
|
For example, `foo.bar.key` has a path of `"foo", "bar"` and the key `"key"`
|
||||||
@ -81,7 +83,7 @@ def config_get(
|
|||||||
|
|
||||||
|
|
||||||
def config_set(
|
def config_set(
|
||||||
key: str, value: Any, *path: str, config_file: Union[str, Path] = "config.json"
|
key: str, value: Any, *path: str, config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set config's key by its path to the value
|
"""Set config's key by its path to the value
|
||||||
|
|
||||||
@ -95,14 +97,13 @@ def config_set(
|
|||||||
* `KeyError`: Key is not found under path provided
|
* `KeyError`: Key is not found under path provided
|
||||||
"""
|
"""
|
||||||
json_write(nested_set(json_read(config_file), value, *(*path, key)), config_file)
|
json_write(nested_set(json_read(config_file), value, *(*path, key)), config_file)
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def config_delete(
|
def config_delete(
|
||||||
key: str,
|
key: str,
|
||||||
*path: str,
|
*path: str,
|
||||||
missing_ok: bool = False,
|
missing_ok: bool = False,
|
||||||
config_file: Union[str, Path] = "config.json",
|
config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set config's key by its path
|
"""Set config's key by its path
|
||||||
|
|
||||||
|
@ -6,10 +6,12 @@ from libbot._utils import supports_argument
|
|||||||
|
|
||||||
|
|
||||||
def func1(foo: str, bar: str):
|
def func1(foo: str, bar: str):
|
||||||
|
"""Dummy function with specific arguments"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def func2(foo: str):
|
def func2(foo: str):
|
||||||
|
"""Dummy function with specific arguments"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user