matrix-python 0.1.2a0__py3-none-any.whl → 1.0.0__py3-none-any.whl
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.
- matrix/__init__.py +17 -1
- matrix/_error_handler.py +14 -0
- matrix/_version.py +24 -0
- matrix/api.py +35 -0
- matrix/bot.py +316 -308
- matrix/checks.py +17 -6
- matrix/command.py +143 -94
- matrix/config.py +112 -38
- matrix/content.py +174 -0
- matrix/context.py +92 -37
- matrix/errors.py +38 -8
- matrix/extension.py +90 -0
- matrix/group.py +138 -0
- matrix/help/__init__.py +4 -0
- matrix/help/help_command.py +372 -0
- matrix/help/pagination.py +73 -0
- matrix/member.py +217 -0
- matrix/message.py +158 -112
- matrix/protocols.py +13 -0
- matrix/py.typed +0 -0
- matrix/registry.py +460 -0
- matrix/room.py +481 -88
- matrix/scheduler.py +13 -10
- matrix/space.py +45 -0
- matrix/types.py +32 -0
- matrix_python-1.0.0.dist-info/METADATA +153 -0
- matrix_python-1.0.0.dist-info/RECORD +31 -0
- {matrix_python-0.1.2a0.dist-info → matrix_python-1.0.0.dist-info}/WHEEL +1 -1
- matrix_python-1.0.0.dist-info/scm_file_list.json +112 -0
- matrix_python-1.0.0.dist-info/scm_version.json +8 -0
- matrix/help.py +0 -231
- matrix_python-0.1.2a0.dist-info/METADATA +0 -771
- matrix_python-0.1.2a0.dist-info/RECORD +0 -15
- {matrix_python-0.1.2a0.dist-info → matrix_python-1.0.0.dist-info}/top_level.txt +0 -0
matrix/__init__.py
CHANGED
|
@@ -1,19 +1,35 @@
|
|
|
1
1
|
"""A simple, developer-friendly library to create powerful Matrix bots."""
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
from importlib.metadata import version, PackageNotFoundError
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
__version__ = version("matrix-python")
|
|
7
|
+
except PackageNotFoundError:
|
|
8
|
+
from matrix._version import version as __version__
|
|
4
9
|
|
|
5
10
|
from .bot import Bot
|
|
11
|
+
from .group import Group, group
|
|
6
12
|
from .config import Config
|
|
7
13
|
from .context import Context
|
|
8
14
|
from .command import Command
|
|
9
15
|
from .help import HelpCommand
|
|
10
16
|
from .checks import cooldown
|
|
17
|
+
from .room import Room
|
|
18
|
+
from .space import Space
|
|
19
|
+
from .message import Message
|
|
20
|
+
from .extension import Extension
|
|
11
21
|
|
|
12
22
|
__all__ = [
|
|
13
23
|
"Bot",
|
|
24
|
+
"Group",
|
|
25
|
+
"group",
|
|
14
26
|
"Config",
|
|
15
27
|
"Command",
|
|
16
28
|
"Context",
|
|
17
29
|
"HelpCommand",
|
|
18
30
|
"cooldown",
|
|
31
|
+
"Room",
|
|
32
|
+
"Space",
|
|
33
|
+
"Message",
|
|
34
|
+
"Extension",
|
|
19
35
|
]
|
matrix/_error_handler.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
from typing import Callable, Dict, Optional, TypeVar
|
|
3
|
+
|
|
4
|
+
F = TypeVar("F", bound=Callable[..., object])
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def resolve_error_handler(
|
|
8
|
+
handlers: Dict[type[Exception], F], error: Exception
|
|
9
|
+
) -> Optional[F]:
|
|
10
|
+
"""Look up the handler registered for the error's type or nearest base class."""
|
|
11
|
+
for cls in inspect.getmro(type(error)):
|
|
12
|
+
if cls in handlers:
|
|
13
|
+
return handlers[cls]
|
|
14
|
+
return None
|
matrix/_version.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# file generated by vcs-versioning
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"__version__",
|
|
7
|
+
"__version_tuple__",
|
|
8
|
+
"version",
|
|
9
|
+
"version_tuple",
|
|
10
|
+
"__commit_id__",
|
|
11
|
+
"commit_id",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
version: str
|
|
15
|
+
__version__: str
|
|
16
|
+
__version_tuple__: tuple[int | str, ...]
|
|
17
|
+
version_tuple: tuple[int | str, ...]
|
|
18
|
+
commit_id: str | None
|
|
19
|
+
__commit_id__: str | None
|
|
20
|
+
|
|
21
|
+
__version__ = version = '1.0.0'
|
|
22
|
+
__version_tuple__ = version_tuple = (1, 0, 0)
|
|
23
|
+
|
|
24
|
+
__commit_id__ = commit_id = 'g058abf630'
|
matrix/api.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from typing import Awaitable, TypeVar
|
|
2
|
+
|
|
3
|
+
from nio import ErrorResponse, Response
|
|
4
|
+
|
|
5
|
+
from matrix.errors import MatrixError
|
|
6
|
+
|
|
7
|
+
T = TypeVar("T", bound=Response)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
async def matrix_call(coro: Awaitable[T], /, *, error_message: str) -> T:
|
|
11
|
+
"""Await `coro`, translating any failure into a `MatrixError`.
|
|
12
|
+
|
|
13
|
+
matrix-nio's `AsyncClient` methods don't raise on API-level errors; they
|
|
14
|
+
return an `ErrorResponse` instead of raising. This wraps a single call so
|
|
15
|
+
both transport-level exceptions and nio `ErrorResponse` results become a
|
|
16
|
+
`MatrixError` carrying `error_message`.
|
|
17
|
+
|
|
18
|
+
## Example
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
response = await matrix_call(
|
|
22
|
+
self.client.room_kick(room_id=self.room_id, user_id=user_id),
|
|
23
|
+
error_message="Failed to kick user",
|
|
24
|
+
)
|
|
25
|
+
```
|
|
26
|
+
"""
|
|
27
|
+
try:
|
|
28
|
+
response = await coro
|
|
29
|
+
except Exception as e:
|
|
30
|
+
raise MatrixError(f"{error_message}: {e}") from e
|
|
31
|
+
|
|
32
|
+
if isinstance(response, ErrorResponse):
|
|
33
|
+
raise MatrixError(f"{error_message}: {response}")
|
|
34
|
+
|
|
35
|
+
return response
|