matrix-python 1.4.3a0__py3-none-any.whl → 1.4.4a0__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/_version.py +2 -2
- matrix/bot.py +45 -8
- matrix/errors.py +4 -0
- matrix/extension.py +14 -1
- matrix/protocols.py +1 -1
- {matrix_python-1.4.3a0.dist-info → matrix_python-1.4.4a0.dist-info}/METADATA +1 -1
- {matrix_python-1.4.3a0.dist-info → matrix_python-1.4.4a0.dist-info}/RECORD +9 -9
- {matrix_python-1.4.3a0.dist-info → matrix_python-1.4.4a0.dist-info}/WHEEL +0 -0
- {matrix_python-1.4.3a0.dist-info → matrix_python-1.4.4a0.dist-info}/top_level.txt +0 -0
matrix/_version.py
CHANGED
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '1.4.
|
|
22
|
-
__version_tuple__ = version_tuple = (1, 4,
|
|
21
|
+
__version__ = version = '1.4.4a0'
|
|
22
|
+
__version_tuple__ = version_tuple = (1, 4, 4, 'a0')
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
matrix/bot.py
CHANGED
|
@@ -3,7 +3,7 @@ import inspect
|
|
|
3
3
|
import asyncio
|
|
4
4
|
import logging
|
|
5
5
|
|
|
6
|
-
from typing import
|
|
6
|
+
from typing import Optional, Any
|
|
7
7
|
|
|
8
8
|
from nio import AsyncClient, Event, MatrixRoom
|
|
9
9
|
|
|
@@ -15,7 +15,12 @@ from .extension import Extension
|
|
|
15
15
|
from .registry import Registry
|
|
16
16
|
from .help import HelpCommand, DefaultHelpCommand
|
|
17
17
|
from .scheduler import Scheduler
|
|
18
|
-
from .errors import
|
|
18
|
+
from .errors import (
|
|
19
|
+
AlreadyRegisteredError,
|
|
20
|
+
CommandNotFoundError,
|
|
21
|
+
CheckError,
|
|
22
|
+
RoomNotFoundError,
|
|
23
|
+
)
|
|
19
24
|
|
|
20
25
|
|
|
21
26
|
class Bot(Registry):
|
|
@@ -36,7 +41,9 @@ class Bot(Registry):
|
|
|
36
41
|
|
|
37
42
|
self._config: Config | None = None
|
|
38
43
|
self._client: AsyncClient | None = None
|
|
44
|
+
self._synced: asyncio.Event = asyncio.Event()
|
|
39
45
|
self._help: HelpCommand | None = help_
|
|
46
|
+
|
|
40
47
|
self.extensions: dict[str, Extension] = {}
|
|
41
48
|
self.scheduler: Scheduler = Scheduler()
|
|
42
49
|
self.log: logging.Logger = logging.getLogger(__name__)
|
|
@@ -75,10 +82,23 @@ class Bot(Registry):
|
|
|
75
82
|
except ValueError:
|
|
76
83
|
continue
|
|
77
84
|
|
|
78
|
-
def get_room(self, room_id: str) -> Room:
|
|
79
|
-
"""Retrieve a Room instance
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
def get_room(self, room_id: str) -> Room | None:
|
|
86
|
+
"""Retrieve a `Room` instance by its Matrix room ID.
|
|
87
|
+
|
|
88
|
+
Returns the `Room` object corresponding to `room_id` if it exists in
|
|
89
|
+
the client's known rooms. Returns `None` if the room cannot be found.
|
|
90
|
+
|
|
91
|
+
## Example
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
room = bot.get_room("!abc123:matrix.org")
|
|
95
|
+
if room:
|
|
96
|
+
print(room.name)
|
|
97
|
+
```
|
|
98
|
+
"""
|
|
99
|
+
if matrix_room := self.client.rooms.get(room_id):
|
|
100
|
+
return Room(matrix_room=matrix_room, client=self.client)
|
|
101
|
+
return None
|
|
82
102
|
|
|
83
103
|
def load_extension(self, extension: Extension) -> None:
|
|
84
104
|
self.log.debug(f"Loading extension: '{extension.name}'")
|
|
@@ -255,10 +275,16 @@ class Bot(Registry):
|
|
|
255
275
|
login_resp = await self.client.login(self.config.password)
|
|
256
276
|
self.log.info("logged in: %s", login_resp)
|
|
257
277
|
|
|
258
|
-
self.
|
|
278
|
+
sync_task = asyncio.create_task(self.client.sync_forever(timeout=30_000))
|
|
259
279
|
|
|
280
|
+
await self._wait_until_synced()
|
|
260
281
|
await self._on_ready()
|
|
261
|
-
|
|
282
|
+
|
|
283
|
+
self.scheduler.start()
|
|
284
|
+
await sync_task
|
|
285
|
+
|
|
286
|
+
async def _wait_until_synced(self) -> None:
|
|
287
|
+
await self._synced.wait()
|
|
262
288
|
|
|
263
289
|
# MATRIX EVENTS
|
|
264
290
|
|
|
@@ -266,6 +292,9 @@ class Bot(Registry):
|
|
|
266
292
|
await self._process_commands(room, event)
|
|
267
293
|
|
|
268
294
|
async def _on_matrix_event(self, matrix_room: MatrixRoom, event: Event) -> None:
|
|
295
|
+
if not self._synced.is_set():
|
|
296
|
+
self._synced.set()
|
|
297
|
+
|
|
269
298
|
# ignore bot events
|
|
270
299
|
if event.sender == self.client.user:
|
|
271
300
|
return
|
|
@@ -276,6 +305,10 @@ class Bot(Registry):
|
|
|
276
305
|
|
|
277
306
|
try:
|
|
278
307
|
room = self.get_room(matrix_room.room_id)
|
|
308
|
+
|
|
309
|
+
if not room:
|
|
310
|
+
raise RoomNotFoundError(f"Room '{matrix_room.room_id}' not found.")
|
|
311
|
+
|
|
279
312
|
await self._dispatch_matrix_event(room, event)
|
|
280
313
|
except Exception as error:
|
|
281
314
|
await self._on_error(error)
|
|
@@ -306,6 +339,10 @@ class Bot(Registry):
|
|
|
306
339
|
|
|
307
340
|
async def _build_context(self, matrix_room: Room, event: Event) -> Context:
|
|
308
341
|
room = self.get_room(matrix_room.room_id)
|
|
342
|
+
|
|
343
|
+
if not room:
|
|
344
|
+
raise RoomNotFoundError(f"Room '{matrix_room.room_id}' not found.")
|
|
345
|
+
|
|
309
346
|
ctx = Context(bot=self, room=room, event=event)
|
|
310
347
|
prefix = self.prefix or self.config.prefix
|
|
311
348
|
|
matrix/errors.py
CHANGED
matrix/extension.py
CHANGED
|
@@ -17,7 +17,20 @@ class Extension(Registry):
|
|
|
17
17
|
self._on_load: Optional[Callable] = None
|
|
18
18
|
self._on_unload: Optional[Callable] = None
|
|
19
19
|
|
|
20
|
-
def get_room(self, room_id: str) -> Room:
|
|
20
|
+
def get_room(self, room_id: str) -> Room | None:
|
|
21
|
+
"""Retrieve a `Room` instance by its Matrix room ID.
|
|
22
|
+
|
|
23
|
+
Returns the `Room` object corresponding to `room_id` if it exists in
|
|
24
|
+
the client's known rooms. Returns `None` if the room cannot be found.
|
|
25
|
+
|
|
26
|
+
## Example
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
room = extension.get_room("!abc123:matrix.org")
|
|
30
|
+
if room:
|
|
31
|
+
print(room.name)
|
|
32
|
+
```
|
|
33
|
+
"""
|
|
21
34
|
if self.bot is None:
|
|
22
35
|
raise RuntimeError("Extension is not loaded")
|
|
23
36
|
return self.bot.get_room(room_id)
|
matrix/protocols.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: matrix-python
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.4a0
|
|
4
4
|
Summary: An easy-to-use Matrix bot framework designed for quick development and minimal setup
|
|
5
5
|
Author: Simon Roy, Chris Dedman Rollet
|
|
6
6
|
Maintainer-email: Code Society Lab <admin@codesociety.xyz>
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
matrix/__init__.py,sha256=g8yEFjELnnwlvOKns-Ug6LgOezkjAFZ-Opt7esbBHKg,728
|
|
2
|
-
matrix/_version.py,sha256=
|
|
3
|
-
matrix/bot.py,sha256=
|
|
2
|
+
matrix/_version.py,sha256=tcfrwnvkUDHHz8JoKK522ystGqqHOEnmR8F4E8SoWsI,528
|
|
3
|
+
matrix/bot.py,sha256=4gwL2vawLFEREwZD4cEydv6XSXm_SP6pztLD8uwB86M,11944
|
|
4
4
|
matrix/checks.py,sha256=F_7432_OcFO-im4fRAj62MUsyv1mXywT4OsGC_7xbBQ,486
|
|
5
5
|
matrix/command.py,sha256=GrP3WsT07sKehGX7PHfnT7gRX22d99877VPd0X2ViEw,10514
|
|
6
6
|
matrix/config.py,sha256=wPLfcHGpSapkBqbZIuI7zBdxh52OHTD8cQS0WqQkMeU,2388
|
|
7
7
|
matrix/content.py,sha256=z5_E2rTvHsODE52OiDkhDHNQAryx5NLhyHjBb65Xe-U,3853
|
|
8
8
|
matrix/context.py,sha256=-CbxY-LtK9-jgHERhvJH73B3SpO-Uk5ty0j1TMKfzuI,4032
|
|
9
|
-
matrix/errors.py,sha256=
|
|
10
|
-
matrix/extension.py,sha256=
|
|
9
|
+
matrix/errors.py,sha256=HKGb5NUeFuZvieXgpLlVSmUxK4jpA0ODuiPQqQlbQTE,1676
|
|
10
|
+
matrix/extension.py,sha256=RbCx58CdRXF8kGUgS-ec1aZdd-K5hQedhCCQ0-YR4Vg,2272
|
|
11
11
|
matrix/group.py,sha256=TRIX7PE3lcB2ZWu3xY2W2OAmE_a8-i2zHNBYnX5uj28,3691
|
|
12
12
|
matrix/message.py,sha256=w6pu86goylxdrX5fgXPUMB_tW0bOFIk6tKy6qkXTjl4,5136
|
|
13
|
-
matrix/protocols.py,sha256=
|
|
13
|
+
matrix/protocols.py,sha256=nFb4tLanwtrKWoIhZ96xMwXPjD3RF5ITca_yXtakXC4,166
|
|
14
14
|
matrix/registry.py,sha256=jxXg_f_pVl6nuwLdVOIjWJ9Yl9hDJSLwoChnnr3ztNs,12753
|
|
15
15
|
matrix/room.py,sha256=PBuMWQo8mKy2d2XIeMbBlVBTnnqZjOPPGpKLp4K1AVM,14038
|
|
16
16
|
matrix/scheduler.py,sha256=EXsL9i8IDXhcpdW8lti0BR5XcIgkmud4iwOPaqcE9Gw,1727
|
|
@@ -18,7 +18,7 @@ matrix/types.py,sha256=UFjC7p8RAf7piEPvp2X3NuWdqBwkM9Yc3He7KWb9icc,384
|
|
|
18
18
|
matrix/help/__init__.py,sha256=1u7V7T_-VgYDeQCTXsc4y8Fo-8gJhOqYJq2U3cUjMWg,168
|
|
19
19
|
matrix/help/help_command.py,sha256=xCLmKklw74LEMjbUfgQR9eaPMFvi3sPtDw2n2pnAnVQ,12800
|
|
20
20
|
matrix/help/pagination.py,sha256=sJk0wC46sFHf7xl7WsGRAUc4FC7b9hPqmwQDmvcjwgM,2717
|
|
21
|
-
matrix_python-1.4.
|
|
22
|
-
matrix_python-1.4.
|
|
23
|
-
matrix_python-1.4.
|
|
24
|
-
matrix_python-1.4.
|
|
21
|
+
matrix_python-1.4.4a0.dist-info/METADATA,sha256=zswqUmzf_FyaRISg-p2Rqxqocwb9vwHT7Ldr51d4K5A,44541
|
|
22
|
+
matrix_python-1.4.4a0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
23
|
+
matrix_python-1.4.4a0.dist-info/top_level.txt,sha256=BvHVM9c7-5SLzg-1OCRpHKgqAubWhRN1e38e6coHs-g,7
|
|
24
|
+
matrix_python-1.4.4a0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|