libbot 4.2.0__tar.gz → 4.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {libbot-4.2.0/src/libbot.egg-info → libbot-4.4.0}/PKG-INFO +10 -11
- {libbot-4.2.0 → libbot-4.4.0}/pyproject.toml +3 -3
- libbot-4.4.0/requirements/_.txt +2 -0
- {libbot-4.2.0 → libbot-4.4.0}/requirements/cache.txt +1 -1
- libbot-4.4.0/requirements/dev.txt +12 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/__init__.py +1 -1
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/cache/classes/cache.py +4 -4
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/cache/classes/cache_memcached.py +17 -8
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/cache/classes/cache_redis.py +16 -9
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/cache/manager/manager.py +14 -2
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/i18n/_functions.py +44 -44
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/i18n/classes/bot_locale.py +24 -19
- libbot-4.4.0/src/libbot/utils/config/_functions.py +163 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/utils/json/_functions.py +18 -18
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/utils/misc/_functions.py +22 -22
- {libbot-4.2.0 → libbot-4.4.0/src/libbot.egg-info}/PKG-INFO +10 -11
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot.egg-info/requires.txt +8 -8
- libbot-4.2.0/requirements/_.txt +0 -2
- libbot-4.2.0/requirements/dev.txt +0 -12
- libbot-4.2.0/src/libbot/utils/config/_functions.py +0 -183
- {libbot-4.2.0 → libbot-4.4.0}/LICENSE +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/README.md +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/requirements/pycord.txt +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/requirements/pyrogram.txt +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/requirements/speed.txt +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/setup.cfg +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/cache/__init__.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/cache/classes/__init__.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/cache/manager/__init__.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/cache/utils/__init__.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/cache/utils/_objects.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/errors/__init__.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/errors/config.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/i18n/__init__.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/i18n/classes/__init__.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/pycord/__init__.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/pycord/classes/__init__.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/pycord/classes/bot.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/pycord/utils/__init__.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/pycord/utils/color.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/pyrogram/__init__.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/pyrogram/classes/__init__.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/pyrogram/classes/client.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/pyrogram/classes/command.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/pyrogram/classes/commandset.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/utils/__init__.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/utils/config/__init__.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/utils/json/__init__.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/utils/misc/__init__.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/utils/syncs/__init__.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot/utils/syncs/_syncs.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot.egg-info/SOURCES.txt +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot.egg-info/dependency_links.txt +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/src/libbot.egg-info/top_level.txt +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/tests/test_bot_locale.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/tests/test_cache.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/tests/test_config_async.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/tests/test_config_sync.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/tests/test_i18n_async.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/tests/test_i18n_sync.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/tests/test_json_async.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/tests/test_json_sync.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/tests/test_nested_set.py +0 -0
- {libbot-4.2.0 → libbot-4.4.0}/tests/test_utils.py +0 -0
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: libbot
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.4.0
|
|
4
4
|
Summary: Universal bot library with functions needed for basic Discord/Telegram bot development.
|
|
5
5
|
Author: Profitroll
|
|
6
|
-
License:
|
|
6
|
+
License-Expression: GPL-3.0
|
|
7
7
|
Project-URL: Source, https://git.end-play.xyz/profitroll/LibBotUniversal
|
|
8
8
|
Project-URL: Documentation, https://git.end-play.xyz/profitroll/LibBotUniversal/wiki
|
|
9
9
|
Project-URL: Tracker, https://git.end-play.xyz/profitroll/LibBotUniversal/issues
|
|
10
10
|
Classifier: Development Status :: 3 - Alpha
|
|
11
11
|
Classifier: Intended Audience :: Developers
|
|
12
|
-
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
13
12
|
Classifier: Operating System :: OS Independent
|
|
14
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
@@ -20,19 +19,19 @@ Requires-Python: >=3.11
|
|
|
20
19
|
Description-Content-Type: text/markdown
|
|
21
20
|
License-File: LICENSE
|
|
22
21
|
Requires-Dist: aiofiles>=23.0.0
|
|
23
|
-
Requires-Dist: typing-extensions~=4.
|
|
22
|
+
Requires-Dist: typing-extensions~=4.14.0
|
|
24
23
|
Provides-Extra: dev
|
|
25
24
|
Requires-Dist: black==25.1.0; extra == "dev"
|
|
26
25
|
Requires-Dist: build==1.2.2.post1; extra == "dev"
|
|
27
26
|
Requires-Dist: isort==5.13.2; extra == "dev"
|
|
28
|
-
Requires-Dist: mypy==1.
|
|
27
|
+
Requires-Dist: mypy==1.16.1; extra == "dev"
|
|
29
28
|
Requires-Dist: pylint==3.3.7; extra == "dev"
|
|
30
|
-
Requires-Dist: pytest-asyncio==0.
|
|
31
|
-
Requires-Dist: pytest-cov==6.
|
|
32
|
-
Requires-Dist: pytest==8.
|
|
33
|
-
Requires-Dist: tox==4.
|
|
29
|
+
Requires-Dist: pytest-asyncio==1.0.0; extra == "dev"
|
|
30
|
+
Requires-Dist: pytest-cov==6.2.1; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest==8.4.1; extra == "dev"
|
|
32
|
+
Requires-Dist: tox==4.27.0; extra == "dev"
|
|
34
33
|
Requires-Dist: twine==6.1.0; extra == "dev"
|
|
35
|
-
Requires-Dist: types-aiofiles==24.1.0.
|
|
34
|
+
Requires-Dist: types-aiofiles==24.1.0.20250708; extra == "dev"
|
|
36
35
|
Requires-Dist: types-ujson==5.10.0.20250326; extra == "dev"
|
|
37
36
|
Provides-Extra: pycord
|
|
38
37
|
Requires-Dist: apscheduler~=3.11.0; extra == "pycord"
|
|
@@ -44,7 +43,7 @@ Provides-Extra: speed
|
|
|
44
43
|
Requires-Dist: ujson~=5.10.0; extra == "speed"
|
|
45
44
|
Provides-Extra: cache
|
|
46
45
|
Requires-Dist: pymemcache~=4.0.0; extra == "cache"
|
|
47
|
-
Requires-Dist: redis~=6.
|
|
46
|
+
Requires-Dist: redis~=6.2.0; extra == "cache"
|
|
48
47
|
Dynamic: license-file
|
|
49
48
|
|
|
50
49
|
<h1 align="center">LibBotUniversal</h1>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["setuptools>=
|
|
2
|
+
requires = ["setuptools>=77.0.3", "wheel"]
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
|
4
4
|
|
|
5
5
|
[project]
|
|
@@ -9,11 +9,11 @@ authors = [{ name = "Profitroll" }]
|
|
|
9
9
|
description = "Universal bot library with functions needed for basic Discord/Telegram bot development."
|
|
10
10
|
readme = "README.md"
|
|
11
11
|
requires-python = ">=3.11"
|
|
12
|
-
license =
|
|
12
|
+
license = "GPL-3.0"
|
|
13
|
+
license-files = ["LICENSE"]
|
|
13
14
|
classifiers = [
|
|
14
15
|
"Development Status :: 3 - Alpha",
|
|
15
16
|
"Intended Audience :: Developers",
|
|
16
|
-
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
|
|
17
17
|
"Operating System :: OS Independent",
|
|
18
18
|
"Programming Language :: Python :: 3.11",
|
|
19
19
|
"Programming Language :: Python :: 3.12",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
pymemcache~=4.0.0
|
|
2
|
-
redis~=6.
|
|
2
|
+
redis~=6.2.0
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
|
-
from typing import Any, Dict
|
|
2
|
+
from typing import Any, Dict, Optional
|
|
3
3
|
|
|
4
4
|
import pymemcache
|
|
5
5
|
import redis
|
|
@@ -27,16 +27,16 @@ class Cache(ABC):
|
|
|
27
27
|
pass
|
|
28
28
|
|
|
29
29
|
@abstractmethod
|
|
30
|
-
def set_json(self, key: str, value: Any) -> None:
|
|
30
|
+
def set_json(self, key: str, value: Any, ttl_seconds: Optional[int] = None) -> None:
|
|
31
31
|
# TODO This method must also carry out ObjectId conversion!
|
|
32
32
|
pass
|
|
33
33
|
|
|
34
34
|
@abstractmethod
|
|
35
|
-
def set_string(self, key: str, value: str) -> None:
|
|
35
|
+
def set_string(self, key: str, value: str, ttl_seconds: Optional[int] = None) -> None:
|
|
36
36
|
pass
|
|
37
37
|
|
|
38
38
|
@abstractmethod
|
|
39
|
-
def set_object(self, key: str, value: Any) -> None:
|
|
39
|
+
def set_object(self, key: str, value: Any, ttl_seconds: Optional[int] = None) -> None:
|
|
40
40
|
pass
|
|
41
41
|
|
|
42
42
|
@abstractmethod
|
|
@@ -13,20 +13,23 @@ logger: Logger = logging.getLogger(__name__)
|
|
|
13
13
|
class CacheMemcached(Cache):
|
|
14
14
|
client: Client
|
|
15
15
|
|
|
16
|
-
def __init__(
|
|
16
|
+
def __init__(
|
|
17
|
+
self, client: Client, prefix: Optional[str] = None, default_ttl_seconds: Optional[int] = None
|
|
18
|
+
) -> None:
|
|
17
19
|
self.client: Client = client
|
|
18
20
|
self.prefix: str | None = prefix
|
|
21
|
+
self.default_ttl_seconds: int = default_ttl_seconds if default_ttl_seconds is not None else 0
|
|
19
22
|
|
|
20
23
|
logger.info("Initialized Memcached for caching")
|
|
21
24
|
|
|
22
25
|
@classmethod
|
|
23
|
-
def from_config(cls, engine_config: Dict[str, Any], prefix: Optional[str] = None) -> "CacheMemcached":
|
|
26
|
+
def from_config(cls, engine_config: Dict[str, Any], prefix: Optional[str] = None, default_ttl_seconds: Optional[int] = None) -> "CacheMemcached":
|
|
24
27
|
if "uri" not in engine_config:
|
|
25
28
|
raise KeyError(
|
|
26
29
|
"Cache configuration is invalid. Please check if all keys are set (engine: memcached)"
|
|
27
30
|
)
|
|
28
31
|
|
|
29
|
-
return cls(Client(engine_config["uri"], default_noreply=True), prefix=prefix)
|
|
32
|
+
return cls(Client(engine_config["uri"], default_noreply=True), prefix=prefix, default_ttl_seconds=default_ttl_seconds)
|
|
30
33
|
|
|
31
34
|
def _get_prefixed_key(self, key: str) -> str:
|
|
32
35
|
return key if self.prefix is None else f"{self.prefix}_{key}"
|
|
@@ -69,28 +72,34 @@ class CacheMemcached(Cache):
|
|
|
69
72
|
def get_object(self, key: str) -> Any | None:
|
|
70
73
|
raise NotImplementedError()
|
|
71
74
|
|
|
72
|
-
def set_json(self, key: str, value: Any) -> None:
|
|
75
|
+
def set_json(self, key: str, value: Any, ttl_seconds: Optional[int] = None) -> None:
|
|
73
76
|
key = self._get_prefixed_key(key)
|
|
74
77
|
|
|
75
78
|
try:
|
|
76
|
-
self.client.set(
|
|
79
|
+
self.client.set(
|
|
80
|
+
key,
|
|
81
|
+
_json_to_string(value),
|
|
82
|
+
expire=self.default_ttl_seconds if ttl_seconds is None else ttl_seconds,
|
|
83
|
+
)
|
|
77
84
|
logger.debug("Set json cache key '%s'", key)
|
|
78
85
|
except Exception as exc:
|
|
79
86
|
logger.error("Could not set json cache key '%s' due to: %s", key, exc)
|
|
80
87
|
return None
|
|
81
88
|
|
|
82
|
-
def set_string(self, key: str, value: str) -> None:
|
|
89
|
+
def set_string(self, key: str, value: str, ttl_seconds: Optional[int] = None) -> None:
|
|
83
90
|
key = self._get_prefixed_key(key)
|
|
84
91
|
|
|
85
92
|
try:
|
|
86
|
-
self.client.set(
|
|
93
|
+
self.client.set(
|
|
94
|
+
key, value, expire=self.default_ttl_seconds if ttl_seconds is None else ttl_seconds
|
|
95
|
+
)
|
|
87
96
|
logger.debug("Set string cache key '%s'", key)
|
|
88
97
|
except Exception as exc:
|
|
89
98
|
logger.error("Could not set string cache key '%s' due to: %s", key, exc)
|
|
90
99
|
return None
|
|
91
100
|
|
|
92
101
|
# TODO Implement binary serialization
|
|
93
|
-
def set_object(self, key: str, value: Any) -> None:
|
|
102
|
+
def set_object(self, key: str, value: Any, ttl_seconds: Optional[int] = None) -> None:
|
|
94
103
|
raise NotImplementedError()
|
|
95
104
|
|
|
96
105
|
def delete(self, key: str) -> None:
|
|
@@ -5,7 +5,7 @@ from typing import Dict, Any, Optional
|
|
|
5
5
|
from redis import Redis
|
|
6
6
|
|
|
7
7
|
from .cache import Cache
|
|
8
|
-
from ..utils._objects import
|
|
8
|
+
from ..utils._objects import _json_to_string, _string_to_json
|
|
9
9
|
|
|
10
10
|
logger: Logger = logging.getLogger(__name__)
|
|
11
11
|
|
|
@@ -13,20 +13,23 @@ logger: Logger = logging.getLogger(__name__)
|
|
|
13
13
|
class CacheRedis(Cache):
|
|
14
14
|
client: Redis
|
|
15
15
|
|
|
16
|
-
def __init__(
|
|
16
|
+
def __init__(
|
|
17
|
+
self, client: Redis, prefix: Optional[str] = None, default_ttl_seconds: Optional[int] = None
|
|
18
|
+
) -> None:
|
|
17
19
|
self.client: Redis = client
|
|
18
20
|
self.prefix: str | None = prefix
|
|
21
|
+
self.default_ttl_seconds: int | None = default_ttl_seconds
|
|
19
22
|
|
|
20
23
|
logger.info("Initialized Redis for caching")
|
|
21
24
|
|
|
22
25
|
@classmethod
|
|
23
|
-
def from_config(cls, engine_config: Dict[str, Any], prefix: Optional[str] = None) -> Any:
|
|
26
|
+
def from_config(cls, engine_config: Dict[str, Any], prefix: Optional[str] = None, default_ttl_seconds: Optional[int] = None) -> Any:
|
|
24
27
|
if "uri" not in engine_config:
|
|
25
28
|
raise KeyError(
|
|
26
29
|
"Cache configuration is invalid. Please check if all keys are set (engine: memcached)"
|
|
27
30
|
)
|
|
28
31
|
|
|
29
|
-
return cls(Redis.from_url(engine_config["uri"]), prefix=prefix)
|
|
32
|
+
return cls(Redis.from_url(engine_config["uri"]), prefix=prefix, default_ttl_seconds=default_ttl_seconds)
|
|
30
33
|
|
|
31
34
|
def _get_prefixed_key(self, key: str) -> str:
|
|
32
35
|
return key if self.prefix is None else f"{self.prefix}_{key}"
|
|
@@ -69,28 +72,32 @@ class CacheRedis(Cache):
|
|
|
69
72
|
def get_object(self, key: str) -> Any | None:
|
|
70
73
|
raise NotImplementedError()
|
|
71
74
|
|
|
72
|
-
def set_json(self, key: str, value: Any) -> None:
|
|
75
|
+
def set_json(self, key: str, value: Any, ttl_seconds: Optional[int] = None) -> None:
|
|
73
76
|
key = self._get_prefixed_key(key)
|
|
74
77
|
|
|
75
78
|
try:
|
|
76
|
-
self.client.set(
|
|
79
|
+
self.client.set(
|
|
80
|
+
key,
|
|
81
|
+
_json_to_string(value),
|
|
82
|
+
ex=self.default_ttl_seconds if ttl_seconds is None else ttl_seconds,
|
|
83
|
+
)
|
|
77
84
|
logger.debug("Set json cache key '%s'", key)
|
|
78
85
|
except Exception as exc:
|
|
79
86
|
logger.error("Could not set json cache key '%s' due to: %s", key, exc)
|
|
80
87
|
return None
|
|
81
88
|
|
|
82
|
-
def set_string(self, key: str, value: str) -> None:
|
|
89
|
+
def set_string(self, key: str, value: str, ttl_seconds: Optional[int] = None) -> None:
|
|
83
90
|
key = self._get_prefixed_key(key)
|
|
84
91
|
|
|
85
92
|
try:
|
|
86
|
-
self.client.set(key, value)
|
|
93
|
+
self.client.set(key, value, ex=self.default_ttl_seconds if ttl_seconds is None else ttl_seconds)
|
|
87
94
|
logger.debug("Set string cache key '%s'", key)
|
|
88
95
|
except Exception as exc:
|
|
89
96
|
logger.error("Could not set string cache key '%s' due to: %s", key, exc)
|
|
90
97
|
return None
|
|
91
98
|
|
|
92
99
|
# TODO Implement binary serialization
|
|
93
|
-
def set_object(self, key: str, value: Any) -> None:
|
|
100
|
+
def set_object(self, key: str, value: Any, ttl_seconds: Optional[int] = None) -> None:
|
|
94
101
|
raise NotImplementedError()
|
|
95
102
|
|
|
96
103
|
def delete(self, key: str) -> None:
|
|
@@ -7,7 +7,19 @@ def create_cache_client(
|
|
|
7
7
|
config: Dict[str, Any],
|
|
8
8
|
engine: Literal["memcached", "redis"] | None = None,
|
|
9
9
|
prefix: Optional[str] = None,
|
|
10
|
+
default_ttl_seconds: Optional[int] = None,
|
|
10
11
|
) -> CacheMemcached | CacheRedis:
|
|
12
|
+
"""Create a cache client of a provided type.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
config (Dict[str, Any]): Cache client configuration.
|
|
16
|
+
engine (Literal["memcached", "redis"] | None): Cache engine to use. Defaults to None.
|
|
17
|
+
prefix (:obj:`str`, optional): Prefix used for each key-value pair. Defaults to None (no prefix).
|
|
18
|
+
default_ttl_seconds (:obj:`int`, optional): Default TTL for values (in seconds). Defaults to None (does not expire).
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
CacheMemcached | CacheRedis: Cache client.
|
|
22
|
+
"""
|
|
11
23
|
if engine not in ["memcached", "redis"] or engine is None:
|
|
12
24
|
raise KeyError(f"Incorrect cache engine provided. Expected 'memcached' or 'redis', got '{engine}'")
|
|
13
25
|
|
|
@@ -18,8 +30,8 @@ def create_cache_client(
|
|
|
18
30
|
|
|
19
31
|
match engine:
|
|
20
32
|
case "memcached":
|
|
21
|
-
return CacheMemcached.from_config(config["cache"][engine], prefix=prefix)
|
|
33
|
+
return CacheMemcached.from_config(config["cache"][engine], prefix=prefix, default_ttl_seconds=default_ttl_seconds)
|
|
22
34
|
case "redis":
|
|
23
|
-
return CacheRedis.from_config(config["cache"][engine], prefix=prefix)
|
|
35
|
+
return CacheRedis.from_config(config["cache"][engine], prefix=prefix, default_ttl_seconds=default_ttl_seconds)
|
|
24
36
|
case _:
|
|
25
37
|
raise KeyError(f"Cache implementation for the engine '{engine}' is not present.")
|
|
@@ -18,16 +18,16 @@ def _(
|
|
|
18
18
|
locale: str | None = "en",
|
|
19
19
|
locales_root: str | Path = Path("locale"),
|
|
20
20
|
) -> Any:
|
|
21
|
-
"""Get value of locale string
|
|
21
|
+
"""Get value of locale string.
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
Args:
|
|
24
|
+
key (str): The last key of the locale's keys path.
|
|
25
|
+
*args (str): Path to key like: `dict[args][key]`.
|
|
26
|
+
locale (str | None): Locale to looked up in. Defaults to "en".
|
|
27
|
+
locales_root (str | Path, optional): Folder where locales are located. Defaults to Path("locale").
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
Returns:
|
|
30
|
+
Any: Value of provided locale key. Is usually `str`, `Dict[str, Any]` or `List[Any]`.
|
|
31
31
|
"""
|
|
32
32
|
if locale is None:
|
|
33
33
|
locale: str = config_get("locale")
|
|
@@ -58,16 +58,16 @@ async def _(
|
|
|
58
58
|
locale: str | None = "en",
|
|
59
59
|
locales_root: str | Path = Path("locale"),
|
|
60
60
|
) -> Any:
|
|
61
|
-
"""Get value of locale string
|
|
61
|
+
"""Get value of locale string.
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
Args:
|
|
64
|
+
key (str): The last key of the locale's keys path.
|
|
65
|
+
*args (str): Path to key like: `dict[args][key]`.
|
|
66
|
+
locale (str | None): Locale to looked up in. Defaults to "en".
|
|
67
|
+
locales_root (str | Path, optional): Folder where locales are located. Defaults to Path("locale").
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
Returns:
|
|
70
|
+
Any: Value of provided locale key. Is usually `str`, `Dict[str, Any]` or `List[Any]`.
|
|
71
71
|
"""
|
|
72
72
|
locale: str = config_get("locale") if locale is None else locale
|
|
73
73
|
|
|
@@ -94,15 +94,15 @@ async def _(
|
|
|
94
94
|
|
|
95
95
|
@asyncable
|
|
96
96
|
def in_all_locales(key: str, *args: str, locales_root: str | Path = Path("locale")) -> List[Any]:
|
|
97
|
-
"""Get value of the provided key and path in all available locales
|
|
97
|
+
"""Get value of the provided key and path in all available locales.
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
*
|
|
102
|
-
|
|
99
|
+
Args:
|
|
100
|
+
key (str): The last key of the locale's keys path.
|
|
101
|
+
*args (str): Path to key like: `dict[args][key]`.
|
|
102
|
+
locales_root (str | Path, optional): Folder where locales are located. Defaults to `Path("locale")`.
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
Returns:
|
|
105
|
+
List[Any]: List of values in all locales.
|
|
106
106
|
"""
|
|
107
107
|
|
|
108
108
|
output: List[Any] = []
|
|
@@ -128,15 +128,15 @@ def in_all_locales(key: str, *args: str, locales_root: str | Path = Path("locale
|
|
|
128
128
|
|
|
129
129
|
@in_all_locales.asynchronous
|
|
130
130
|
async def in_all_locales(key: str, *args: str, locales_root: str | Path = Path("locale")) -> List[Any]:
|
|
131
|
-
"""Get value of the provided key and path in all available locales
|
|
131
|
+
"""Get value of the provided key and path in all available locales.
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
*
|
|
136
|
-
|
|
133
|
+
Args:
|
|
134
|
+
key (str): The last key of the locale's keys path.
|
|
135
|
+
*args (str): Path to key like: `dict[args][key]`.
|
|
136
|
+
locales_root (str | Path, optional): Folder where locales are located. Defaults to Path("locale").
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
Returns:
|
|
139
|
+
List[Any]: List of values in all locales.
|
|
140
140
|
"""
|
|
141
141
|
|
|
142
142
|
output: List[Any] = []
|
|
@@ -164,15 +164,15 @@ async def in_all_locales(key: str, *args: str, locales_root: str | Path = Path("
|
|
|
164
164
|
def in_every_locale(
|
|
165
165
|
key: str, *args: str, locales_root: str | Path = Path("locale")
|
|
166
166
|
) -> Dict[str, Any]:
|
|
167
|
-
"""Get value of the provided key and path in every available locale with locale tag
|
|
167
|
+
"""Get value of the provided key and path in every available locale with locale tag.
|
|
168
168
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
*
|
|
172
|
-
|
|
169
|
+
Args:
|
|
170
|
+
key (str): The last key of the locale's keys path.
|
|
171
|
+
*args (str): Path to key like: `dict[args][key]`.
|
|
172
|
+
locales_root (str | Path, optional): Folder where locales are located. Defaults to Path("locale").
|
|
173
173
|
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
Returns:
|
|
175
|
+
Dict[str, Any]: Locale is a key, and it's value from locale file is a value.
|
|
176
176
|
"""
|
|
177
177
|
|
|
178
178
|
output: Dict[str, Any] = {}
|
|
@@ -200,15 +200,15 @@ def in_every_locale(
|
|
|
200
200
|
async def in_every_locale(
|
|
201
201
|
key: str, *args: str, locales_root: str | Path = Path("locale")
|
|
202
202
|
) -> Dict[str, Any]:
|
|
203
|
-
"""Get value of the provided key and path in every available locale with locale tag
|
|
203
|
+
"""Get value of the provided key and path in every available locale with locale tag.
|
|
204
204
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
*
|
|
208
|
-
|
|
205
|
+
Args:
|
|
206
|
+
key (str): The last key of the locale's keys path.
|
|
207
|
+
*args (str): Path to key like: `dict[args][key]`.
|
|
208
|
+
locales_root (str | Path, optional): Folder where locales are located. Defaults to Path("locale").
|
|
209
209
|
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
Returns:
|
|
211
|
+
Dict[str, Any]: Locale is a key, and it's value from locale file is a value.
|
|
212
212
|
"""
|
|
213
213
|
|
|
214
214
|
output: Dict[str, Any] = {}
|
|
@@ -14,6 +14,11 @@ class BotLocale:
|
|
|
14
14
|
default_locale: str | None = "en",
|
|
15
15
|
locales_root: str | Path = Path("locale"),
|
|
16
16
|
) -> None:
|
|
17
|
+
"""
|
|
18
|
+
Args:
|
|
19
|
+
default_locale (str | None, optional): Default locale. Defaults to "en".
|
|
20
|
+
locales_root (str | Path, optional): Path to a directory with locale files. Defaults to Path("locale").
|
|
21
|
+
"""
|
|
17
22
|
if isinstance(locales_root, str):
|
|
18
23
|
locales_root = Path(locales_root)
|
|
19
24
|
elif not isinstance(locales_root, Path):
|
|
@@ -30,15 +35,15 @@ class BotLocale:
|
|
|
30
35
|
self.locales[locale] = json_read(Path(f"{locales_root}/{locale}.json"))
|
|
31
36
|
|
|
32
37
|
def _(self, key: str, *args: str, locale: str | None = None) -> Any:
|
|
33
|
-
"""Get value of locale string
|
|
38
|
+
"""Get value of locale string.
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*
|
|
38
|
-
|
|
40
|
+
Args:
|
|
41
|
+
key (str): The last key of the locale's keys path.
|
|
42
|
+
*args (str): Path to key like: `dict[args][key]`.
|
|
43
|
+
locale (str | None, optional): Locale to looked up in. Defaults to config's `"locale"` value.
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
Returns:
|
|
46
|
+
Any: Value of provided locale key. Is usually `str`, `Dict[str, Any]` or `List[Any]`.
|
|
42
47
|
"""
|
|
43
48
|
if locale is None:
|
|
44
49
|
locale: str = self.default
|
|
@@ -64,14 +69,14 @@ class BotLocale:
|
|
|
64
69
|
return f'⚠️ Locale in config is invalid: could not get "{key}" in {args} from locale "{locale}"'
|
|
65
70
|
|
|
66
71
|
def in_all_locales(self, key: str, *args: str) -> List[Any]:
|
|
67
|
-
"""Get value of the provided key and path in all available locales
|
|
72
|
+
"""Get value of the provided key and path in all available locales.
|
|
68
73
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
*
|
|
74
|
+
Args:
|
|
75
|
+
key (str): The last key of the locale's keys path.
|
|
76
|
+
*args (str): Path to key like: `dict[args][key]`.
|
|
72
77
|
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
Returns:
|
|
79
|
+
List[Any]: List of values in all locales.
|
|
75
80
|
"""
|
|
76
81
|
output: List[Any] = []
|
|
77
82
|
|
|
@@ -94,14 +99,14 @@ class BotLocale:
|
|
|
94
99
|
return output
|
|
95
100
|
|
|
96
101
|
def in_every_locale(self, key: str, *args: str) -> Dict[str, Any]:
|
|
97
|
-
"""Get value of the provided key and path in every available locale with locale tag
|
|
102
|
+
"""Get value of the provided key and path in every available locale with locale tag.
|
|
98
103
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
*
|
|
104
|
+
Args:
|
|
105
|
+
key (str): The last key of the locale's keys path.
|
|
106
|
+
*args (str): Path to key like: `dict[args][key]`.
|
|
102
107
|
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
Returns:
|
|
109
|
+
Dict[str, Any]: Locale is a key, and it's value from locale file is a value.
|
|
105
110
|
"""
|
|
106
111
|
output: Dict[str, Any] = {}
|
|
107
112
|
|